From c3a160589a9cb41c70a56e5e7b66a65857a0d10e Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Mon, 1 Jul 2013 21:04:32 +0100 Subject: Factored layer model out into new Inkscape::LayerModel class. This allows Inkscape::Selection to use a LayerModel that is not associated with a UI. Changed the interface of verbs (SPAction) to use a new ActionContext rather than UI::View::View, again so that verbs may be used in a console mode. Modified boolean operation verbs to work in console-only mode. Fixed up DESKTOP_IS_ACTIVE macro to work in the case of no desktops. Modified main.cpp to process selections and verbs in no-GUI mode. Other changes are all consequences of the SPDesktop, Selection and LayerModel interface changes. (bzr r12387.1.1) --- src/inkscape.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/inkscape.cpp') diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 7e570deb7..125a7176a 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -87,7 +87,7 @@ enum { LAST_SIGNAL }; -#define DESKTOP_IS_ACTIVE(d) ((d) == inkscape->desktops->data) +#define DESKTOP_IS_ACTIVE(d) (inkscape->desktops && ((d) == inkscape->desktops->data)) /*################################ -- cgit v1.2.3 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 From 036013caefc09f34ef9b418e1ca148a821c777d6 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Thu, 4 Jul 2013 23:51:56 +0100 Subject: Further renaming of DBus variables (object -> app_interface/doc_interface and doc_context -> target) Fixes to application interface for document_new (now only works in console mode, and behaves as expected) (bzr r12387.1.8) --- src/inkscape.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/inkscape.cpp') diff --git a/src/inkscape.cpp b/src/inkscape.cpp index 2e60ee5ea..a24bd2b8a 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -1359,7 +1359,22 @@ inkscape_active_action_context() if (!doc) { return Inkscape::ActionContext(); } - + + return inkscape_action_context_for_document(doc); +} + +Inkscape::ActionContext +inkscape_action_context_for_document(SPDocument *doc) +{ + // If there are desktops, check them first to see if the document is bound to one of them + for (GSList *iter = inkscape->desktops ; iter ; iter = iter->next) { + SPDesktop *desktop=static_cast(iter->data); + if (desktop->doc() == doc) { + return Inkscape::ActionContext(desktop); + } + } + + // Document is not associated with any desktops - maybe we're in command-line mode std::map::iterator sel_iter = inkscape->selection_models.find(doc); if (sel_iter == inkscape->selection_models.end()) { return Inkscape::ActionContext(); -- cgit v1.2.3