From 80bce9c528f98207f3a8bc8ebeba4991dfc2bbc9 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Thu, 14 Jan 2010 22:45:34 -0800 Subject: [PATCH] Restore encapsulation of selection implementation. --- src/selection-chemistry.cpp | 109 +++++++++++++++++++++++++++++++++++- src/selection-chemistry.h | 38 ++++++++----- src/verbs.cpp | 71 +++-------------------- 3 files changed, 139 insertions(+), 79 deletions(-) diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index dfe47bee8..e81d133c2 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1,5 +1,3 @@ -#define __SP_SELECTION_CHEMISTRY_C__ - /** @file * @brief Miscellanous operations on selected items */ @@ -9,8 +7,9 @@ * MenTaLguY * bulia byak * Andrius R. + * Jon A. Cruz * - * Copyright (C) 1999-2006 authors + * Copyright (C) 1999-2010 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -22,6 +21,10 @@ #include "selection-chemistry.h" +// TOOD fixme: This should be moved into preference repr +SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; + + #include #include "svg/svg.h" @@ -61,6 +64,7 @@ #include "sp-linear-gradient-fns.h" #include "sp-pattern.h" #include "sp-radial-gradient-fns.h" +#include "gradient-context.h" #include "sp-namedview.h" #include "preferences.h" #include "sp-offset.h" @@ -86,6 +90,9 @@ #include "display/curve.h" #include "display/canvas-bpath.h" #include "inkscape-private.h" +#include "path-chemistry.h" +#include "ui/tool/control-point-selection.h" +#include "ui/tool/multi-path-manipulator.h" // For clippath editing #include "tools-switch.h" @@ -100,6 +107,102 @@ using Geom::Y; because the layer manipulation code uses them. It should be rewritten specifically for that purpose. */ + + +namespace Inkscape { + +void SelectionHelper::selectAll(SPDesktop *dt) +{ + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_multipath->selectSubpaths(); + } else { + sp_edit_select_all(dt); + } +} + +void SelectionHelper::selectAllInAll(SPDesktop *dt) +{ + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_selected_nodes->selectAll(); + } else { + sp_edit_select_all_in_all_layers(dt); + } +} + +void SelectionHelper::selectNone(SPDesktop *dt) +{ + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_selected_nodes->clear(); + } else { + sp_desktop_selection(dt)->clear(); + } +} + +void SelectionHelper::invert(SPDesktop *dt) +{ + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_multipath->invertSelectionInSubpaths(); + } else { + sp_edit_invert(dt); + } +} + +void SelectionHelper::invertAllInAll(SPDesktop *dt) +{ + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_selected_nodes->invertSelection(); + } else { + sp_edit_invert_in_all_layers(dt); + } +} + +void SelectionHelper::reverse(SPDesktop *dt) +{ + // TODO make this a virtual method of event context! + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_multipath->reverseSubpaths(); + } else { + sp_selected_path_reverse(dt); + } +} + +void SelectionHelper::selectNext(SPDesktop *dt) +{ + SPEventContext *ec = dt->event_context; + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_multipath->shiftSelection(1); + } else if (tools_isactive(dt, TOOLS_GRADIENT) + && ec->_grdrag->isNonEmpty()) { + sp_gradient_context_select_next(ec); + } else { + sp_selection_item_next(dt); + } +} + +void SelectionHelper::selectPrev(SPDesktop *dt) +{ + SPEventContext *ec = dt->event_context; + if (tools_isactive(dt, TOOLS_NODES)) { + InkNodeTool *nt = static_cast(dt->event_context); + nt->_multipath->shiftSelection(-1); + } else if (tools_isactive(dt, TOOLS_GRADIENT) + && ec->_grdrag->isNonEmpty()) { + sp_gradient_context_select_prev(ec); + } else { + sp_selection_item_prev(dt); + } +} + +} // namespace Inkscape + + /** * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t', * then prepends the copy to 'clip'. diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 7cc5f8d9f..60d64ced9 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -1,5 +1,5 @@ -#ifndef __SP_SELECTION_CHEMISTRY_H__ -#define __SP_SELECTION_CHEMISTRY_H__ +#ifndef SEEN_SELECTION_CHEMISTRY_H +#define SEEN_SELECTION_CHEMISTRY_H /* * Miscellanous operations on selected items @@ -8,8 +8,9 @@ * Lauris Kaplinski * Frank Felfe * bulia byak + * Jon A. Cruz * - * Copyright (C) 1999-2005 authors + * Copyright (C) 1999-2010 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -28,6 +29,20 @@ namespace LivePathEffect { class SPCSSAttr; +namespace Inkscape { + class SelectionHelper { + public: + static void selectAll(SPDesktop *desktop); + static void selectAllInAll(SPDesktop *desktop); + static void selectNone(SPDesktop *desktop); + static void invert(SPDesktop *desktop); + static void invertAllInAll(SPDesktop *desktop); + static void reverse(SPDesktop *dt); + static void selectNext(SPDesktop *desktop); + static void selectPrev(SPDesktop *desktop); + }; +} // namespace Inkscape + void sp_selection_delete(SPDesktop *desktop); void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone = false); void sp_edit_clear_all(SPDesktop *desktop); @@ -131,19 +146,14 @@ GSList *sp_degroup_list (GSList *items); /* selection cycling */ typedef enum { - SP_CYCLE_SIMPLE, - SP_CYCLE_VISIBLE, /* cycle only visible items */ - SP_CYCLE_FOCUS /* readjust visible area to view selected item */ + SP_CYCLE_SIMPLE, + SP_CYCLE_VISIBLE, // cycle only visible items + SP_CYCLE_FOCUS // readjust visible area to view selected item } SPCycleType; -/* fixme: This should be moved into preference repr */ -#ifndef __SP_SELECTION_CHEMISTRY_C__ -extern SPCycleType SP_CYCLING; -#else -SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; -#endif - -#endif +// TOOD fixme: This should be moved into preference repr +extern SPCycleType SP_CYCLING; +#endif // SEEN_SELECTION_CHEMISTRY_H diff --git a/src/verbs.cpp b/src/verbs.cpp index 37f4da4d6..7c3652b36 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -16,6 +16,7 @@ * MenTaLguY * David Turner * bulia byak + * Jon A. Cruz * * Copyright (C) 2006 Johan Engelen * Copyright (C) (date unspecified) Authors @@ -49,7 +50,6 @@ #include "draw-context.h" #include "extension/effect.h" #include "file.h" -#include "gradient-context.h" #include "gradient-drag.h" #include "helper/action.h" #include "help.h" @@ -79,8 +79,6 @@ #include "ui/dialog/layers.h" #include "ui/dialog/swatches.h" #include "ui/icon-names.h" -#include "ui/tool/control-point-selection.h" -#include "ui/tool/multi-path-manipulator.h" #include "ui/tool/node-tool.h" //#ifdef WITH_INKBOARD @@ -835,7 +833,6 @@ EditVerb::perform(SPAction *action, void *data, void */*pdata*/) SPDesktop *dt = static_cast(sp_action_get_view(action)); if (!dt) return; - SPEventContext *ec = dt->event_context; switch (reinterpret_cast(data)) { case SP_VERB_EDIT_UNDO: @@ -920,70 +917,26 @@ EditVerb::perform(SPAction *action, void *data, void */*pdata*/) sp_edit_clear_all(dt); break; case SP_VERB_EDIT_SELECT_ALL: - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_multipath->selectSubpaths(); - } else { - sp_edit_select_all(dt); - } + SelectionHelper::selectAll(dt); break; case SP_VERB_EDIT_INVERT: - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_multipath->invertSelectionInSubpaths(); - } else { - sp_edit_invert(dt); - } + SelectionHelper::invert(dt); break; case SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS: - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_selected_nodes->selectAll(); - } else { - sp_edit_select_all_in_all_layers(dt); - } + SelectionHelper::selectAllInAll(dt); break; case SP_VERB_EDIT_INVERT_IN_ALL_LAYERS: - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_selected_nodes->invertSelection(); - } else { - sp_edit_invert_in_all_layers(dt); - } + SelectionHelper::invertAllInAll(dt); break; - case SP_VERB_EDIT_SELECT_NEXT: - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_multipath->shiftSelection(1); - } else if (tools_isactive(dt, TOOLS_GRADIENT) - && ec->_grdrag->isNonEmpty()) { - sp_gradient_context_select_next (ec); - } else { - sp_selection_item_next(dt); - } + SelectionHelper::selectNext(dt); break; case SP_VERB_EDIT_SELECT_PREV: - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_multipath->shiftSelection(-1); - } else if (tools_isactive(dt, TOOLS_GRADIENT) - && ec->_grdrag->isNonEmpty()) { - sp_gradient_context_select_prev (ec); - } else { - sp_selection_item_prev(dt); - } + SelectionHelper::selectPrev(dt); break; - case SP_VERB_EDIT_DESELECT: - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_selected_nodes->clear(); - } else { - sp_desktop_selection(dt)->clear(); - } + SelectionHelper::selectNone(dt); break; - case SP_VERB_EDIT_GUIDES_AROUND_PAGE: sp_guide_create_guides_around_page(dt); break; @@ -1095,13 +1048,7 @@ SelectionVerb::perform(SPAction *action, void *data, void */*pdata*/) sp_selected_path_simplify(dt); break; case SP_VERB_SELECTION_REVERSE: - // TODO make this a virtual method of event context! - if (tools_isactive(dt, TOOLS_NODES)) { - InkNodeTool *nt = static_cast(dt->event_context); - nt->_multipath->reverseSubpaths(); - } else { - sp_selected_path_reverse(dt); - } + SelectionHelper::reverse(dt); break; case SP_VERB_SELECTION_TRACE: inkscape_dialogs_unhide(); -- 2.30.2