summaryrefslogtreecommitdiffstats
path: root/src/verbs.cpp
diff options
context:
space:
mode:
authorEric Greveson <eric@greveson.co.uk>2013-07-01 20:04:32 +0000
committerEric Greveson <eric@greveson.co.uk>2013-07-01 20:04:32 +0000
commitc3a160589a9cb41c70a56e5e7b66a65857a0d10e (patch)
tree46860c161eda2e11687aff38141e04b40185798b /src/verbs.cpp
parentCorrectly ignore symbolic link to ltmain.sh (diff)
downloadinkscape-c3a160589a9cb41c70a56e5e7b66a65857a0d10e.tar.gz
inkscape-c3a160589a9cb41c70a56e5e7b66a65857a0d10e.zip
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)
Diffstat (limited to 'src/verbs.cpp')
-rw-r--r--src/verbs.cpp193
1 files changed, 102 insertions, 91 deletions
diff --git a/src/verbs.cpp b/src/verbs.cpp
index 6f83b3dfb..4bbd3f9df 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -50,6 +50,7 @@
#include "file.h"
#include "gradient-drag.h"
#include "helper/action.h"
+#include "helper/action-context.h"
#include "help.h"
#include "inkscape-private.h"
#include "interface.h"
@@ -124,7 +125,7 @@ class FileVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
FileVerb(unsigned int const code,
@@ -143,7 +144,7 @@ class EditVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
EditVerb(unsigned int const code,
@@ -162,7 +163,7 @@ class SelectionVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
SelectionVerb(unsigned int const code,
@@ -181,7 +182,7 @@ class LayerVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
LayerVerb(unsigned int const code,
@@ -200,7 +201,7 @@ class ObjectVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
ObjectVerb(unsigned int const code,
@@ -219,7 +220,7 @@ class ContextVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
ContextVerb(unsigned int const code,
@@ -238,7 +239,7 @@ class ZoomVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
ZoomVerb(unsigned int const code,
@@ -258,7 +259,7 @@ class DialogVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
DialogVerb(unsigned int const code,
@@ -277,7 +278,7 @@ class HelpVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
HelpVerb(unsigned int const code,
@@ -296,7 +297,7 @@ class TutorialVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
TutorialVerb(unsigned int const code,
@@ -315,7 +316,7 @@ class TextVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
TextVerb(unsigned int const code,
@@ -382,10 +383,10 @@ Verb::~Verb(void)
* for a function that every subclass should write. Most
* can be written using \c make_action_helper.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return NULL to represent error (this function shouldn't ever be called)
*/
-SPAction *Verb::make_action(Inkscape::UI::View::View */*view*/)
+SPAction *Verb::make_action(Inkscape::ActionContext const & /*context*/)
{
//std::cout << "make_action" << std::endl;
return NULL;
@@ -395,13 +396,13 @@ SPAction *Verb::make_action(Inkscape::UI::View::View */*view*/)
* Create an action for a \c FileVerb.
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *FileVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *FileVerb::make_action(Inkscape::ActionContext const & context)
{
//std::cout << "fileverb: make_action: " << &perform << std::endl;
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -409,13 +410,13 @@ SPAction *FileVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *EditVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *EditVerb::make_action(Inkscape::ActionContext const & context)
{
//std::cout << "editverb: make_action: " << &perform << std::endl;
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -423,12 +424,12 @@ SPAction *EditVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *SelectionVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *SelectionVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -436,12 +437,12 @@ SPAction *SelectionVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *LayerVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *LayerVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -449,12 +450,12 @@ SPAction *LayerVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *ObjectVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *ObjectVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -462,12 +463,12 @@ SPAction *ObjectVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *ContextVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *ContextVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -475,12 +476,12 @@ SPAction *ContextVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *ZoomVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *ZoomVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -488,12 +489,12 @@ SPAction *ZoomVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *DialogVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *DialogVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -501,12 +502,12 @@ SPAction *DialogVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *HelpVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *HelpVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -514,12 +515,12 @@ SPAction *HelpVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *TutorialVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *TutorialVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -527,12 +528,12 @@ SPAction *TutorialVerb::make_action(Inkscape::UI::View::View *view)
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *TextVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *TextVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -546,16 +547,16 @@ SPAction *TextVerb::make_action(Inkscape::UI::View::View *view)
* if the action gets crated, a listener is added to the action with
* the vector that is passed in.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @param vector The function vector for the verb.
* @return The created action.
*/
-SPAction *Verb::make_action_helper(Inkscape::UI::View::View *view, void (*perform_fun)(SPAction *, void *), void *in_pntr)
+SPAction *Verb::make_action_helper(Inkscape::ActionContext const & context, void (*perform_fun)(SPAction *, void *), void *in_pntr)
{
SPAction *action;
//std::cout << "Adding action: " << _code << std::endl;
- action = sp_action_new(view, _id, _(_name),
+ action = sp_action_new(context, _id, _(_name),
_(_tip), _image, this);
if (action == NULL) return NULL;
@@ -587,22 +588,22 @@ SPAction *Verb::make_action_helper(Inkscape::UI::View::View *view, void (*perfor
* looked for, and the sensitivity is matched. Unfortunately, this is
* currently a linear search.
*
- * @param view The view which this action would relate to.
+ * @param context The action context which this action relates to.
* @return The action, or NULL if there is an error.
*/
-SPAction *Verb::get_action(Inkscape::UI::View::View *view)
+SPAction *Verb::get_action(Inkscape::ActionContext const & context)
{
SPAction *action = NULL;
if ( _actions == NULL ) {
_actions = new ActionTable;
}
- ActionTable::iterator action_found = _actions->find(view);
+ ActionTable::iterator action_found = _actions->find(context.getView());
if (action_found != _actions->end()) {
action = action_found->second;
} else {
- action = this->make_action(view);
+ action = this->make_action(context);
// if (action == NULL) printf("Hmm, NULL in %s\n", _name);
if (action == NULL) printf("Hmm, NULL in %s\n", _name);
@@ -610,16 +611,16 @@ SPAction *Verb::get_action(Inkscape::UI::View::View *view)
sp_action_set_sensitive(action, 0);
} else {
for (ActionTable::iterator cur_action = _actions->begin();
- cur_action != _actions->end() && view != NULL;
+ cur_action != _actions->end() && context.getView() != NULL;
++cur_action) {
- if (cur_action->first != NULL && cur_action->first->doc() == view->doc()) {
+ if (cur_action->first != NULL && cur_action->first->doc() == context.getDocument()) {
sp_action_set_sensitive(action, cur_action->second->sensitive);
break;
}
}
}
- _actions->insert(ActionTable::value_type(view, action));
+ _actions->insert(ActionTable::value_type(context.getView(), action));
}
return action;
@@ -802,8 +803,7 @@ void FileVerb::perform(SPAction *action, void *data)
#if 0
// These aren't used, but are here to remind people not to use
// the CURRENT_DOCUMENT macros unless they really have to.
- Inkscape::UI::View::View *current_view = sp_action_get_view(action);
- SPDocument *current_document = current_view->doc();
+ SPDocument *current_document = sp_action_get_document(action);
#endif
SPDesktop *desktop = dynamic_cast<SPDesktop*>(sp_action_get_view(action));
@@ -1028,8 +1028,39 @@ void EditVerb::perform(SPAction *action, void *data)
*/
void SelectionVerb::perform(SPAction *action, void *data)
{
+ Inkscape::Selection *selection = sp_action_get_selection(action);
SPDesktop *dt = static_cast<SPDesktop*>(sp_action_get_view(action));
+ // Some of these operations have been modified so they work in command-line mode!
+ // In this case, all we need is a selection
+ if (!selection) {
+ return;
+ }
+
+ switch (reinterpret_cast<std::size_t>(data)) {
+ case SP_VERB_SELECTION_UNION:
+ sp_selected_path_union(selection, dt);
+ break;
+ case SP_VERB_SELECTION_INTERSECT:
+ sp_selected_path_intersect(selection, dt);
+ break;
+ case SP_VERB_SELECTION_DIFF:
+ sp_selected_path_diff(selection, dt);
+ break;
+ case SP_VERB_SELECTION_SYMDIFF:
+ sp_selected_path_symdiff(selection, dt);
+ break;
+ case SP_VERB_SELECTION_CUT:
+ sp_selected_path_cut(selection, dt);
+ break;
+ case SP_VERB_SELECTION_SLICE:
+ sp_selected_path_slice(selection, dt);
+ break;
+ default:
+ break;
+ }
+
+ // The remaining operations require a desktop
if (!dt)
return;
@@ -1065,26 +1096,6 @@ void SelectionVerb::perform(SPAction *action, void *data)
text_remove_all_kerns();
break;
- case SP_VERB_SELECTION_UNION:
- sp_selected_path_union(dt);
- break;
- case SP_VERB_SELECTION_INTERSECT:
- sp_selected_path_intersect(dt);
- break;
- case SP_VERB_SELECTION_DIFF:
- sp_selected_path_diff(dt);
- break;
- case SP_VERB_SELECTION_SYMDIFF:
- sp_selected_path_symdiff(dt);
- break;
-
- case SP_VERB_SELECTION_CUT:
- sp_selected_path_cut(dt);
- break;
- case SP_VERB_SELECTION_SLICE:
- sp_selected_path_slice(dt);
- break;
-
case SP_VERB_SELECTION_OFFSET:
sp_selected_path_offset(dt);
break;
@@ -1500,7 +1511,7 @@ void ContextVerb::perform(SPAction *action, void *data)
*/
for (vidx = SP_VERB_CONTEXT_SELECT; vidx <= SP_VERB_CONTEXT_PAINTBUCKET_PREFS; vidx++)
{
- SPAction *tool_action= get((sp_verb_t)vidx)->get_action(dt);
+ SPAction *tool_action= get((sp_verb_t)vidx)->get_action(action->context);
if (tool_action) {
sp_action_set_active(tool_action, vidx == (int)verb);
}
@@ -2090,7 +2101,7 @@ class EffectLastVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
EffectLastVerb(unsigned int const code,
@@ -2109,12 +2120,12 @@ public:
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *EffectLastVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *EffectLastVerb::make_action(Inkscape::ActionContext const & context)
{
- return make_action_helper(view, &perform);
+ return make_action_helper(context, &perform);
}
/**
@@ -2155,7 +2166,7 @@ class FitCanvasVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
FitCanvasVerb(unsigned int const code,
@@ -2174,12 +2185,12 @@ public:
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *FitCanvasVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *FitCanvasVerb::make_action(Inkscape::ActionContext const & context)
{
- SPAction *action = make_action_helper(view, &perform);
+ SPAction *action = make_action_helper(context, &perform);
return action;
}
@@ -2221,7 +2232,7 @@ class LockAndHideVerb : public Verb {
private:
static void perform(SPAction *action, void *mydata);
protected:
- virtual SPAction *make_action(Inkscape::UI::View::View *view);
+ virtual SPAction *make_action(Inkscape::ActionContext const & context);
public:
/** Use the Verb initializer with the same parameters. */
LockAndHideVerb(unsigned int const code,
@@ -2240,12 +2251,12 @@ public:
*
* Calls \c make_action_helper with the \c vector.
*
- * @param view Which view the action should be created for.
+ * @param context Which context the action should be created for.
* @return The built action.
*/
-SPAction *LockAndHideVerb::make_action(Inkscape::UI::View::View *view)
+SPAction *LockAndHideVerb::make_action(Inkscape::ActionContext const & context)
{
- SPAction *action = make_action_helper(view, &perform);
+ SPAction *action = make_action_helper(context, &perform);
return action;
}