Code

Improve behavior when pasting, DnDing and importing bitmap images
[inkscape.git] / src / ui / dialog / align-and-distribute.cpp
index 024d4b2f12dff91a762342732b72c57d1f586bde..8c8d64ec00554f4d181ed0af779ec0081b22d0a5 100644 (file)
 #include "graphlayout/graphlayout.h"
 #include "inkscape.h"
 #include "macros.h"
-#include "node-context.h"  //For access to ShapeEditor
 #include "preferences.h"
 #include "removeoverlap/removeoverlap.h"
 #include "selection.h"
-#include "shape-editor.h" //For node align/distribute methods
 #include "sp-flowtext.h"
 #include "sp-item-transform.h"
 #include "sp-text.h"
 #include "text-editing.h"
 #include "tools-switch.h"
 #include "ui/icon-names.h"
+#include "ui/tool/node-tool.h"
+#include "ui/tool/multi-path-manipulator.h"
 #include "util/glib-list-iterators.h"
 #include "verbs.h"
 #include "widgets/icon.h"
@@ -429,12 +429,13 @@ private :
 
         if (!_dialog.getDesktop()) return;
         SPEventContext *event_context = sp_desktop_event_context(_dialog.getDesktop());
-        if (!SP_IS_NODE_CONTEXT (event_context)) return ;
+        if (!INK_IS_NODE_TOOL (event_context)) return;
+        InkNodeTool *nt = INK_NODE_TOOL(event_context);
 
         if (_distribute)
-            event_context->shape_editor->distribute((Geom::Dim2)_orientation);
+            nt->_multipath->distributeNodes(_orientation);
         else
-            event_context->shape_editor->align((Geom::Dim2)_orientation);
+            nt->_multipath->alignNodes(_orientation);
 
     }
 };
@@ -705,14 +706,16 @@ private :
         {
             if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) {
                 Inkscape::Text::Layout const *layout = te_get_layout(*it);
-                Geom::Point base = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(*it);
-                if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X];
-                if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y];
-                if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X];
-                if (base[Geom::Y] > b_max[Geom::Y]) b_max[Geom::Y] = base[Geom::Y];
-
-                Baselines b (*it, base, _orientation);
-                sorted.push_back(b);
+                boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+                if (pt) {
+                    Geom::Point base = *pt * sp_item_i2d_affine(*it);
+                    if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X];
+                    if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y];
+                    if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X];
+                    if (base[Geom::Y] > b_max[Geom::Y]) b_max[Geom::Y] = base[Geom::Y];
+                    Baselines b (*it, base, _orientation);
+                    sorted.push_back(b);
+                }
             }
         }
 
@@ -746,11 +749,14 @@ private :
             {
                 if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) {
                     Inkscape::Text::Layout const *layout = te_get_layout(*it);
-                    Geom::Point base = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(*it);
-                    Geom::Point t(0.0, 0.0);
-                    t[_orientation] = b_min[_orientation] - base[_orientation];
-                    sp_item_move_rel(*it, Geom::Translate(t));
-                    changed = true;
+                    boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+                    if (pt) {
+                        Geom::Point base = *pt * sp_item_i2d_affine(*it);
+                        Geom::Point t(0.0, 0.0);
+                        t[_orientation] = b_min[_orientation] - base[_orientation];
+                        sp_item_move_rel(*it, Geom::Translate(t));
+                        changed = true;
+                    }
                 }
             }