diff options
| author | Eric Greveson <eric@greveson.co.uk> | 2013-07-01 20:09:53 +0000 |
|---|---|---|
| committer | Eric Greveson <eric@greveson.co.uk> | 2013-07-01 20:09:53 +0000 |
| commit | 6fe6a37589cbd6e53bf763879503ace16260e7a2 (patch) | |
| tree | ab3d7fa48e6ca4af582a54cf4c042de0fac2bef2 /src/helper | |
| parent | Factored layer model out into new Inkscape::LayerModel class. This allows (diff) | |
| download | inkscape-6fe6a37589cbd6e53bf763879503ace16260e7a2.tar.gz inkscape-6fe6a37589cbd6e53bf763879503ace16260e7a2.zip | |
Added new files referenced in previous commit message (forgot to add!)
(bzr r12387.1.2)
Diffstat (limited to 'src/helper')
| -rw-r--r-- | src/helper/action-context.cpp | 74 | ||||
| -rw-r--r-- | src/helper/action-context.h | 78 |
2 files changed, 152 insertions, 0 deletions
diff --git a/src/helper/action-context.cpp b/src/helper/action-context.cpp new file mode 100644 index 000000000..c88086f7f --- /dev/null +++ b/src/helper/action-context.cpp @@ -0,0 +1,74 @@ +/* + * ActionContext implementation. + * + * Author: + * Eric Greveson <eric@greveson.co.uk> + * + * Copyright (C) 2013 Eric Greveson + * + * This code is in public domain + */ + +#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->layerModel()->getDocument(); +} + +Selection *ActionContext::getSelection() const +{ + return _selection; +} + +UI::View::View *ActionContext::getView() const +{ + return _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..de09f94f4 --- /dev/null +++ b/src/helper/action-context.h @@ -0,0 +1,78 @@ +/** \file + * Inkscape UI action context implementation + *//* + * Author: + * Eric Greveson <eric@greveson.co.uk> + * + * Copyright (C) 2013 Eric Greveson + * + * This code is in public domain + */ + +#ifndef SEEN_INKSCAPE_ACTION_CONTEXT_H +#define SEEN_INKSCAPE_ACTION_CONTEXT_H + +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. + + 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; +}; + +} // 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 : |
