From 09ce234c1fc367a2607936e6cf106cb24c60e94f Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Wed, 3 Jul 2013 20:06:11 +0100 Subject: Modified dbus interface so that it works in console mode (--dbus-listen) Modified action context setup so that in console mode, when a document is added to the main inkscape app instance, it gets a selection model and layer model automatically set up for it Made a couple more verbs work in console mode (bzr r12387.1.4) --- src/inkscape.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'src/inkscape.cpp') diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 125a7176a..2e60ee5ea 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -58,12 +58,14 @@ #include "extension/system.h" #include "inkscape-private.h" #include "io/sys.h" +#include "layer-model.h" #include "message-stack.h" #include "preferences.h" #include "resource-manager.h" #include "selection.h" #include "ui/dialog/debug.h" #include "xml/repr.h" +#include "helper/action-context.h" #include "helper/sp-marshal.h" static Inkscape::Application *inkscape = NULL; @@ -105,10 +107,27 @@ static void inkscape_dispose (GObject *object); static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop); static void inkscape_deactivate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop); +class AppSelectionModel { + Inkscape::LayerModel _layer_model; + Inkscape::Selection *_selection; + +public: + AppSelectionModel(SPDocument *doc) { + _layer_model.setDocument(doc); + // TODO: is this really how we should manage the lifetime of the selection? + // I just copied this from the initialization of the Selection in SPDesktop. + // When and how is it actually released? + _selection = Inkscape::GC::release(new Inkscape::Selection(&_layer_model, NULL)); + } + + Inkscape::Selection *getSelection() const { return _selection; } +}; + struct Inkscape::Application { GObject object; Inkscape::XML::Document *menus; std::map document_set; + std::map selection_models; GSList *desktops; gchar *argv0; gboolean dialogs_toggle; @@ -481,6 +500,7 @@ inkscape_init (SPObject * object) } new (&inkscape->document_set) std::map(); + new (&inkscape->selection_models) std::map(); inkscape->menus = sp_repr_read_mem (_(menus_skeleton), MENUS_SKELETON_SIZE, NULL); inkscape->desktops = NULL; @@ -504,6 +524,7 @@ inkscape_dispose (GObject *object) inkscape->menus = NULL; } + inkscape->selection_models.~map(); inkscape->document_set.~map(); G_OBJECT_CLASS (parent_class)->dispose (object); @@ -1234,6 +1255,14 @@ inkscape_add_document (SPDocument *document) iter->second ++; } } + } else { + // insert succeeded, this document is new. Do we need to create a + // selection model for it, i.e. are we running without a desktop? + if (!inkscape->use_gui) { + // Create layer model and selection model so we can run some verbs without a GUI + g_assert(inkscape->selection_models.find(document) == inkscape->selection_models.end()); + inkscape->selection_models[document] = new AppSelectionModel(document); + } } } @@ -1253,6 +1282,13 @@ inkscape_remove_document (SPDocument *document) if (iter->second < 1) { // this was the last one, remove the pair from list inkscape->document_set.erase (iter); + + // also remove the selection model + std::map::iterator sel_iter = inkscape->selection_models.find(document); + if (sel_iter != inkscape->selection_models.end()) { + inkscape->selection_models.erase(sel_iter); + } + return true; } else { return false; @@ -1312,6 +1348,24 @@ inkscape_active_event_context (void) return NULL; } +Inkscape::ActionContext +inkscape_active_action_context() +{ + if (SP_ACTIVE_DESKTOP) { + return Inkscape::ActionContext(SP_ACTIVE_DESKTOP); + } + + SPDocument *doc = inkscape_active_document(); + if (!doc) { + return Inkscape::ActionContext(); + } + + std::map::iterator sel_iter = inkscape->selection_models.find(doc); + if (sel_iter == inkscape->selection_models.end()) { + return Inkscape::ActionContext(); + } + return Inkscape::ActionContext(sel_iter->second->getSelection()); +} /*##################### -- cgit v1.2.3