summaryrefslogtreecommitdiffstats
path: root/src/helper
diff options
context:
space:
mode:
authorMatthew Petroff <matthew@mpetroff.net>2013-07-17 05:13:49 +0000
committerMatthew Petroff <matthew@mpetroff.net>2013-07-17 05:13:49 +0000
commitdd59aa3bb2cab030296a4622e5166f0e3f8d5445 (patch)
treea86612c94d3ddce3edf696ea17fefb58b0accccf /src/helper
parentTemporary fixes/kludges. (diff)
parentShape calculations. re-introduce grid of a smaller size. (http://article.gman... (diff)
downloadinkscape-dd59aa3bb2cab030296a4622e5166f0e3f8d5445.tar.gz
inkscape-dd59aa3bb2cab030296a4622e5166f0e3f8d5445.zip
Merge from trunk.
(bzr r12380.1.17)
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/CMakeLists.txt2
-rw-r--r--src/helper/Makefile_insert2
-rw-r--r--src/helper/action-context.cpp84
-rw-r--r--src/helper/action-context.h89
-rw-r--r--src/helper/action.cpp53
-rw-r--r--src/helper/action.h13
6 files changed, 231 insertions, 12 deletions
diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt
index f709c7386..2e1e724f5 100644
--- a/src/helper/CMakeLists.txt
+++ b/src/helper/CMakeLists.txt
@@ -10,6 +10,7 @@ set(sp_marshal_SRC
set(helper_SRC
action.cpp
+ action-context.cpp
geom.cpp
geom-nodetype.cpp
gnome-utils.cpp
@@ -29,6 +30,7 @@ set(helper_SRC
# -------
# Headers
action.h
+ action-context.h
geom-curves.h
geom-nodetype.h
geom.h
diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert
index 2be40e0e0..790d87b14 100644
--- a/src/helper/Makefile_insert
+++ b/src/helper/Makefile_insert
@@ -5,6 +5,8 @@ helper/unit-menu.$(OBJEXT): helper/sp-marshal.h
ink_common_sources += \
helper/action.cpp \
helper/action.h \
+ helper/action-context.cpp \
+ helper/action-context.h \
helper/geom.cpp \
helper/geom.h \
helper/geom-curves.h \
diff --git a/src/helper/action-context.cpp b/src/helper/action-context.cpp
new file mode 100644
index 000000000..d52e43d96
--- /dev/null
+++ b/src/helper/action-context.cpp
@@ -0,0 +1,84 @@
+/*
+ * ActionContext implementation.
+ *
+ * Author:
+ * Eric Greveson <eric@greveson.co.uk>
+ *
+ * Copyright (C) 2013 Eric Greveson
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "desktop.h"
+#include "document.h"
+#include "layer-model.h"
+#include "selection.h"
+#include "helper/action-context.h"
+#include "ui/view/view.h"
+
+namespace Inkscape {
+
+ActionContext::ActionContext()
+ : _selection(NULL)
+ , _view(NULL)
+{
+}
+
+ActionContext::ActionContext(Selection *selection)
+ : _selection(selection)
+ , _view(NULL)
+{
+}
+
+ActionContext::ActionContext(UI::View::View *view)
+ : _selection(NULL)
+ , _view(view)
+{
+ SPDesktop *desktop = static_cast<SPDesktop *>(view);
+ if (desktop) {
+ _selection = desktop->selection;
+ }
+}
+
+SPDocument *ActionContext::getDocument() const
+{
+ if (_selection == NULL) {
+ return NULL;
+ }
+
+ // Should be the same as the view's document, if view is non-NULL
+ return _selection->layers()->getDocument();
+}
+
+Selection *ActionContext::getSelection() const
+{
+ return _selection;
+}
+
+UI::View::View *ActionContext::getView() const
+{
+ return _view;
+}
+
+SPDesktop *ActionContext::getDesktop() const
+{
+ // 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<SPDesktop *>(_view);
+}
+
+} // namespace Inkscape
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/helper/action-context.h b/src/helper/action-context.h
new file mode 100644
index 000000000..bb538f413
--- /dev/null
+++ b/src/helper/action-context.h
@@ -0,0 +1,89 @@
+/** \file
+ * Inkscape UI action context implementation
+ *//*
+ * Author:
+ * Eric Greveson <eric@greveson.co.uk>
+ *
+ * Copyright (C) 2013 Eric Greveson
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef SEEN_INKSCAPE_ACTION_CONTEXT_H
+#define SEEN_INKSCAPE_ACTION_CONTEXT_H
+
+class SPDesktop;
+class SPDocument;
+
+namespace Inkscape {
+
+class Selection;
+
+namespace UI {
+namespace View {
+class View;
+} // namespace View
+} // namespace UI
+
+/** This structure contains all the document/view context required
+ for an action. Some actions may be executed on a document without
+ requiring a GUI, hence not providing the info directly through
+ Inkscape::UI::View::View. Actions that do require GUI objects should
+ check to see if the relevant pointers are NULL before attempting to
+ use them.
+
+ TODO: we store a UI::View::View* because that's what the actions and verbs
+ used to take as parameters in their methods. Why is this? They almost
+ always seemed to cast straight to an SPDesktop* - so shouldn't we actually
+ be storing an SPDesktop*? Is there a case where a non-SPDesktop
+ UI::View::View is used by the actions?
+
+ ActionContext is designed to be copyable, so it may be used with stack
+ storage if required. */
+class ActionContext {
+ // NB: Only one of these is typically set - selection model if in console mode, view if in GUI mode
+ Selection *_selection; /**< The selection model to which this action applies, if running in console mode. May be NULL. */
+ UI::View::View *_view; /**< The view to which this action applies. May be NULL (e.g. if running in console mode). */
+
+public:
+ /** Construct without any document or GUI */
+ ActionContext();
+
+ /** Construct an action context for when the app is being run without
+ any GUI, i.e. in console mode */
+ ActionContext(Selection *selection);
+
+ /** Construct an action context for when the app is being run in GUI mode */
+ ActionContext(UI::View::View *view);
+
+ /** Get the document for the action context. May be NULL. Prefer this
+ function to getView()->doc() if the action doesn't require a GUI. */
+ SPDocument *getDocument() const;
+
+ /** Get the selection for the action context. May be NULL. Should be
+ non-NULL if getDocument() is non-NULL. */
+ Selection *getSelection() const;
+
+ /** Get the view for the action context. May be NULL. Guaranteed to be
+ NULL if running in console mode. */
+ UI::View::View *getView() const;
+
+ /** Get the desktop for the action context. May be NULL. Guaranteed to be
+ NULL if running in console mode. */
+ SPDesktop *getDesktop() const;
+};
+
+} // namespace Inkscape
+
+#endif
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
diff --git a/src/helper/action.cpp b/src/helper/action.cpp
index 0e9957ca3..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"
@@ -41,7 +42,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 +77,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 +86,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 +112,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);
}
@@ -170,13 +169,47 @@ sp_action_set_name (SPAction *action, Glib::ustring const &name)
}
/**
- * Return View associated with the action.
+ * 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, if any.
*/
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();
+}
+
+/**
+ * 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<SPDesktop *>(sp_action_get_view(action));
}
/*
diff --git a/src/helper/action.h b/src/helper/action.h
index 0cd010b34..1f2de87b4 100644
--- a/src/helper/action.h
+++ b/src/helper/action.h
@@ -12,6 +12,7 @@
#ifndef SEEN_INKSCAPE_SP_ACTION_H
#define SEEN_INKSCAPE_SP_ACTION_H
+#include "helper/action-context.h"
#include <sigc++/sigc++.h>
#include <glibmm/ustring.h>
#include <glib-object.h>
@@ -24,8 +25,13 @@ struct SPActionClass;
#define SP_ACTION_CLASS(o) (G_TYPE_CHECK_CLASS_CAST((o), SP_TYPE_ACTION, SPActionClass))
#define SP_IS_ACTION(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), SP_TYPE_ACTION))
+class SPDesktop;
+class SPDocument;
namespace Inkscape {
+
+class Selection;
class Verb;
+
namespace UI {
namespace View {
class View;
@@ -39,7 +45,7 @@ class View;
struct SPAction : public GObject {
unsigned sensitive : 1; /**< Value to track whether the action is sensitive */
unsigned active : 1; /**< Value to track whether the action is active */
- Inkscape::UI::View::View *view; /**< The View to which this action is attached */
+ Inkscape::ActionContext context; /**< The context (doc/view) to which this action is attached */
gchar *id; /**< The identifier for the action */
gchar *name; /**< Full text name of the action */
gchar *tip; /**< A tooltip to describe the action */
@@ -59,7 +65,7 @@ struct SPActionClass {
GType sp_action_get_type();
-SPAction *sp_action_new(Inkscape::UI::View::View *view,
+SPAction *sp_action_new(Inkscape::ActionContext const &context,
gchar const *id,
gchar const *name,
gchar const *tip,
@@ -70,7 +76,10 @@ void sp_action_perform(SPAction *action, void *data);
void sp_action_set_active(SPAction *action, unsigned active);
void sp_action_set_sensitive(SPAction *action, unsigned sensitive);
void sp_action_set_name(SPAction *action, Glib::ustring const &name);
+SPDocument *sp_action_get_document(SPAction *action);
+Inkscape::Selection *sp_action_get_selection(SPAction *action);
Inkscape::UI::View::View *sp_action_get_view(SPAction *action);
+SPDesktop *sp_action_get_desktop(SPAction *action);
#endif