diff options
| author | Eric Greveson <eric@greveson.co.uk> | 2013-07-04 14:01:44 +0000 |
|---|---|---|
| committer | Eric Greveson <eric@greveson.co.uk> | 2013-07-04 14:01:44 +0000 |
| commit | 104efe4e3ecadc975ab76748c66f041abf8ee7b1 (patch) | |
| tree | 01c6a23e2ee0bf43fda8eb78441a34e9dc338a3b /src/verbs.cpp | |
| parent | Merge recent changes from inkscape trunk (diff) | |
| download | inkscape-104efe4e3ecadc975ab76748c66f041abf8ee7b1.tar.gz inkscape-104efe4e3ecadc975ab76748c66f041abf8ee7b1.zip | |
Code readability improvements and licence changes for action-context.*
based on merge request code review and feedback
(bzr r12387.1.7)
Diffstat (limited to 'src/verbs.cpp')
| -rw-r--r-- | src/verbs.cpp | 91 |
1 files changed, 24 insertions, 67 deletions
diff --git a/src/verbs.cpp b/src/verbs.cpp index 2e6417ce1..1dae8bcf0 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -628,9 +628,13 @@ SPAction *Verb::get_action(Inkscape::ActionContext const & context) } /* static */ -void Verb::show_gui_required_message(SPAction *action) +bool Verb::ensure_desktop_valid(SPAction *action) { + if (sp_action_get_desktop(action) != NULL) { + return true; + } g_printerr("WARNING: ignoring verb %s - GUI required for this verb.\n", action->id); + return false; } void Verb::sensitive(SPDocument *in_doc, bool in_sensitive) @@ -827,12 +831,9 @@ void FileVerb::perform(SPAction *action, void *data) if (handled) { return; } - + + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *desktop = sp_action_get_desktop(action); - if (desktop == NULL) { - show_gui_required_message(action); - return; - } Gtk::Window *parent = desktop->getToplevel(); g_assert(parent != NULL); @@ -905,12 +906,9 @@ void EditVerb::perform(SPAction *action, void *data) if (handled) { return; } - + + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } switch (reinterpret_cast<std::size_t>(data)) { case SP_VERB_EDIT_UNDO: @@ -1118,10 +1116,7 @@ void SelectionVerb::perform(SPAction *action, void *data) } // The remaining operations require a desktop - if (dt == NULL) { - show_gui_required_message(action); - return; - } + g_return_if_fail(ensure_desktop_valid(action)); g_assert(dt->_dlg_mgr != NULL); @@ -1200,13 +1195,10 @@ void SelectionVerb::perform(SPAction *action, void *data) */ void LayerVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); size_t verb = reinterpret_cast<std::size_t>(data); - if (dt == NULL) { - show_gui_required_message(action); - return; - } if ( !dt->currentLayer() ) { return; } @@ -1455,11 +1447,8 @@ void LayerVerb::perform(SPAction *action, void *data) */ void ObjectVerb::perform( SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } SPEventContext *ec = dt->event_context; @@ -1544,13 +1533,9 @@ void ContextVerb::perform(SPAction *action, void *data) SPDesktop *dt; sp_verb_t verb; int vidx; - - dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } + g_return_if_fail(ensure_desktop_valid(action)); + dt = sp_action_get_desktop(action); verb = (sp_verb_t)GPOINTER_TO_INT((gpointer)data); @@ -1748,11 +1733,8 @@ void ContextVerb::perform(SPAction *action, void *data) */ void TextVerb::perform(SPAction *action, void */*data*/) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } SPDocument *doc = sp_desktop_document(dt); (void)doc; @@ -1765,11 +1747,8 @@ void TextVerb::perform(SPAction *action, void */*data*/) */ void ZoomVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } SPEventContext *ec = dt->event_context; SPDocument *doc = sp_desktop_document(dt); @@ -1956,12 +1935,9 @@ void DialogVerb::perform(SPAction *action, void *data) // unhide all when opening a new dialog inkscape_dialogs_unhide(); } - + + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } g_assert(dt->_dlg_mgr != NULL); switch (reinterpret_cast<std::size_t>(data)) { @@ -2073,11 +2049,8 @@ void DialogVerb::perform(SPAction *action, void *data) */ void HelpVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } g_assert(dt->_dlg_mgr != NULL); switch (reinterpret_cast<std::size_t>(data)) { @@ -2112,10 +2085,7 @@ void HelpVerb::perform(SPAction *action, void *data) */ void TutorialVerb::perform(SPAction *action, void *data) { - if (sp_action_get_desktop(action) == NULL) { - show_gui_required_message(action); - return; - } + g_return_if_fail(ensure_desktop_valid(action)); switch (reinterpret_cast<std::size_t>(data)) { case SP_VERB_TUTORIAL_BASIC: // TRANSLATORS: If you have translated the tutorial-basic.en.svgz file to your language, @@ -2197,14 +2167,9 @@ SPAction *EffectLastVerb::make_action(Inkscape::ActionContext const & context) */ void EffectLastVerb::perform(SPAction *action, void *data) { - // These aren't used, but are here to remind people not to use - // the CURRENT_DOCUMENT macros unless they really have to. + g_return_if_fail(ensure_desktop_valid(action)); Inkscape::UI::View::View *current_view = sp_action_get_view(action); - if (current_view == NULL) { - show_gui_required_message(action); - return; - } - // SPDocument *current_document = SP_VIEW_DOCUMENT(current_view); + Inkscape::Extension::Effect *effect = Inkscape::Extension::Effect::get_last_effect(); if (effect == NULL) return; @@ -2266,12 +2231,8 @@ SPAction *FitCanvasVerb::make_action(Inkscape::ActionContext const & context) */ void FitCanvasVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } - SPDocument *doc = sp_desktop_document(dt); if (!doc) return; @@ -2336,12 +2297,8 @@ SPAction *LockAndHideVerb::make_action(Inkscape::ActionContext const & context) */ void LockAndHideVerb::perform(SPAction *action, void *data) { + g_return_if_fail(ensure_desktop_valid(action)); SPDesktop *dt = sp_action_get_desktop(action); - if (dt == NULL) { - show_gui_required_message(action); - return; - } - SPDocument *doc = sp_desktop_document(dt); if (!doc) return; |
