Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / lpe-tool-context.cpp
index ec4cd068948bee302d8a981b8ce424c1a7c19ecd..30248edd0bc148703fa91badda8f82ea6e65f8d0 100644 (file)
@@ -27,7 +27,7 @@
 #include <gtk/gtk.h>
 #include "desktop.h"
 #include "message-context.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "shape-editor.h"
 #include "selection.h"
 #include "desktop-handles.h"
@@ -45,7 +45,7 @@ static void sp_lpetool_context_init(SPLPEToolContext *erc);
 static void sp_lpetool_context_dispose(GObject *object);
 
 static void sp_lpetool_context_setup(SPEventContext *ec);
-static void sp_lpetool_context_set(SPEventContext *ec, gchar const *key, gchar const *val);
+static void sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *);
 static gint sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
 static gint sp_lpetool_context_root_handler(SPEventContext *ec, GdkEvent *event);
 
@@ -164,13 +164,15 @@ sp_lpetool_context_setup(SPEventContext *ec)
 
 // TODO temp force:
     ec->enableSelectionCue();
+    
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
     if (item) {
         lc->shape_editor->set_item(item, SH_NODEPATH);
         lc->shape_editor->set_item(item, SH_KNOTHOLDER);
     }
 
-    if (prefs_get_int_attribute("tools.lpetool", "selcue", 0) != 0) {
+    if (prefs->getBool("/tools/lpetool/selcue")) {
         ec->enableSelectionCue();
     }
 
@@ -199,18 +201,19 @@ sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpointer da
 }
 
 static void
-sp_lpetool_context_set(SPEventContext *ec, gchar const *key, gchar const *val)
+sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val)
 {
-    // FIXME: how to set this correcly? the value from preferences-skeleton.h doesn't seem to get
-    // read (it wants to set drag = 1)
-    lpetool_parent_class->set(ec, key, "drag");
+    if (val->getEntryName() == "mode") {
+        Inkscape::Preferences::get()->setString("/tools/geometric/mode", "drag");
+        SP_PEN_CONTEXT(ec)->mode = SP_PEN_CONTEXT_MODE_DRAG;
+    }
 
-    /**
+    /*
     //pass on up to parent class to handle common attributes.
     if ( lpetool_parent_class->set ) {
         lpetool_parent_class->set(ec, key, val);
     }
-    **/
+    */
 }
 
 static gint 
@@ -263,7 +266,9 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
         case GDK_BUTTON_PRESS:
             if (event->button.button == 1 && !event_context->space_panning) {
                 if (lc->mode == Inkscape::LivePathEffect::INVALID_LPE) {
-                    // don't do anything for now if we are inactive
+                    // don't do anything for now if we are inactive (except clearing the selection
+                    // since this was a click into empty space)
+                    selection->clear();
                     desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Choose a construction tool from the toolbar."));
                     ret = true;
                     break;
@@ -277,10 +282,11 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
 
                 using namespace Inkscape::LivePathEffect;
 
-                int mode = prefs_get_int_attribute("tools.lpetool", "mode", 0);
+                Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+                int mode = prefs->getInt("/tools/lpetool/mode");
                 EffectType type = lpesubtools[mode];
 
-                //bool over_stroke = lc->shape_editor->is_over_stroke(NR::Point(event->button.x, event->button.y), true);
+                //bool over_stroke = lc->shape_editor->is_over_stroke(Geom::Point(event->button.x, event->button.y), true);
 
                 sp_pen_context_wait_for_LPE_mouse_clicks(lc, type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type));
 
@@ -295,7 +301,7 @@ sp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
             }
 
             bool over_stroke = false;
