Code

Adding notification when managed layers change.
authorjoncruz <joncruz@users.sourceforge.net>
Sun, 21 May 2006 15:58:09 +0000 (15:58 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Sun, 21 May 2006 15:58:09 +0000 (15:58 +0000)
ChangeLog
src/dialogs/layers-panel.cpp
src/dialogs/layers-panel.h
src/layer-manager.cpp
src/layer-manager.h

index 8b601381e65e6d856c0ec60ad7108bd10950afb2..f14540efc43b09eb2de33d7b76e117ef5a529f56 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-05-21  Jon A. Cruz  <jon@joncruz.org>
+
+       * src/layer-manager.cpp, src/layer-manager.h,
+         src/dialogs/layers-panel.cpp, src/dialogs/layers-panel.h:
+         Adding notification when managed layers change.
+
 2006-05-21  Michael Wybrow  <mjwybrow@users.sourceforge.net>
 
        * src/extension/internal/pdf.cpp: Compilation fix.  For versions
index 0ee6ac7e7191ef8a2f84cd4d6d30038e722ed20e..21b3102eff88105ffe162c21a636bb800013bc58 100644 (file)
@@ -350,6 +350,27 @@ public:
     Gtk::TreeModelColumn<bool> _colLocked;
 };
 
+void LayersPanel::_updateLayer( SPObject *layer ) {
+    _store->foreach( sigc::bind<SPObject*>(sigc::mem_fun(*this, &LayersPanel::_checkForUpdated), layer) );
+}
+
+bool LayersPanel::_checkForUpdated(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer)
+{
+    bool stopGoing = false;
+    Gtk::TreeModel::Row row = *iter;
+    Glib::ustring tmp = row[_model->_colLabel];
+    if ( layer == row[_model->_colObject] )
+    {
+        row[_model->_colLabel] = layer->label() ? layer->label() : SP_OBJECT_ID(layer);
+        row[_model->_colVisible] = SP_IS_ITEM(layer) ? !SP_ITEM(layer)->isHidden() : false;
+        row[_model->_colLocked] = SP_IS_ITEM(layer) ? SP_ITEM(layer)->isLocked() : false;
+
+        stopGoing = true;
+    }
+
+    return stopGoing;
+}
+
 void LayersPanel::_selectLayer( SPObject *layer ) {
     if ( !layer || (_desktop && _desktop->doc() && (layer == _desktop->doc()->root)) ) {
         if ( _tree.get_selection()->count_selected_rows() != 0 ) {
@@ -705,6 +726,7 @@ void LayersPanel::setDesktop( SPDesktop* desktop )
 {
     if ( desktop != _desktop ) {
         _layerChangedConnection.disconnect();
+        _layerUpdatedConnection.disconnect();
         _changedConnection.disconnect();
         if ( _mgr ) {
             _mgr = 0;
@@ -715,13 +737,13 @@ void LayersPanel::setDesktop( SPDesktop* desktop )
 
         _desktop = SP_ACTIVE_DESKTOP;
         if ( _desktop ) {
-            _layerChangedConnection = _desktop->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
-
             setLabel( _desktop->doc()->name );
 
             _mgr = _desktop->layer_manager;
             if ( _mgr ) {
-                _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
+                _layerChangedConnection = _mgr->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayersPanel::_selectLayer) );
+                _layerUpdatedConnection = _mgr->connectLayerDetailsChanged( sigc::mem_fun(*this, &LayersPanel::_updateLayer) );
+                _changedConnection = _mgr->connectChanged( sigc::mem_fun(*this, &LayersPanel::_layersChanged) );
             }
 
             _layersChanged();
index bdfab6b29d29a4075138a13008d1e99c3e486d6b..f7a9f079959050e7cfc299e74418b4580d211c6b 100644 (file)
@@ -71,6 +71,9 @@ private:
     void _takeAction( int val );
     bool _executeAction();
 
+    void _updateLayer(SPObject *layer);
+    bool _checkForUpdated(const Gtk::TreePath &path, const Gtk::TreeIter& iter, SPObject* layer);
+
     void _selectLayer(SPObject *layer);
     bool _checkForSelected(const Gtk::TreePath& path, const Gtk::TreeIter& iter, SPObject* layer);
 
@@ -79,10 +82,9 @@ private:
 
     SPObject* _selectedLayer();
 
-    // Hooked to the desktop:
-    sigc::connection _layerChangedConnection;
-
     // Hooked to the layer manager:
+    sigc::connection _layerChangedConnection;
+    sigc::connection _layerUpdatedConnection;
     sigc::connection _changedConnection;
     sigc::connection _addedConnection;
     sigc::connection _removedConnection;
index c2999f6c80c4bc2ea925ee65a12f0239fb7f0775..ab2dff10762028c4244684fedfddc6c4e45936c0 100644 (file)
@@ -23,7 +23,7 @@ namespace Inkscape {
 LayerManager::LayerManager(SPDesktop *desktop)
 : _desktop(desktop), _document(NULL)
 {
-//    _layer_connection = desktop->connectCurrentLayerChanged( sigc::hide<0>( sigc::mem_fun(*this, &LayerManager::_rebuild) ) );
+    _layer_connection = desktop->connectCurrentLayerChanged( sigc::mem_fun(*this, &LayerManager::_selectedLayerChanged) );
 
     sigc::bound_mem_functor1<void, Inkscape::LayerManager, SPDocument*> first = sigc::mem_fun(*this, &LayerManager::_setDocument);
 
@@ -47,6 +47,17 @@ void LayerManager::_setDocument(SPDocument *document) {
     _rebuild();
 }
 
+
+void LayerManager::_objectModifiedCB( SPObject* obj, guint flags, LayerManager* mgr )
+{
+    mgr->_objectModified( obj, flags );
+}
+
+void LayerManager::_objectModified( SPObject* obj, guint flags )
+{
+    _details_changed_signal.emit( obj );
+}
+
 void LayerManager::_rebuild() {
     _clear();
     GSList const *layers=sp_document_get_resource_list(_document, "layer");
@@ -69,6 +80,8 @@ void LayerManager::_rebuild() {
                     }
                     Inkscape::XML::Node* node = higher ? SP_OBJECT_REPR(higher) : 0;
                     if ( node && node->parent() ) {
+                        g_signal_connect( G_OBJECT(curr), "modified", G_CALLBACK( _objectModifiedCB ), this );
+
                         _addOne(curr);
                     }
                 }
@@ -77,6 +90,13 @@ void LayerManager::_rebuild() {
     }
 }
 
+// Connected to the desktop's CurrentLayerChanged signal
+void LayerManager::_selectedLayerChanged(SPObject *layer)
+{
+    // notify anyone who's listening to this instead of directly to the desktop
+    _layer_changed_signal.emit(layer);
+}
+
 }
 
 /*
index 48ef73c73585de665f2c85dd1f55c3698010a235..b4d827089ce0238d401289c92d22be649a21f5db 100644 (file)
@@ -25,10 +25,21 @@ class LayerManager : public DocumentSubset,
 public:
     LayerManager(SPDesktop *desktop);
 
+    sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
+       return _layer_changed_signal.connect(slot);
+    }
+
+    sigc::connection connectLayerDetailsChanged(const sigc::slot<void, SPObject *> & slot) {
+       return _details_changed_signal.connect(slot);
+    }
+
 private:
+    static void _objectModifiedCB( SPObject* obj, guint flags, LayerManager* mgr );
 
+    void _objectModified( SPObject* obj, guint flags );
     void _setDocument(SPDocument *document);
     void _rebuild();
+    void _selectedLayerChanged(SPObject *layer);
 
     sigc::connection _layer_connection;
     sigc::connection _document_connection;
@@ -36,6 +47,9 @@ private:
 
     GC::soft_ptr<SPDesktop> _desktop;
     SPDocument *_document;
+
+    sigc::signal<void, SPObject *>     _layer_changed_signal;
+    sigc::signal<void, SPObject *>     _details_changed_signal;
 };
 
 }