Code

Added the ability to toggle a layer "solo". Fixes bug #171530.
authorjoncruz <joncruz@users.sourceforge.net>
Fri, 13 Jun 2008 15:55:51 +0000 (15:55 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Fri, 13 Jun 2008 15:55:51 +0000 (15:55 +0000)
src/desktop.cpp
src/desktop.h
src/dialogs/layers-panel.cpp
src/verbs.cpp
src/verbs.h

index 5796ed6386ba810fa01aef91ed359249c94f47d8..e16b030a44dfc9d2c2705502fcc61b661bcc172e 100644 (file)
@@ -85,6 +85,7 @@
 #include "xml/repr.h"
 #include "message-context.h"
 #include "device-manager.h"
+#include "layer-fns.h"
 #include "layer-manager.h"
 #include "event-log.h"
 #include "display/canvas-grid.h"
@@ -467,6 +468,31 @@ void SPDesktop::setCurrentLayer(SPObject *object) {
     _layer_hierarchy->setBottom(object);
 }
 
+void SPDesktop::toggleLayerSolo(SPObject *object) {
+    g_return_if_fail(SP_IS_GROUP(object));
+    g_return_if_fail( currentRoot() == object || (currentRoot() && currentRoot()->isAncestorOf(object)) );
+
+    bool othersShowing = false;
+    std::vector<SPObject*> layers;
+    for ( SPObject* obj = Inkscape::next_layer(currentRoot(), object); obj; obj = Inkscape::next_layer(currentRoot(), obj) ) {
+        layers.push_back(obj);
+        othersShowing |= !SP_ITEM(obj)->isHidden();
+    }
+    for ( SPObject* obj = Inkscape::previous_layer(currentRoot(), object); obj; obj = Inkscape::previous_layer(currentRoot(), obj) ) {
+        layers.push_back(obj);
+        othersShowing |= !SP_ITEM(obj)->isHidden();
+    }
+
+
+    if ( SP_ITEM(object)->isHidden() ) {
+        SP_ITEM(object)->setHidden(false);
+    }
+
+    for ( std::vector<SPObject*>::iterator it = layers.begin(); it != layers.end(); ++it ) {
+        SP_ITEM(*it)->setHidden(othersShowing);
+    }
+}
+
 /**
  * Return layer that contains \a object.
  */
index af0d41b2a573ff7335480670e114e1faee43ab77..adb6cb98b1f67089c9877d5801ce7846be458912 100644 (file)
@@ -209,6 +209,7 @@ struct SPDesktop : public Inkscape::UI::View::View
     SPObject *currentRoot() const;
     SPObject *currentLayer() const;
     void setCurrentLayer(SPObject *object);
+    void toggleLayerSolo(SPObject *object);
     SPObject *layerForObject(SPObject *object);
     bool isLayer(SPObject *object) const;
     bool isWithinViewport(SPItem *item) const;
index 480b60b633a2d1005e4fcd5d01639a721d8e10be..ebb6d989d2086a7bd86259f8356dad284ab15da9 100644 (file)
@@ -63,7 +63,8 @@ enum {
     BUTTON_UP,
     BUTTON_DOWN,
 //    BUTTON_DUPLICATE,
-    BUTTON_DELETE
+    BUTTON_DELETE,
+    BUTTON_SOLO
 };
 
 class ImageToggler : public Gtk::CellRendererPixbuf {
@@ -353,6 +354,10 @@ bool LayersPanel::_executeAction()
             {
                 _fireAction( SP_VERB_LAYER_DELETE );
             }
+            case BUTTON_SOLO:
+            {
+                _fireAction( SP_VERB_LAYER_SOLO );
+            }
             break;
         }
 
@@ -575,7 +580,7 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
                 row[_model->_colVisible] = newValue;
                 item->setHidden( !newValue  );
                 item->updateRepr();
-                sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, 
+                sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
                                   newValue? _("Unhide layer") : _("Hide layer"));
             }
             break;
@@ -586,7 +591,7 @@ void LayersPanel::_toggled( Glib::ustring const& str, int targetCol )
                 row[_model->_colLocked] = newValue;
                 item->setLocked( newValue );
                 item->updateRepr();
-                sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS, 
+                sp_document_done( _desktop->doc() , SP_VERB_DIALOG_LAYERS,
                                   newValue? _("Lock layer") : _("Unlock layer"));
             }
             break;
@@ -777,6 +782,7 @@ LayersPanel::LayersPanel() :
     {
         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_RENAME, 0, "Rename", (int)BUTTON_RENAME ) );
         _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_NEW, 0, "New", (int)BUTTON_NEW ) );
+        _watching.push_back( &_addPopupItem( targetDesktop, SP_VERB_LAYER_SOLO, 0, "Solo", (int)BUTTON_SOLO ) );
 
          _popupMenu.items().push_back( Gtk::Menu_Helpers::SeparatorElem() );
 
index 509dff087c0cfe63be06d42769ba349d4be4ccfc..a362d3c0f9e3678901c64648b3e6be595c61b7a3 100644 (file)
@@ -1251,6 +1251,15 @@ LayerVerb::perform(SPAction *action, void *data, void */*pdata*/)
             }
             break;
         }
+        case SP_VERB_LAYER_SOLO: {
+            if ( dt->currentLayer() == dt->currentRoot() ) {
+                dt->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No current layer."));
+            } else {
+                dt->toggleLayerSolo( dt->currentLayer() );
+                sp_document_maybe_done(sp_desktop_document(dt), "layer:solo", SP_VERB_LAYER_SOLO, _("Toggle layer solo"));
+            }
+            break;
+        }
     }
 
     return;
@@ -2372,6 +2381,8 @@ Verb *Verb::_base_verbs[] = {
                   N_("Lower the current layer"), "lower_layer"),
     new LayerVerb(SP_VERB_LAYER_DELETE, "LayerDelete", N_("_Delete Current Layer"),
                   N_("Delete the current layer"), "delete_layer"),
+    new LayerVerb(SP_VERB_LAYER_SOLO, "LayerSolo", N_("_Solo Current Layer"),
+                  N_("Solo the current layer"), 0),
 
     /* Object */
     new ObjectVerb(SP_VERB_OBJECT_ROTATE_90_CW, "ObjectRotate90", N_("Rotate _90&#176; CW"),
index 6447bbadd45a7801b145568419421bb63a4f62c1..198a25521de91d0efc4a296112f013d37cdeebab 100644 (file)
@@ -129,6 +129,7 @@ enum {
     SP_VERB_LAYER_RAISE,
     SP_VERB_LAYER_LOWER,
     SP_VERB_LAYER_DELETE,
+    SP_VERB_LAYER_SOLO,
     /* Object */
     SP_VERB_OBJECT_ROTATE_90_CW,
     SP_VERB_OBJECT_ROTATE_90_CCW,