-            over_stroke = lc->shape_editor->is_over_stroke(NR::Point(event->motion.x, event->motion.y), false);
+            over_stroke = lc->shape_editor->is_over_stroke(Geom::Point(event->motion.x, event->motion.y), false);
 
             if (over_stroke) {
                 event_context->cursor_shape = cursor_node_xpm;
@@ -369,7 +375,7 @@ lpetool_mode_to_index(Inkscape::LivePathEffect::EffectType const type) {
  * Checks whether an item has a construction applied as LPE and if so returns the index in
  * lpesubtools of this construction
  */
-int lpetool_item_has_construction(SPLPEToolContext *lc, SPItem *item)
+int lpetool_item_has_construction(SPLPEToolContext */*lc*/, SPItem *item)
 {
     if (!SP_IS_LPE_ITEM(item)) {
         return -1;
@@ -417,11 +423,12 @@ void
 lpetool_get_limiting_bbox_corners(SPDocument *document, Geom::Point &A, Geom::Point &B) {
     Geom::Coord w = sp_document_width(document);
     Geom::Coord h = sp_document_height(document);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
 
-    double ulx = prefs_get_double_attribute ("tools.lpetool", "bbox_upperleftx", 0);
-    double uly = prefs_get_double_attribute ("tools.lpetool", "bbox_upperlefty", 0);
-    double lrx = prefs_get_double_attribute ("tools.lpetool", "bbox_lowerrightx", w);
-    double lry = prefs_get_double_attribute ("tools.lpetool", "bbox_lowerrighty", h);
+    double ulx = prefs->getDouble("/tools/lpetool/bbox_upperleftx", 0);
+    double uly = prefs->getDouble("/tools/lpetool/bbox_upperlefty", 0);
+    double lrx = prefs->getDouble("/tools/lpetool/bbox_lowerrightx", w);
+    double lry = prefs->getDouble("/tools/lpetool/bbox_lowerrighty", h);
 
     A = Geom::Point(ulx, uly);
     B = Geom::Point(lrx, lry);
@@ -439,14 +446,15 @@ lpetool_context_reset_limiting_bbox(SPLPEToolContext *lc)
         lc->canvas_bbox = NULL;
     }
 
-    if (prefs_get_int_attribute("tools.lpetool", "show_bbox", 1) == 0)
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if (!prefs->getBool("/tools/lpetool/show_bbox", true))
         return;
 
     SPDocument *document = sp_desktop_document(lc->desktop);
 
     Geom::Point A, B;
     lpetool_get_limiting_bbox_corners(document, A, B);
-    NR::Matrix doc2dt(lc->desktop->doc2dt());
+    Geom::Matrix doc2dt(lc->desktop->doc2dt());
     A *= doc2dt;
     B *= doc2dt;
 
@@ -459,7 +467,7 @@ lpetool_context_reset_limiting_bbox(SPLPEToolContext *lc)
 
 static void
 set_pos_and_anchor(SPCanvasText *canvas_text, const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
-                   const double t, const double length, bool use_curvature = false)
+                   const double t, const double length, bool /*use_curvature*/ = false)
 {
     using namespace Geom;
 
@@ -477,10 +485,11 @@ set_pos_and_anchor(SPCanvasText *canvas_text, const Geom::Piecewise<Geom::D2<Geo
 void
 lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *selection)
 {
-    bool show = prefs_get_int_attribute ("tools.lpetool", "show_measuring_info",  1) == 1 ? true : false;
     if (!selection) {
         selection = sp_desktop_selection(lc->desktop);
     }
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    bool show = prefs->getBool("/tools/lpetool/show_measuring_info",  true);
 
     SPPath *path;
     SPCurve *curve;
@@ -498,7 +507,7 @@ lpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *select
             if (!show)
                 sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));
 
-            SPUnitId unitid = static_cast<SPUnitId>(prefs_get_int_attribute("tools.lpetool", "unitid", SP_UNIT_PX));
+            SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
             SPUnit unit = sp_unit_get_by_id(unitid);
 
             lengthval = Geom::length(pwd2);
@@ -526,6 +535,7 @@ lpetool_delete_measuring_items(SPLPEToolContext *lc)
 void
 lpetool_update_measuring_items(SPLPEToolContext *lc)
 {
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     SPPath *path;
     SPCurve *curve;
     double lengthval;
@@ -535,7 +545,7 @@ lpetool_update_measuring_items(SPLPEToolContext *lc)
         path = i->first;
         curve = sp_shape_get_curve(SP_SHAPE(path));
         Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());
-        SPUnitId unitid = static_cast<SPUnitId>(prefs_get_int_attribute("tools.lpetool", "unitid", SP_UNIT_PX));
+        SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
         SPUnit unit = sp_unit_get_by_id(unitid);
         lengthval = Geom::length(pwd2);
         gboolean success;