Code

add verbs for unlocking and unhiding all objects globaly or within the current layer
authoracspike <acspike@users.sourceforge.net>
Mon, 12 Mar 2007 03:26:13 +0000 (03:26 +0000)
committeracspike <acspike@users.sourceforge.net>
Mon, 12 Mar 2007 03:26:13 +0000 (03:26 +0000)
src/selection-chemistry.cpp
src/selection-chemistry.h
src/verbs.cpp
src/verbs.h

index bc9ebe7a5a60bcd481bcdeb6888d0ba7423c5d76..7d22695fc45d1042f8a984d2630f1ba06ebf42f6 100644 (file)
@@ -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++
index 6bd58e8e5af0fe8f49af8bffc282ba78d9151941..0ad465ec472439ef7ab1e425a9357e212102700f 100644 (file)
@@ -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
index cc01706eacd3ba47297a1fa7373c2066946eb313..91adfc7d08a6ccc65a0543bbb643742a858ceb35 100644 (file)
@@ -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<SPDesktop*>(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)
 };
index 40930f46da9b3e6c7a2a4840dc1e4c496f300e27..3ebc129d16d41c7ebb88dcc2330c6f1d9c23d047 100644 (file)
@@ -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
 };