summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Engel <markus.engel@tum.de>2013-04-12 22:37:18 +0000
committerMarkus Engel <markus.engel@tum.de>2013-04-12 22:37:18 +0000
commitfbb85064cfaaf03cc09bacedb16a8561f61f2b3d (patch)
treee2a26a8e4fbbcfd1180522452d7b4db23408d39d /src
parentvarious little changes (diff)
downloadinkscape-fbb85064cfaaf03cc09bacedb16a8561f61f2b3d.tar.gz
inkscape-fbb85064cfaaf03cc09bacedb16a8561f61f2b3d.zip
Added prefPaths to contexts; modified SPFactory
(bzr r11608.1.94)
Diffstat (limited to 'src')
-rw-r--r--src/arc-context.cpp2
-rw-r--r--src/arc-context.h2
-rw-r--r--src/box3d-context.cpp2
-rw-r--r--src/box3d-context.h2
-rw-r--r--src/connector-context.cpp2
-rw-r--r--src/connector-context.h2
-rw-r--r--src/desktop.cpp63
-rw-r--r--src/document.cpp5
-rw-r--r--src/dropper-context.cpp2
-rw-r--r--src/dropper-context.h2
-rw-r--r--src/dyna-draw-context.cpp2
-rw-r--r--src/dyna-draw-context.h2
-rw-r--r--src/eraser-context.cpp2
-rw-r--r--src/eraser-context.h2
-rw-r--r--src/event-context.cpp8
-rw-r--r--src/event-context.h2
-rw-r--r--src/flood-context.cpp2
-rw-r--r--src/flood-context.h2
-rw-r--r--src/gradient-context.cpp2
-rw-r--r--src/gradient-context.h2
-rw-r--r--src/lpe-tool-context.cpp2
-rw-r--r--src/lpe-tool-context.h2
-rw-r--r--src/measure-context.cpp2
-rw-r--r--src/measure-context.h2
-rw-r--r--src/mesh-context.cpp2
-rw-r--r--src/mesh-context.h2
-rw-r--r--src/pen-context.cpp2
-rw-r--r--src/pen-context.h2
-rw-r--r--src/pencil-context.cpp2
-rw-r--r--src/pencil-context.h2
-rw-r--r--src/rect-context.cpp3
-rw-r--r--src/rect-context.h2
-rw-r--r--src/select-context.cpp2
-rw-r--r--src/select-context.h2
-rw-r--r--src/sp-factory.cpp39
-rw-r--r--src/sp-factory.h42
-rw-r--r--src/sp-guide.cpp2
-rw-r--r--src/sp-object.cpp50
-rw-r--r--src/sp-rect.cpp2
-rw-r--r--src/sp-tref.cpp2
-rw-r--r--src/sp-use.cpp2
-rw-r--r--src/spiral-context.cpp2
-rw-r--r--src/spiral-context.h2
-rw-r--r--src/spray-context.cpp2
-rw-r--r--src/spray-context.h2
-rw-r--r--src/star-context.cpp2
-rw-r--r--src/star-context.h2
-rw-r--r--src/text-context.cpp2
-rw-r--r--src/text-context.h2
-rw-r--r--src/tweak-context.cpp2
-rw-r--r--src/tweak-context.h2
-rw-r--r--src/ui/tool/node-tool.cpp2
-rw-r--r--src/ui/tool/node-tool.h2
-rw-r--r--src/zoom-context.cpp2
-rw-r--r--src/zoom-context.h2
55 files changed, 207 insertions, 99 deletions
diff --git a/src/arc-context.cpp b/src/arc-context.cpp
index d28296ed8..cd9adece0 100644
--- a/src/arc-context.cpp
+++ b/src/arc-context.cpp
@@ -60,6 +60,8 @@ static void sp_arc_drag(SPArcContext *ec, Geom::Point pt, guint state);
static void sp_arc_finish(SPArcContext *ec);
static void sp_arc_cancel(SPArcContext *ec);
+const std::string SPArcContext::prefsPath = "/tools/shapes/arc";
+
G_DEFINE_TYPE(SPArcContext, sp_arc_context, SP_TYPE_EVENT_CONTEXT);
static void sp_arc_context_class_init(SPArcContextClass *klass)
diff --git a/src/arc-context.h b/src/arc-context.h
index 9834b3de7..7ab4ee884 100644
--- a/src/arc-context.h
+++ b/src/arc-context.h
@@ -40,6 +40,8 @@ public:
sigc::connection sel_changed_connection;
Inkscape::MessageContext *_message_context;
+
+ static const std::string prefsPath;
};
struct SPArcContextClass {
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index 1aca7a95e..a5b8c6e2f 100644
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
@@ -64,6 +64,8 @@ static gint sp_box3d_context_item_handler(SPEventContext *event_context, SPItem
static void sp_box3d_drag(Box3DContext &bc, guint state);
static void sp_box3d_finish(Box3DContext *bc);
+const std::string Box3DContext::prefsPath = "/tools/shapes/3dbox";
+
G_DEFINE_TYPE(Box3DContext, sp_box3d_context, SP_TYPE_EVENT_CONTEXT);
static void sp_box3d_context_class_init(Box3DContextClass *klass)
diff --git a/src/box3d-context.h b/src/box3d-context.h
index f52d78ce2..a724736be 100644
--- a/src/box3d-context.h
+++ b/src/box3d-context.h
@@ -61,6 +61,8 @@ public:
sigc::connection sel_changed_connection;
Inkscape::MessageContext *_message_context;
+
+ static const std::string prefsPath;
};
struct Box3DContextClass {
diff --git a/src/connector-context.cpp b/src/connector-context.cpp
index 7b29126e6..5c7bf97c8 100644
--- a/src/connector-context.cpp
+++ b/src/connector-context.cpp
@@ -171,6 +171,8 @@ static Inkscape::XML::NodeEventVector layer_repr_events = {
NULL /* order_changed */
};
+const std::string SPConnectorContext::prefsPath = "/tools/connector";
+
G_DEFINE_TYPE(SPConnectorContext, sp_connector_context, SP_TYPE_EVENT_CONTEXT);
static void
diff --git a/src/connector-context.h b/src/connector-context.h
index 32cebf439..f74903d74 100644
--- a/src/connector-context.h
+++ b/src/connector-context.h
@@ -98,6 +98,8 @@ public:
gchar *shref;
gchar *ehref;
SPCanvasItem *c0, *c1, *cl0, *cl1;
+
+ static const std::string prefsPath;
};
struct SPConnectorContextClass : public SPEventContextClass { };
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 0bf442b7a..626576c7f 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -227,7 +227,8 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
* call "set" instead of "push". Can we assume that there is only one
* context ever?
*/
- push_event_context (SP_TYPE_SELECT_CONTEXT, "/tools/select", SP_EVENT_CONTEXT_STATIC);
+ //push_event_context (SP_TYPE_SELECT_CONTEXT, "/tools/select", SP_EVENT_CONTEXT_STATIC);
+ set_event_context(SP_TYPE_SELECT_CONTEXT, "/tools/select");
// display rect and zoom are now handled in sp_desktop_widget_realize()
@@ -351,12 +352,14 @@ void SPDesktop::destroy()
g_signal_handlers_disconnect_by_func(G_OBJECT (main), (gpointer) G_CALLBACK(sp_desktop_root_handler), this);
g_signal_handlers_disconnect_by_func(G_OBJECT (drawing), (gpointer) G_CALLBACK(_arena_handler), this);
- while (event_context) {
- SPEventContext *ec = event_context;
- event_context = ec->next;
- sp_event_context_finish (ec);
- g_object_unref (G_OBJECT (ec));
- }
+// while (event_context) {
+// SPEventContext *ec = event_context;
+// event_context = ec->next;
+// sp_event_context_finish (ec);
+// g_object_unref (G_OBJECT (ec));
+// }
+ sp_event_context_finish(event_context);
+ g_object_unref(G_OBJECT(event_context));
if (_layer_hierarchy) {
delete _layer_hierarchy;
@@ -688,16 +691,16 @@ void
SPDesktop::set_event_context (GType type, const gchar *config)
{
SPEventContext *ec;
- while (event_context) {
+ //while (event_context) {
ec = event_context;
sp_event_context_deactivate (ec);
// we have to keep event_context valid during destruction - otherwise writing
// destructors is next to impossible
- SPEventContext *next = ec->next;
+ // SPEventContext *next = ec->next;
sp_event_context_finish (ec);
g_object_unref (G_OBJECT (ec));
- event_context = next;
- }
+ // event_context = next;
+ //}
// The event_context will be null. This means that it will be impossible
// to process any event invoked by the lines below. See for example bug
@@ -705,7 +708,7 @@ SPDesktop::set_event_context (GType type, const gchar *config)
// context to the node tool. In this bug the line bellow invokes GDK_LEAVE_NOTIFY
// events which cannot be handled and must be discarded.
ec = sp_event_context_new (type, this, config, SP_EVENT_CONTEXT_STATIC);
- ec->next = event_context;
+ // ec->next = event_context;
event_context = ec;
// Now the event_context has been set again and we can process all events again
sp_event_context_activate (ec);
@@ -718,24 +721,24 @@ SPDesktop::set_event_context (GType type, const gchar *config)
void
SPDesktop::push_event_context (GType type, const gchar *config, unsigned int key)
{
- SPEventContext *ref, *ec;
-
- if (event_context && event_context->key == key) return;
- ref = event_context;
- while (ref && ref->next && ref->next->key != key) ref = ref->next;
- if (ref && ref->next) {
- ec = ref->next;
- ref->next = ec->next;
- sp_event_context_finish (ec);
- g_object_unref (G_OBJECT (ec));
- }
-
- if (event_context) sp_event_context_deactivate (event_context);
- ec = sp_event_context_new (type, this, config, key);
- ec->next = event_context;
- event_context = ec;
- sp_event_context_activate (ec);
- _event_context_changed_signal.emit (this, ec);
+// SPEventContext *ref, *ec;
+//
+// if (event_context && event_context->key == key) return;
+// ref = event_context;
+// while (ref && ref->next && ref->next->key != key) ref = ref->next;
+// if (ref && ref->next) {
+// ec = ref->next;
+// ref->next = ec->next;
+// sp_event_context_finish (ec);
+// g_object_unref (G_OBJECT (ec));
+// }
+//
+// if (event_context) sp_event_context_deactivate (event_context);
+// ec = sp_event_context_new (type, this, config, key);
+// ec->next = event_context;
+// event_context = ec;
+// sp_event_context_activate (ec);
+// _event_context_changed_signal.emit (this, ec);
}
/**
diff --git a/src/document.cpp b/src/document.cpp
index 0a8b2e674..e58f581b5 100644
--- a/src/document.cpp
+++ b/src/document.cpp
@@ -349,10 +349,11 @@ SPDocument *SPDocument::createDoc(Inkscape::XML::Document *rdoc,
document->name = g_strdup(name);
// Create SPRoot element
- SPObject* rootObj = SPFactory::instance().createObject(*rroot);
+ const std::string typeString = NodeTraits::getTypeString(*rroot);
+ SPObject* rootObj = SPFactory::instance().createObject(typeString);
document->root = dynamic_cast<SPRoot*>(rootObj);
- if (document->root == nullptr) {
+ if (document->root == 0) {
// Node is not a valid root element
delete rootObj;
diff --git a/src/dropper-context.cpp b/src/dropper-context.cpp
index fefa1ccb6..c74950139 100644
--- a/src/dropper-context.cpp
+++ b/src/dropper-context.cpp
@@ -78,6 +78,8 @@ static SPEventContextClass *parent_class;
static GdkCursor *cursor_dropper_fill = NULL;
static GdkCursor *cursor_dropper_stroke = NULL;
+const std::string SPDropperContext::prefsPath = "/tools/dropper";
+
G_DEFINE_TYPE(SPDropperContext, sp_dropper_context, SP_TYPE_EVENT_CONTEXT);
static void
diff --git a/src/dropper-context.h b/src/dropper-context.h
index 300b77ed5..c1fb7f37f 100644
--- a/src/dropper-context.h
+++ b/src/dropper-context.h
@@ -33,6 +33,8 @@ public:
CDropperContext* cdroppercontext;
SPEventContext event_context;
+
+ static const std::string prefsPath;
};
struct SPDropperContextClass {
diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp
index cf958eaad..1bd9d8562 100644
--- a/src/dyna-draw-context.cpp
+++ b/src/dyna-draw-context.cpp
@@ -99,6 +99,8 @@ static Geom::Point sp_dyna_draw_get_npoint(SPDynaDrawContext const *ddc, Geom::P
static Geom::Point sp_dyna_draw_get_vpoint(SPDynaDrawContext const *ddc, Geom::Point n);
static void draw_temporary_box(SPDynaDrawContext *dc);
+const std::string SPDynaDrawContext::prefsPath = "/tools/calligraphic";
+
G_DEFINE_TYPE(SPDynaDrawContext, sp_dyna_draw_context, SP_TYPE_COMMON_CONTEXT);
static void
diff --git a/src/dyna-draw-context.h b/src/dyna-draw-context.h
index a53757c42..1d6992f94 100644
--- a/src/dyna-draw-context.h
+++ b/src/dyna-draw-context.h
@@ -58,6 +58,8 @@ public:
SPCanvasItem *hatch_area;
bool just_started_drawing;
bool trace_bg;
+
+ static const std::string prefsPath;
};
struct SPDynaDrawContextClass : public SPEventContextClass{};
diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp
index 01d3adcf6..00fb41004 100644
--- a/src/eraser-context.cpp
+++ b/src/eraser-context.cpp
@@ -101,6 +101,8 @@ static Geom::Point sp_eraser_get_npoint(SPEraserContext const *erc, Geom::Point
static Geom::Point sp_eraser_get_vpoint(SPEraserContext const *erc, Geom::Point n);
static void draw_temporary_box(SPEraserContext *dc);
+const std::string SPEraserContext::prefsPath = "/tools/eraser";
+
G_DEFINE_TYPE(SPEraserContext, sp_eraser_context, SP_TYPE_COMMON_CONTEXT);
static void
diff --git a/src/eraser-context.h b/src/eraser-context.h
index f8f0cf2ff..dff4d2db5 100644
--- a/src/eraser-context.h
+++ b/src/eraser-context.h
@@ -43,6 +43,8 @@ class SPEraserContext : public SPCommonContext {
public:
SPEraserContext();
CEraserContext* cerasercontext;
+
+ static const std::string prefsPath;
};
struct SPEraserContextClass : public SPEventContextClass{};
diff --git a/src/event-context.cpp b/src/event-context.cpp
index c4152a71a..b5677a5fc 100644
--- a/src/event-context.cpp
+++ b/src/event-context.cpp
@@ -127,7 +127,7 @@ SPEventContext::SPEventContext() {
event_context->hot_x = 0;
event_context->yp = 0;
event_context->within_tolerance = false;
- event_context->next = 0;
+ //event_context->next = 0;
event_context->tolerance = 0;
event_context->key = 0;
event_context->item_to_select = 0;
@@ -958,9 +958,9 @@ void sp_event_context_finish(SPEventContext *ec) {
ec->enableSelectionCue(false);
- if (ec->next) {
- g_warning("Finishing event context with active link\n");
- }
+// if (ec->next) {
+// g_warning("Finishing event context with active link\n");
+// }
// if ((SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish)
// (SP_EVENT_CONTEXT_CLASS(G_OBJECT_GET_CLASS(ec)))->finish(ec);
diff --git a/src/event-context.h b/src/event-context.h
index 0ae621178..52d16666c 100644
--- a/src/event-context.h
+++ b/src/event-context.h
@@ -116,7 +116,7 @@ public:
CEventContext* ceventcontext;
/// Desktop eventcontext stack
- SPEventContext *next;
+ //SPEventContext *next;
unsigned key;
SPDesktop *desktop;
Inkscape::Preferences::Observer *pref_observer;
diff --git a/src/flood-context.cpp b/src/flood-context.cpp
index 39002d39a..fedd51a4b 100644
--- a/src/flood-context.cpp
+++ b/src/flood-context.cpp
@@ -84,6 +84,8 @@ static gint sp_flood_context_item_handler(SPEventContext *event_context, SPItem
static void sp_flood_finish(SPFloodContext *rc);
+const std::string SPFloodContext::prefsPath = "/tools/paintbucket";
+
G_DEFINE_TYPE(SPFloodContext, sp_flood_context, SP_TYPE_EVENT_CONTEXT);
static void sp_flood_context_class_init(SPFloodContextClass *klass)
diff --git a/src/flood-context.h b/src/flood-context.h
index 0b19610a5..a93c98c73 100644
--- a/src/flood-context.h
+++ b/src/flood-context.h
@@ -41,6 +41,8 @@ public:
sigc::connection sel_changed_connection;
Inkscape::MessageContext *_message_context;
+
+ static const std::string prefsPath;
};
struct SPFloodContextClass {
diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp
index 50863565d..3d9fa9c3f 100644
--- a/src/gradient-context.cpp
+++ b/src/gradient-context.cpp
@@ -59,6 +59,8 @@ static gint sp_gradient_context_root_handler(SPEventContext *event_context, GdkE
static void sp_gradient_drag(SPGradientContext &rc, Geom::Point const pt, guint state, guint32 etime);
+const std::string SPGradientContext::prefsPath = "/tools/gradient";
+
G_DEFINE_TYPE(SPGradientContext, sp_gradient_context, SP_TYPE_EVENT_CONTEXT);
static void sp_gradient_context_class_init(SPGradientContextClass *klass)
diff --git a/src/gradient-context.h b/src/gradient-context.h
index 1746c9a73..c6bbdc491 100644
--- a/src/gradient-context.h
+++ b/src/gradient-context.h
@@ -44,6 +44,8 @@ public:
sigc::connection *selcon;
sigc::connection *subselcon;
+
+ static const std::string prefsPath;
};
struct SPGradientContextClass {
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index 3d81efc00..93a548a8e 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -64,6 +64,8 @@ SubtoolEntry lpesubtools[] = {
{Inkscape::LivePathEffect::MIRROR_SYMMETRY, "draw-geometry-mirror"}
};
+const std::string SPLPEToolContext::prefsPath = "/tools/lpetool";
+
G_DEFINE_TYPE(SPLPEToolContext, sp_lpetool_context, SP_TYPE_PEN_CONTEXT);
static void
diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h
index d108fb821..c4b507f3d 100644
--- a/src/lpe-tool-context.h
+++ b/src/lpe-tool-context.h
@@ -62,6 +62,8 @@ public:
sigc::connection sel_changed_connection;
sigc::connection sel_modified_connection;
+
+ static const std::string prefsPath;
};
struct SPLPEToolContextClass : public SPEventContextClass{};
diff --git a/src/measure-context.cpp b/src/measure-context.cpp
index 8b0a3608f..f56239690 100644
--- a/src/measure-context.cpp
+++ b/src/measure-context.cpp
@@ -64,6 +64,8 @@ boost::optional<Geom::Point> lastEnd;
std::vector<Inkscape::Display::TemporaryItem*> measure_tmp_items;
+const std::string SPMeasureContext::prefsPath = "/tools/measure";
+
G_DEFINE_TYPE(SPMeasureContext, sp_measure_context, SP_TYPE_EVENT_CONTEXT);
namespace
diff --git a/src/measure-context.h b/src/measure-context.h
index 4e3ad4804..0fcee314d 100644
--- a/src/measure-context.h
+++ b/src/measure-context.h
@@ -27,6 +27,8 @@ public:
//SPEventContext event_context;
SPCanvasItem *grabbed;
+
+ static const std::string prefsPath;
};
struct SPMeasureContextClass {
diff --git a/src/mesh-context.cpp b/src/mesh-context.cpp
index 6c7fe05d8..ecfceae20 100644
--- a/src/mesh-context.cpp
+++ b/src/mesh-context.cpp
@@ -61,6 +61,8 @@ static gint sp_mesh_context_root_handler(SPEventContext *event_context, GdkEvent
static void sp_mesh_drag(SPMeshContext &rc, Geom::Point const pt, guint state, guint32 etime);
+const std::string SPMeshContext::prefsPath = "/tools/mesh";
+
G_DEFINE_TYPE(SPMeshContext, sp_mesh_context, SP_TYPE_EVENT_CONTEXT);
static void sp_mesh_context_class_init(SPMeshContextClass *klass)
diff --git a/src/mesh-context.h b/src/mesh-context.h
index 887bfcf17..2d207e536 100644
--- a/src/mesh-context.h
+++ b/src/mesh-context.h
@@ -46,6 +46,8 @@ public:
sigc::connection *selcon;
sigc::connection *subselcon;
+
+ static const std::string prefsPath;
};
struct SPMeshContextClass {
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 333f9ef87..180152642 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -80,6 +80,8 @@ static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Po
static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical
+const std::string SPPenContext::prefsPath = "/tools/freehand/pen";
+
G_DEFINE_TYPE(SPPenContext, sp_pen_context, SP_TYPE_DRAW_CONTEXT);
/**
diff --git a/src/pen-context.h b/src/pen-context.h
index 617753c3b..fc5378113 100644
--- a/src/pen-context.h
+++ b/src/pen-context.h
@@ -62,6 +62,8 @@ public:
SPCtrlLine *cl1;
unsigned int events_disabled : 1;
+
+ static const std::string prefsPath;
};
/// The SPPenContext vtable (empty).
diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp
index 47580b4d2..0b3955a0c 100644
--- a/src/pencil-context.cpp
+++ b/src/pencil-context.cpp
@@ -68,6 +68,8 @@ static bool pencil_within_tolerance = false;
static bool in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; }
+const std::string SPPencilContext::prefsPath = "/tools/freehand/pencil";
+
G_DEFINE_TYPE(SPPencilContext, sp_pencil_context, SP_TYPE_DRAW_CONTEXT);
/**
diff --git a/src/pencil-context.h b/src/pencil-context.h
index afe375fd8..4174e38ae 100644
--- a/src/pencil-context.h
+++ b/src/pencil-context.h
@@ -42,6 +42,8 @@ public:
Geom::Piecewise<Geom::D2<Geom::SBasis> > sketch_interpolation; // the current proposal from the sketched paths
unsigned sketch_n; // number of sketches done
+
+ static const std::string prefsPath;
};
/// The SPPencilContext vtable (empty).
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index 45fc5a87e..b5149ea22 100644
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
@@ -62,6 +62,9 @@ static void sp_rect_drag(SPRectContext &rc, Geom::Point const pt, guint state);
static void sp_rect_finish(SPRectContext *rc);
static void sp_rect_cancel(SPRectContext *rc);
+
+const std::string SPRectContext::prefsPath = "/tools/shapes/rect";
+
G_DEFINE_TYPE(SPRectContext, sp_rect_context, SP_TYPE_EVENT_CONTEXT);
static void sp_rect_context_class_init(SPRectContextClass *klass)
diff --git a/src/rect-context.h b/src/rect-context.h
index 88c964c41..b840e1b2c 100644
--- a/src/rect-context.h
+++ b/src/rect-context.h
@@ -41,6 +41,8 @@ public:
sigc::connection sel_changed_connection;
Inkscape::MessageContext *_message_context;
+
+ static const std::string prefsPath;
};
struct SPRectContextClass {
diff --git a/src/select-context.cpp b/src/select-context.cpp
index b28920868..7b811e16e 100644
--- a/src/select-context.cpp
+++ b/src/select-context.cpp
@@ -69,6 +69,8 @@ static gint xp = 0, yp = 0; // where drag started
static gint tolerance = 0;
static bool within_tolerance = false;
+const std::string SPSelectContext::prefsPath = "/tools/select";
+
G_DEFINE_TYPE(SPSelectContext, sp_select_context, SP_TYPE_EVENT_CONTEXT);
static void
diff --git a/src/select-context.h b/src/select-context.h
index 58a816df3..791569bcd 100644
--- a/src/select-context.h
+++ b/src/select-context.h
@@ -52,6 +52,8 @@ public:
SPCanvasItem *grabbed;
Inkscape::SelTrans *_seltrans;
Inkscape::SelectionDescriber *_describer;
+
+ static const std::string prefsPath;
};
struct SPSelectContextClass {
diff --git a/src/sp-factory.cpp b/src/sp-factory.cpp
index 272584ca6..389589d09 100644
--- a/src/sp-factory.cpp
+++ b/src/sp-factory.cpp
@@ -10,7 +10,7 @@ SPFactory::TypeNotRegistered::TypeNotRegistered(const std::string& type)
: std::exception(), type(type) {
}
-const char* SPFactory::TypeNotRegistered::what() const noexcept {
+const char* SPFactory::TypeNotRegistered::what() const throw() {
return type.c_str();
}
@@ -19,39 +19,16 @@ SPFactory& SPFactory::instance() {
return factory;
}
-bool SPFactory::registerObject(const std::string& id, std::function<SPObject* ()> createFunction) {
+bool SPFactory::registerObject(const std::string& id, CreateFunction* createFunction) {
return this->objectMap.insert(std::make_pair(id, createFunction)).second;
-
- // replace when gcc supports this
- //return this->objectMap.emplace(id, createFunction).second;
}
-SPObject* SPFactory::createObject(const Inkscape::XML::Node& id) const {
- std::string name;
-
- switch (id.type()) {
- case Inkscape::XML::TEXT_NODE:
- name = "string";
- break;
-
- case Inkscape::XML::ELEMENT_NODE: {
- gchar const* const sptype = id.attribute("sodipodi:type");
-
- if (sptype) {
- name = sptype;
- } else {
- name = id.name();
- }
- break;
- }
- default:
- break;
- }
+SPObject* SPFactory::createObject(const std::string& id) const {
+ std::map<const std::string, CreateFunction*>::const_iterator it = this->objectMap.find(id);
- try {
- std::function<SPObject* ()> createFunction = this->objectMap.at(name);
- return createFunction();
- } catch (const std::out_of_range& ex) {
- std::throw_with_nested(TypeNotRegistered(name));
+ if (it == this->objectMap.end()) {
+ throw TypeNotRegistered(id);
}
+
+ return (*it).second();
}
diff --git a/src/sp-factory.h b/src/sp-factory.h
index 359ac7acc..645644412 100644
--- a/src/sp-factory.h
+++ b/src/sp-factory.h
@@ -1,7 +1,6 @@
#pragma once
#include <exception>
-#include <functional>
#include <map>
#include <string>
@@ -21,7 +20,7 @@ public:
class TypeNotRegistered : public std::exception {
public:
TypeNotRegistered(const std::string& type);
- const char* what() const noexcept;
+ const char* what() const throw();
private:
const std::string type;
@@ -29,9 +28,42 @@ public:
static SPFactory& instance();
- bool registerObject(const std::string& id, std::function<SPObject* ()> createFunction);
- SPObject* createObject(const Inkscape::XML::Node& id) const;
+ typedef SPObject* CreateFunction();
+
+ bool registerObject(const std::string& id, CreateFunction* createFunction);
+ SPObject* createObject(const std::string& id) const;
private:
- std::map<const std::string, std::function<SPObject* ()>> objectMap;
+ std::map<const std::string, CreateFunction*> objectMap;
+};
+
+
+#include "xml/node.h"
+
+struct NodeTraits {
+ static std::string getTypeString(const Inkscape::XML::Node& node) {
+ std::string name;
+
+ switch (node.type()) {
+ case Inkscape::XML::TEXT_NODE:
+ name = "string";
+ break;
+
+ case Inkscape::XML::ELEMENT_NODE: {
+ gchar const* const sptype = node.attribute("sodipodi:type");
+
+ if (sptype) {
+ name = sptype;
+ } else {
+ name = node.name();
+ }
+ break;
+ }
+ default:
+ name = "";
+ break;
+ }
+
+ return name;
+ }
};
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 3182195ff..4fc6e34bb 100644
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
@@ -59,7 +59,7 @@ static void sp_guide_get_property(GObject *object, guint prop_id, GValue *value,
#include "sp-factory.h"
namespace {
- SPGuide* createGuide() {
+ SPObject* createGuide() {
return new SPGuide();
}
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index dc9b1a2e5..363a05579 100644
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
@@ -214,24 +214,24 @@ public:
-#include <stdexcept>
-#include <exception>
-
-void log_exception(std::exception_ptr exception) {
- try {
- std::rethrow_exception(exception);
- } catch (const std::exception& e) {
- std::cerr << "Caught Exception of type " << std::string(typeid(e).name()) << '\n';
- std::cerr << "Message: " << std::string(e.what()) << '\n';
-
- try {
- std::rethrow_if_nested(e);
- } catch (...) {
- std::cerr << "Inner Exception: \n";
- log_exception(std::current_exception());
- }
- }
-}
+//#include <stdexcept>
+//#include <exception>
+//
+//void log_exception(std::exception_ptr exception) {
+// try {
+// std::rethrow_exception(exception);
+// } catch (const std::exception& e) {
+// std::cerr << "Caught Exception of type " << std::string(typeid(e).name()) << '\n';
+// std::cerr << "Message: " << std::string(e.what()) << '\n';
+//
+// try {
+// std::rethrow_if_nested(e);
+// } catch (...) {
+// std::cerr << "Inner Exception: \n";
+// log_exception(std::current_exception());
+// }
+// }
+//}
@@ -628,7 +628,9 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
SPObject* object = this;
try {
- SPObject* ochild = SPFactory::instance().createObject(*child);
+ const std::string typeString = NodeTraits::getTypeString(*child);
+
+ SPObject* ochild = SPFactory::instance().createObject(typeString);
SPObject *prev = ref ? object->get_child_by_repr(ref) : NULL;
object->attach(ochild, prev);
@@ -636,7 +638,8 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
ochild->invoke_build(object->document, child, object->cloned);
} catch (const SPFactory::TypeNotRegistered& e) {
- log_exception(std::current_exception());
+ //log_exception(std::current_exception());
+ g_warning("TypeNotRegistered exception: %s", e.what());
}
}
@@ -693,13 +696,16 @@ void SPObject::build(SPDocument *document, Inkscape::XML::Node *repr) {
// }
try {
- SPObject* child = SPFactory::instance().createObject(*rchild);
+ const std::string typeString = NodeTraits::getTypeString(*rchild);
+
+ SPObject* child = SPFactory::instance().createObject(typeString);
object->attach(child, object->lastChild());
sp_object_unref(child, NULL);
child->invoke_build(document, rchild, object->cloned);
} catch (const SPFactory::TypeNotRegistered& e) {
- log_exception(std::current_exception());
+ //log_exception(std::current_exception());
+ g_warning("TypeNotRegistered exception: %s", e.what());
}
}
}
diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp
index c150267fc..d16f16a9b 100644
--- a/src/sp-rect.cpp
+++ b/src/sp-rect.cpp
@@ -34,7 +34,7 @@
#include "sp-factory.h"
namespace {
- SPRect* createRect() {
+ SPObject* createRect() {
return new SPRect();
}
diff --git a/src/sp-tref.cpp b/src/sp-tref.cpp
index 223cf3cec..87e8498f3 100644
--- a/src/sp-tref.cpp
+++ b/src/sp-tref.cpp
@@ -405,7 +405,7 @@ void sp_tref_update_text(SPTRef *tref)
Inkscape::XML::Document *xml_doc = tref->document->getReprDoc();
Inkscape::XML::Node *newStringRepr = xml_doc->createTextNode(charData.c_str());
- tref->stringChild = SPFactory::instance().createObject(*newStringRepr); //SP_OBJECT(g_object_new(sp_repr_type_lookup(newStringRepr), NULL));
+ tref->stringChild = SPFactory::instance().createObject(NodeTraits::getTypeString(*newStringRepr));
// Add this SPString as a child of the tref
tref->attach(tref->stringChild, tref->lastChild());
diff --git a/src/sp-use.cpp b/src/sp-use.cpp
index 7c490ce41..f565cba20 100644
--- a/src/sp-use.cpp
+++ b/src/sp-use.cpp
@@ -453,7 +453,7 @@ sp_use_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, SPUse *use)
// }
// }
- SPObject* obj = SPFactory::instance().createObject(*childrepr);
+ SPObject* obj = SPFactory::instance().createObject(NodeTraits::getTypeString(*childrepr));
if (SP_IS_ITEM(obj)) {
use->child = obj;
diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp
index 48be26037..7e3aed1b9 100644
--- a/src/spiral-context.cpp
+++ b/src/spiral-context.cpp
@@ -57,6 +57,8 @@ static void sp_spiral_drag(SPSpiralContext *sc, Geom::Point const &p, guint stat
static void sp_spiral_finish(SPSpiralContext *sc);
static void sp_spiral_cancel(SPSpiralContext *sc);
+const std::string SPSpiralContext::prefsPath = "/tools/shapes/spiral";
+
G_DEFINE_TYPE(SPSpiralContext, sp_spiral_context, SP_TYPE_EVENT_CONTEXT);
static void
diff --git a/src/spiral-context.h b/src/spiral-context.h
index fc91ac26b..bd111f9c9 100644
--- a/src/spiral-context.h
+++ b/src/spiral-context.h
@@ -43,6 +43,8 @@ public:
sigc::connection sel_changed_connection;
Inkscape::MessageContext *_message_context;
+
+ static const std::string prefsPath;
};
struct SPSpiralContextClass {
diff --git a/src/spray-context.cpp b/src/spray-context.cpp
index 855e0508a..7d4980355 100644
--- a/src/spray-context.cpp
+++ b/src/spray-context.cpp
@@ -84,6 +84,8 @@ static void sp_spray_context_setup(SPEventContext *ec);
static void sp_spray_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val);
static gint sp_spray_context_root_handler(SPEventContext *ec, GdkEvent *event);
+const std::string SPSprayContext::prefsPath = "/tools/spray";
+
G_DEFINE_TYPE(SPSprayContext, sp_spray_context, SP_TYPE_EVENT_CONTEXT);
/**
diff --git a/src/spray-context.h b/src/spray-context.h
index 79175ccc2..06aecb2c8 100644
--- a/src/spray-context.h
+++ b/src/spray-context.h
@@ -93,6 +93,8 @@ public:
SPCanvasItem *dilate_area;
sigc::connection style_set_connection;
+
+ static const std::string prefsPath;
};
struct SPSprayContextClass
diff --git a/src/star-context.cpp b/src/star-context.cpp
index ab75813fe..6979d51a2 100644
--- a/src/star-context.cpp
+++ b/src/star-context.cpp
@@ -61,6 +61,8 @@ static void sp_star_drag (SPStarContext * sc, Geom::Point p, guint state);
static void sp_star_finish (SPStarContext * sc);
static void sp_star_cancel(SPStarContext * sc);
+const std::string SPStarContext::prefsPath = "/tools/shapes/star";
+
G_DEFINE_TYPE(SPStarContext, sp_star_context, SP_TYPE_EVENT_CONTEXT);
static void
diff --git a/src/star-context.h b/src/star-context.h
index ce47126e6..ca5d3517e 100644
--- a/src/star-context.h
+++ b/src/star-context.h
@@ -49,6 +49,8 @@ public:
sigc::connection sel_changed_connection;
Inkscape::MessageContext *_message_context;
+
+ static const std::string prefsPath;
};
struct SPStarContextClass {
diff --git a/src/text-context.cpp b/src/text-context.cpp
index f268e8f67..1f8262e3f 100644
--- a/src/text-context.cpp
+++ b/src/text-context.cpp
@@ -79,6 +79,8 @@ static gint sptc_focus_in(GtkWidget *widget, GdkEventFocus *event, SPTextContext
static gint sptc_focus_out(GtkWidget *widget, GdkEventFocus *event, SPTextContext *tc);
static void sptc_commit(GtkIMContext *imc, gchar *string, SPTextContext *tc);
+const std::string SPTextContext::prefsPath = "/tools/text";
+
G_DEFINE_TYPE(SPTextContext, sp_text_context, SP_TYPE_EVENT_CONTEXT);
static void sp_text_context_class_init(SPTextContextClass *klass)
diff --git a/src/text-context.h b/src/text-context.h
index b1ccf5794..3214b08cd 100644
--- a/src/text-context.h
+++ b/src/text-context.h
@@ -76,6 +76,8 @@ public:
/* Preedit String */
gchar* preedit_string;
+
+ static const std::string prefsPath;
};
struct SPTextContextClass {
diff --git a/src/tweak-context.cpp b/src/tweak-context.cpp
index d41eebec8..9fca2183b 100644
--- a/src/tweak-context.cpp
+++ b/src/tweak-context.cpp
@@ -87,6 +87,8 @@ static void sp_tweak_context_setup(SPEventContext *ec);
static void sp_tweak_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val);
static gint sp_tweak_context_root_handler(SPEventContext *ec, GdkEvent *event);
+const std::string SPTweakContext::prefsPath = "/tools/tweak";
+
G_DEFINE_TYPE(SPTweakContext, sp_tweak_context, SP_TYPE_EVENT_CONTEXT);
static void
diff --git a/src/tweak-context.h b/src/tweak-context.h
index 56539fc62..e5033c0dc 100644
--- a/src/tweak-context.h
+++ b/src/tweak-context.h
@@ -82,6 +82,8 @@ public:
bool do_o;
sigc::connection style_set_connection;
+
+ static const std::string prefsPath;
};
struct SPTweakContextClass
diff --git a/src/ui/tool/node-tool.cpp b/src/ui/tool/node-tool.cpp
index 8d8db772a..8887d4334 100644
--- a/src/ui/tool/node-tool.cpp
+++ b/src/ui/tool/node-tool.cpp
@@ -124,6 +124,8 @@ void handleControlUiStyleChange(InkNodeTool *nt);
//} // anonymous namespace
+const std::string InkNodeTool::prefsPath = "/tools/nodes";
+
G_DEFINE_TYPE(InkNodeTool, ink_node_tool, SP_TYPE_EVENT_CONTEXT);
static void
diff --git a/src/ui/tool/node-tool.h b/src/ui/tool/node-tool.h
index f997aee11..b5ce65513 100644
--- a/src/ui/tool/node-tool.h
+++ b/src/ui/tool/node-tool.h
@@ -74,6 +74,8 @@ public:
unsigned single_node_transform_handles : 1;
unsigned edit_clipping_paths : 1;
unsigned edit_masks : 1;
+
+ static const std::string prefsPath;
};
struct InkNodeToolClass {
diff --git a/src/zoom-context.cpp b/src/zoom-context.cpp
index ac8dd6138..92c50b148 100644
--- a/src/zoom-context.cpp
+++ b/src/zoom-context.cpp
@@ -37,6 +37,8 @@ static gint tolerance = 0;
static bool within_tolerance = false;
static bool escaped;
+const std::string SPZoomContext::prefsPath = "/tools/zoom";
+
G_DEFINE_TYPE(SPZoomContext, sp_zoom_context, SP_TYPE_EVENT_CONTEXT);
static void sp_zoom_context_class_init(SPZoomContextClass *klass)
diff --git a/src/zoom-context.h b/src/zoom-context.h
index a73fd2bc2..4342cc982 100644
--- a/src/zoom-context.h
+++ b/src/zoom-context.h
@@ -28,6 +28,8 @@ public:
//SPEventContext event_context;
SPCanvasItem *grabbed;
+
+ static const std::string prefsPath;
};
struct SPZoomContextClass {