summaryrefslogtreecommitdiffstats
path: root/src/desktop.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/desktop.cpp')
-rw-r--r--src/desktop.cpp52
1 files changed, 23 insertions, 29 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 1264e0184..f798079fd 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -228,7 +228,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
controls = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
// Set the select tool as the active tool.
- set_event_context2("/tools/select");
+ setEventContext("/tools/select");
// display rect and zoom are now handled in sp_desktop_widget_realize()
@@ -322,7 +322,6 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
// canvas_debug = sp_canvas_item_new (main, SP_TYPE_CANVAS_DEBUG, NULL);
}
-
void SPDesktop::destroy()
{
_destroy_signal.emit(this);
@@ -331,6 +330,7 @@ void SPDesktop::destroy()
delete snapindicator;
snapindicator = NULL;
}
+
if (temporary_item_list) {
delete temporary_item_list;
temporary_item_list = NULL;
@@ -356,12 +356,6 @@ 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);
- if (event_context) {
- event_context->finish();
- delete event_context;
- event_context = NULL;
- }
-
delete layers;
if (layer_manager) {
@@ -656,34 +650,34 @@ SPDesktop::change_document (SPDocument *theDocument)
}
/**
- * Replaces the currently active tool with a new one.
+ * Replaces the currently active tool with a new one. Pass the empty string to
+ * unset and free the current tool.
*/
-void SPDesktop::set_event_context2(const std::string& toolName)
+void SPDesktop::setEventContext(const std::string& toolName)
{
- Inkscape::UI::Tools::ToolBase* old_tool = event_context;
-
- if (old_tool) {
- if (toolName.compare(old_tool->pref_observer->observed_path) != 0) {
- //g_message("Old tool: %s", old_tool->pref_observer->observed_path.c_str());
- //g_message("New tool: %s", toolName.c_str());
- old_tool->finish();
- delete old_tool;
+ if (event_context) {
+ if (toolName.compare(event_context->pref_observer->observed_path) != 0) {
+ event_context->finish();
+ delete event_context;
} else {
_event_context_changed_signal.emit(this, event_context);
return;
}
}
-
- Inkscape::UI::Tools::ToolBase* new_tool = ToolFactory::createObject(toolName);
- new_tool->desktop = this;
- new_tool->message_context = new Inkscape::MessageContext(this->messageStack());
- event_context = new_tool;
- new_tool->setup();
-
- // Make sure no delayed snapping events are carried over after switching tools
- // (this is only an additional safety measure against sloppy coding, because each
- // tool should take care of this by itself)
- sp_event_context_discard_delayed_snap_event(event_context);
+
+ if (toolName.empty()) {
+ event_context = nullptr;
+ } else {
+ event_context = ToolFactory::createObject(toolName);
+ event_context->desktop = this;
+ event_context->message_context = new Inkscape::MessageContext(this->messageStack());
+ event_context->setup();
+
+ // Make sure no delayed snapping events are carried over after switching tools
+ // (this is only an additional safety measure against sloppy coding, because each
+ // tool should take care of this by itself)
+ sp_event_context_discard_delayed_snap_event(event_context);
+ }
_event_context_changed_signal.emit(this, event_context);
}