From: joncruz Date: Fri, 13 Jun 2008 15:55:51 +0000 (+0000) Subject: Added the ability to toggle a layer "solo". Fixes bug #171530. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=da83ec78b92d29793d7cd1d6526585cda47127f4;p=inkscape.git Added the ability to toggle a layer "solo". Fixes bug #171530. --- diff --git a/src/desktop.cpp b/src/desktop.cpp index 5796ed638..e16b030a4 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -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 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::iterator it = layers.begin(); it != layers.end(); ++it ) { + SP_ITEM(*it)->setHidden(othersShowing); + } +} + /** * Return layer that contains \a object. */ diff --git a/src/desktop.h b/src/desktop.h index af0d41b2a..adb6cb98b 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -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; diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index 480b60b63..ebb6d989d 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -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() ); diff --git a/src/verbs.cpp b/src/verbs.cpp index 509dff087..a362d3c0f 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -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° CW"), diff --git a/src/verbs.h b/src/verbs.h index 6447bbadd..198a25521 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -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,