From: joncruz Date: Fri, 26 May 2006 07:10:40 +0000 (+0000) Subject: Cleaned up propagation of status changes. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=87c6636aa10a025441b313717f37fdbbc5b9af6e;p=inkscape.git Cleaned up propagation of status changes. --- diff --git a/ChangeLog b/ChangeLog index 394ac602e..722f97376 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-05-26 Jon A. Cruz + + * src/layer-manager.cpp, src/layer-manager.h, + src/widgets/layer-selector.cpp: + + Cleaned up propagation of status changes. + Fixes bug #1495333. + 2006-05-26 Michael Wybrow * src/path-prefix.h: Add missing CREATE_* directory locations diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp index ab2dff107..840d12380 100644 --- a/src/layer-manager.cpp +++ b/src/layer-manager.cpp @@ -17,9 +17,41 @@ #include "ui/view/view.h" #include "sp-object.h" #include "xml/node.h" +#include "xml/node-observer.h" namespace Inkscape { + +using Inkscape::XML::Node; + +class LayerManager::LayerWatcher : public Inkscape::XML::NodeObserver { +public: + LayerWatcher(LayerManager* mgr, SPObject* obj) : + _mgr(mgr), + _obj(obj), + _lockedAttr(g_quark_from_string("sodipodi:insensitive")), + _labelAttr(g_quark_from_string("inkscape:label")) + {} + + virtual void notifyChildAdded( Node &node, Node &child, Node *prev ) {} + virtual void notifyChildRemoved( Node &node, Node &child, Node *prev ) {} + virtual void notifyChildOrderChanged( Node &node, Node &child, Node *old_prev, Node *new_prev ) {} + virtual void notifyContentChanged( Node &node, Util::ptr_shared old_content, Util::ptr_shared new_content ) {} + virtual void notifyAttributeChanged( Node &node, GQuark name, Util::ptr_shared old_value, Util::ptr_shared new_value ) { + if ( name == _lockedAttr || name == _labelAttr ) { + if ( _mgr && _obj ) { + _mgr->_objectModified( _obj, 0 ); + } + } + } + + LayerManager* _mgr; + SPObject* _obj; + GQuark _lockedAttr; + GQuark _labelAttr; +}; + + LayerManager::LayerManager(SPDesktop *desktop) : _desktop(desktop), _document(NULL) { @@ -59,7 +91,19 @@ void LayerManager::_objectModified( SPObject* obj, guint flags ) } void LayerManager::_rebuild() { + while ( !_watchers.empty() ) { + LayerWatcher* one = _watchers.back(); + _watchers.pop_back(); + if ( one->_obj ) { + Node* node = SP_OBJECT_REPR(one->_obj); + if ( node ) { + node->removeObserver(*one); + } + } + } + _clear(); + GSList const *layers=sp_document_get_resource_list(_document, "layer"); SPObject *root=_desktop->currentRoot(); if ( root ) { @@ -78,10 +122,14 @@ void LayerManager::_rebuild() { while ( higher && (SP_OBJECT_PARENT(higher) != root) ) { higher = SP_OBJECT_PARENT(higher); } - Inkscape::XML::Node* node = higher ? SP_OBJECT_REPR(higher) : 0; + Node* node = higher ? SP_OBJECT_REPR(higher) : 0; if ( node && node->parent() ) { g_signal_connect( G_OBJECT(curr), "modified", G_CALLBACK( _objectModifiedCB ), this ); + LayerWatcher* eye = new LayerWatcher(this, curr); + _watchers.push_back( eye ); + SP_OBJECT_REPR(curr)->addObserver(*eye); + _addOne(curr); } } diff --git a/src/layer-manager.h b/src/layer-manager.h index b4d827089..d92946a4c 100644 --- a/src/layer-manager.h +++ b/src/layer-manager.h @@ -13,6 +13,7 @@ #include "document-subset.h" #include "gc-finalized.h" #include "gc-soft-ptr.h" +#include class SPDesktop; class SPDocument; @@ -34,6 +35,9 @@ public: } private: + friend class LayerWatcher; + class LayerWatcher; + static void _objectModifiedCB( SPObject* obj, guint flags, LayerManager* mgr ); void _objectModified( SPObject* obj, guint flags ); @@ -48,6 +52,8 @@ private: GC::soft_ptr _desktop; SPDocument *_document; + std::vector _watchers; + sigc::signal _layer_changed_signal; sigc::signal _details_changed_signal; }; diff --git a/src/widgets/layer-selector.cpp b/src/widgets/layer-selector.cpp index 8fe0c928e..bf23dcfca 100644 --- a/src/widgets/layer-selector.cpp +++ b/src/widgets/layer-selector.cpp @@ -418,6 +418,18 @@ void LayerSelector::_protectUpdate(sigc::slot slot) { _visibility_toggled_connection.block(true); _lock_toggled_connection.block(true); slot(); + + SPObject *layer = _desktop ? _desktop->currentLayer() : 0; + if ( layer ) { + bool wantedValue = ( SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false ); + if ( _lock_toggle.get_active() != wantedValue ) { + _lock_toggle.set_active( wantedValue ); + } + wantedValue = ( SP_IS_ITEM(layer) ? SP_ITEM(layer)->isHidden() : false ); + if ( _visibility_toggle.get_active() != wantedValue ) { + _visibility_toggle.set_active( wantedValue ); + } + } _visibility_toggled_connection.block(visibility_blocked); _lock_toggled_connection.block(lock_blocked); }