From 1615436543169f305d1df4d830ed8f5ec5dc75ed Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 26 Jan 2013 19:33:04 +0000 Subject: More GObject boilerplate reduction (bzr r12065) --- src/helper/action.cpp | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) (limited to 'src/helper/action.cpp') diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 4fafa191e..0e9957ca3 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -19,34 +19,9 @@ #include "document.h" #include "helper/action.h" -static void sp_action_class_init (SPActionClass *klass); -static void sp_action_init (SPAction *action); static void sp_action_finalize (GObject *object); -static GObjectClass *parent_class; - -/** - * Register SPAction class and return its type. - */ -GType -sp_action_get_type (void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPActionClass), - NULL, NULL, - (GClassInitFunc) sp_action_class_init, - NULL, NULL, - sizeof(SPAction), - 0, - (GInstanceInitFunc) sp_action_init, - NULL - }; - type = g_type_register_static(G_TYPE_OBJECT, "SPAction", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPAction, sp_action, G_TYPE_OBJECT); /** * SPAction vtable initialization. @@ -54,8 +29,6 @@ sp_action_get_type (void) static void sp_action_class_init (SPActionClass *klass) { - parent_class = (GObjectClass*) g_type_class_ref(G_TYPE_OBJECT); - GObjectClass *object_class = (GObjectClass *) klass; object_class->finalize = sp_action_finalize; } @@ -84,19 +57,19 @@ sp_action_init (SPAction *action) static void sp_action_finalize (GObject *object) { - SPAction *action = SP_ACTION(object); + SPAction *action = SP_ACTION(object); - g_free (action->image); - g_free (action->tip); - g_free (action->name); - g_free (action->id); + g_free (action->image); + g_free (action->tip); + g_free (action->name); + g_free (action->id); action->signal_perform.~signal(); action->signal_set_sensitive.~signal(); action->signal_set_active.~signal(); action->signal_set_name.~signal(); - parent_class->finalize (object); + G_OBJECT_CLASS(sp_action_parent_class)->finalize (object); } /** -- cgit v1.2.3 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/helper/action.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/helper/action.cpp') diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 0e9957ca3..107d0179b 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -41,7 +41,7 @@ sp_action_init (SPAction *action) { action->sensitive = 0; action->active = 0; - action->view = NULL; + action->context = Inkscape::ActionContext(); action->id = action->name = action->tip = NULL; action->image = NULL; @@ -76,7 +76,7 @@ sp_action_finalize (GObject *object) * Create new SPAction object and set its properties. */ SPAction * -sp_action_new(Inkscape::UI::View::View *view, +sp_action_new(Inkscape::ActionContext const &context, const gchar *id, const gchar *name, const gchar *tip, @@ -85,7 +85,7 @@ sp_action_new(Inkscape::UI::View::View *view, { SPAction *action = (SPAction *)g_object_new(SP_TYPE_ACTION, NULL); - action->view = view; + action->context = context; action->sensitive = TRUE; action->id = g_strdup (id); action->name = g_strdup (name); @@ -111,11 +111,9 @@ public: : ActionEventBase(share_static_string("action")) { _addProperty(share_static_string("timestamp"), timestamp()); - if (action->view) { - SPDocument *document = action->view->doc(); - if (document) { - _addProperty(share_static_string("document"), document->serial()); - } + SPDocument *document = action->context.getDocument(); + if (document) { + _addProperty(share_static_string("document"), document->serial()); } _addProperty(share_static_string("verb"), action->id); } @@ -169,6 +167,26 @@ sp_action_set_name (SPAction *action, Glib::ustring const &name) action->signal_set_name.emit(name); } +/** + * Return Document associated with the action. + */ +SPDocument * +sp_action_get_document (SPAction *action) +{ + g_return_val_if_fail (SP_IS_ACTION (action), NULL); + return action->context.getDocument(); +} + +/** + * Return Selection associated with the action + */ +Inkscape::Selection * +sp_action_get_selection (SPAction *action) +{ + g_return_val_if_fail (SP_IS_ACTION (action), NULL); + return action->context.getSelection(); +} + /** * Return View associated with the action. */ @@ -176,7 +194,7 @@ Inkscape::UI::View::View * sp_action_get_view (SPAction *action) { g_return_val_if_fail (SP_IS_ACTION (action), NULL); - return action->view; + return action->context.getView(); } /* -- 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/helper/action.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/helper/action.cpp') diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 107d0179b..28cb40334 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -16,6 +16,7 @@ #include "debug/simple-event.h" #include "debug/event-tracker.h" #include "ui/view/view.h" +#include "desktop.h" #include "document.h" #include "helper/action.h" @@ -188,7 +189,7 @@ sp_action_get_selection (SPAction *action) } /** - * Return View associated with the action. + * Return View associated with the action, if any. */ Inkscape::UI::View::View * sp_action_get_view (SPAction *action) @@ -197,6 +198,20 @@ sp_action_get_view (SPAction *action) return action->context.getView(); } +/** + * Return Desktop associated with the action, if any. + */ +SPDesktop * +sp_action_get_desktop (SPAction *action) +{ + // TODO: this slightly horrible storage of a UI::View::View*, and + // casting to an SPDesktop*, is only done because that's what was + // already the norm in the Inkscape codebase. This seems wrong. Surely + // we should store an SPDesktop* in the first place? Is there a case + // of actions being carried out on a View that is not an SPDesktop? + return static_cast(sp_action_get_view(action)); +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From 968ce4cd75e9309b8fb78f5b21f96d53e0d0c6e6 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Fri, 20 Dec 2013 15:22:30 +0100 Subject: Null check added. (should fix bug 1172484) (bzr r12853) --- src/helper/action.cpp | 71 +++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'src/helper/action.cpp') diff --git a/src/helper/action.cpp b/src/helper/action.cpp index 28cb40334..060bf317c 100644 --- a/src/helper/action.cpp +++ b/src/helper/action.cpp @@ -40,16 +40,16 @@ sp_action_class_init (SPActionClass *klass) static void sp_action_init (SPAction *action) { - action->sensitive = 0; - action->active = 0; - action->context = Inkscape::ActionContext(); - action->id = action->name = action->tip = NULL; - action->image = NULL; - - new (&action->signal_perform) sigc::signal(); - new (&action->signal_set_sensitive) sigc::signal(); - new (&action->signal_set_active) sigc::signal(); - new (&action->signal_set_name) sigc::signal(); + action->sensitive = 0; + action->active = 0; + action->context = Inkscape::ActionContext(); + action->id = action->name = action->tip = NULL; + action->image = NULL; + + new (&action->signal_perform) sigc::signal(); + new (&action->signal_set_sensitive) sigc::signal(); + new (&action->signal_set_active) sigc::signal(); + new (&action->signal_set_name) sigc::signal(); } /** @@ -84,17 +84,17 @@ sp_action_new(Inkscape::ActionContext const &context, const gchar *image, Inkscape::Verb * verb) { - SPAction *action = (SPAction *)g_object_new(SP_TYPE_ACTION, NULL); + SPAction *action = (SPAction *)g_object_new(SP_TYPE_ACTION, NULL); - action->context = context; - action->sensitive = TRUE; - action->id = g_strdup (id); - action->name = g_strdup (name); - action->tip = g_strdup (tip); - action->image = g_strdup (image); - action->verb = verb; + action->context = context; + action->sensitive = TRUE; + action->id = g_strdup (id); + action->name = g_strdup (name); + action->tip = g_strdup (tip); + action->image = g_strdup (image); + action->verb = verb; - return action; + return action; } namespace { @@ -129,11 +129,11 @@ public: */ void sp_action_perform(SPAction *action, void * /*data*/) { - g_return_if_fail (action != NULL); - g_return_if_fail (SP_IS_ACTION (action)); + g_return_if_fail (action != NULL); + g_return_if_fail (SP_IS_ACTION (action)); - Inkscape::Debug::EventTracker tracker(action); - action->signal_perform.emit(); + Inkscape::Debug::EventTracker tracker(action); + action->signal_perform.emit(); } /** @@ -142,10 +142,10 @@ void sp_action_perform(SPAction *action, void * /*data*/) void sp_action_set_active (SPAction *action, unsigned int active) { - g_return_if_fail (action != NULL); - g_return_if_fail (SP_IS_ACTION (action)); + g_return_if_fail (action != NULL); + g_return_if_fail (SP_IS_ACTION (action)); - action->signal_set_active.emit(active); + action->signal_set_active.emit(active); } /** @@ -154,15 +154,18 @@ sp_action_set_active (SPAction *action, unsigned int active) void sp_action_set_sensitive (SPAction *action, unsigned int sensitive) { - g_return_if_fail (action != NULL); - g_return_if_fail (SP_IS_ACTION (action)); + g_return_if_fail (action != NULL); + g_return_if_fail (SP_IS_ACTION (action)); - action->signal_set_sensitive.emit(sensitive); + action->signal_set_sensitive.emit(sensitive); } void sp_action_set_name (SPAction *action, Glib::ustring const &name) { + g_return_if_fail (action != NULL); + g_return_if_fail (SP_IS_ACTION (action)); + g_free(action->name); action->name = g_strdup(name.data()); action->signal_set_name.emit(name); @@ -174,8 +177,8 @@ sp_action_set_name (SPAction *action, Glib::ustring const &name) SPDocument * sp_action_get_document (SPAction *action) { - g_return_val_if_fail (SP_IS_ACTION (action), NULL); - return action->context.getDocument(); + g_return_val_if_fail (SP_IS_ACTION (action), NULL); + return action->context.getDocument(); } /** @@ -194,8 +197,8 @@ sp_action_get_selection (SPAction *action) Inkscape::UI::View::View * sp_action_get_view (SPAction *action) { - g_return_val_if_fail (SP_IS_ACTION (action), NULL); - return action->context.getView(); + g_return_val_if_fail (SP_IS_ACTION (action), NULL); + return action->context.getView(); } /** @@ -209,7 +212,7 @@ sp_action_get_desktop (SPAction *action) // already the norm in the Inkscape codebase. This seems wrong. Surely // we should store an SPDesktop* in the first place? Is there a case // of actions being carried out on a View that is not an SPDesktop? - return static_cast(sp_action_get_view(action)); + return static_cast(sp_action_get_view(action)); } /* -- cgit v1.2.3