From: acspike Date: Mon, 12 Mar 2007 03:26:13 +0000 (+0000) Subject: add verbs for unlocking and unhiding all objects globaly or within the current layer X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=42a42d6e2fde3e6581f84c38eeecf0888ceaa4bc;p=inkscape.git add verbs for unlocking and unhiding all objects globaly or within the current layer --- diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index bc9ebe7a5..7d22695fc 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2870,6 +2870,62 @@ void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) { _("Fit page to selection")); }; +static void itemtree_map(void (*f)(SPItem *, SPDesktop *), SPObject *root, SPDesktop *desktop) { + // don't operate on layers + if (SP_IS_ITEM(root) && !desktop->isLayer(SP_ITEM(root))) { + f(SP_ITEM(root), desktop); + } + for ( SPObject::SiblingIterator iter = root->firstChild() ; iter ; ++iter ) { + //don't recurse into locked layers + if (!(desktop->isLayer(SP_ITEM(&*iter)) && SP_ITEM(&*iter)->isLocked())) { + itemtree_map(f, iter, desktop); + } + } +} + +static void unlock(SPItem *item, SPDesktop *desktop) { + if (item->isLocked()) { + item->setLocked(FALSE); + } +} + +static void unhide(SPItem *item, SPDesktop *desktop) { + if (desktop->itemIsHidden(item)) { + item->setExplicitlyHidden(FALSE); + } +} + +static void process_all(void (*f)(SPItem *, SPDesktop *), SPDesktop *dt, bool layer_only, char *label) { + if (!dt) return; + + SPObject *root; + if (layer_only) { + root = dt->currentLayer(); + } else { + root = dt->currentRoot(); + } + + itemtree_map(f, root, dt); + + sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_ITEM, label); +} + +void unlock_all(SPDesktop *dt) { + process_all(&unlock, dt, true, _("Unlock all objects in the current layer")); +} + +void unlock_all_in_all_layers(SPDesktop *dt) { + process_all(&unlock, dt, false, _("Unlock all objects in all layers")); +} + +void unhide_all(SPDesktop *dt) { + process_all(&unhide, dt, true, _("Unhide all objects in the current layer")); +} + +void unhide_all_in_all_layers(SPDesktop *dt) { + process_all(&unhide, dt, false, _("Unhide all objects in all layers")); +} + /* Local Variables: mode:c++ diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 6bd58e8e5..0ad465ec4 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -100,6 +100,12 @@ void fit_canvas_to_selection(SPDesktop *desktop); void fit_canvas_to_drawing(SPDocument *doc); void fit_canvas_to_selection_or_drawing(SPDesktop *desktop); +void unlock_all(SPDesktop *dt); +void unlock_all_in_all_layers(SPDesktop *dt); +void unhide_all(SPDesktop *dt); +void unhide_all_in_all_layers(SPDesktop *dt); + + /* selection cycling */ typedef enum diff --git a/src/verbs.cpp b/src/verbs.cpp index cc01706ea..91adfc7d0 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1966,8 +1966,74 @@ FitCanvasVerb::perform(SPAction *action, void *data, void *pdata) /* *********** End Fit Canvas ********** */ +/* *********** Lock'N'Hide ********** */ +/** \brief A class to represent the object unlocking and unhiding verbs */ +class LockAndHideVerb : public Verb { +private: + static void perform(SPAction *action, void *mydata, void *otherdata); + static SPActionEventVector vector; +protected: + virtual SPAction *make_action(Inkscape::UI::View::View *view); +public: + /** \brief Use the Verb initializer with the same parameters. */ + LockAndHideVerb(unsigned int const code, + gchar const *id, + gchar const *name, + gchar const *tip, + gchar const *image) : + Verb(code, id, name, tip, image) + { + set_default_sensitive(false); + } +}; /* LockAndHideVerb class */ + +/** + * The vector to attach in the lock'n'hide verb. + */ +SPActionEventVector LockAndHideVerb::vector = + {{NULL},LockAndHideVerb::perform, NULL, NULL, NULL, NULL}; + +/** \brief Create an action for a \c LockAndHideVerb + \param view Which view the action should be created for + \return The built action. + + Calls \c make_action_helper with the \c vector. +*/ +SPAction * +LockAndHideVerb::make_action(Inkscape::UI::View::View *view) +{ + SPAction *action = make_action_helper(view, &vector); + return action; +} +/** \brief Decode the verb code and take appropriate action */ +void +LockAndHideVerb::perform(SPAction *action, void *data, void *pdata) +{ + SPDesktop *dt = static_cast(sp_action_get_view(action)); + if (!dt) return; + + switch ((long) data) { + case SP_VERB_UNLOCK_ALL: + unlock_all(dt); + break; + case SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS: + unlock_all_in_all_layers(dt); + break; + case SP_VERB_UNHIDE_ALL: + unhide_all(dt); + break; + case SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS: + unhide_all_in_all_layers(dt); + break; + default: + return; + } + + return; +} +/* *********** End Lock'N'Hide ********** */ /* these must be in the same order as the SP_VERB_* enum in "verbs.h" */ @@ -2403,6 +2469,15 @@ Verb *Verb::_base_verbs[] = { N_("Fit the page to the drawing"), NULL), new FitCanvasVerb(SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, "FitCanvasToSelectionOrDrawing", N_("Fit Page to Selection or Drawing"), N_("Fit the page to the current selection or the drawing if there is no selection"), NULL), + /* LockAndHide */ + new LockAndHideVerb(SP_VERB_UNLOCK_ALL, "UnlockAll", N_("Unlock All"), + N_("Unlock all objects in the current layer"), NULL), + new LockAndHideVerb(SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS, "UnlockAllInAllLayers", N_("Unlock All in All Layers"), + N_("Unlock all objects in all layers"), NULL), + new LockAndHideVerb(SP_VERB_UNHIDE_ALL, "UnhideAll", N_("Unhide All"), + N_("Unhide all objects in the current layer"), NULL), + new LockAndHideVerb(SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS, "UnhideAllInAllLayers", N_("Unhide All in All Layers"), + N_("Unhide all objects in all layers"), NULL), /* Footer */ new Verb(SP_VERB_LAST, " '\"invalid id", NULL, NULL, NULL) }; diff --git a/src/verbs.h b/src/verbs.h index 40930f46d..3ebc129d1 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -233,6 +233,11 @@ enum { SP_VERB_FIT_CANVAS_TO_SELECTION, SP_VERB_FIT_CANVAS_TO_DRAWING, SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING, + /* LockAndHide */ + SP_VERB_UNLOCK_ALL, + SP_VERB_UNLOCK_ALL_IN_ALL_LAYERS, + SP_VERB_UNHIDE_ALL, + SP_VERB_UNHIDE_ALL_IN_ALL_LAYERS, /* Footer */ SP_VERB_LAST };