From 410db19c3e005769ef7dbf538a5b5fa5f0b5b88e Mon Sep 17 00:00:00 2001 From: joncruz Date: Sun, 21 May 2006 15:58:09 +0000 Subject: [PATCH] Adding notification when managed layers change. --- ChangeLog | 6 ++++++ src/dialogs/layers-panel.cpp | 28 +++++++++++++++++++++++++--- src/dialogs/layers-panel.h | 8 +++++--- src/layer-manager.cpp | 22 +++++++++++++++++++++- src/layer-manager.h | 14 ++++++++++++++ 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8b601381e..f14540efc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-05-21 Jon A. Cruz + + * 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 * src/extension/internal/pdf.cpp: Compilation fix. For versions diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index 0ee6ac7e7..21b3102ef 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -350,6 +350,27 @@ public: Gtk::TreeModelColumn _colLocked; }; +void LayersPanel::_updateLayer( SPObject *layer ) { + _store->foreach( sigc::bind(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(); diff --git a/src/dialogs/layers-panel.h b/src/dialogs/layers-panel.h index bdfab6b29..f7a9f0799 100644 --- a/src/dialogs/layers-panel.h +++ b/src/dialogs/layers-panel.h @@ -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; diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp index c2999f6c8..ab2dff107 100644 --- a/src/layer-manager.cpp +++ b/src/layer-manager.cpp @@ -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 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); +} + } /* diff --git a/src/layer-manager.h b/src/layer-manager.h index 48ef73c73..b4d827089 100644 --- a/src/layer-manager.h +++ b/src/layer-manager.h @@ -25,10 +25,21 @@ class LayerManager : public DocumentSubset, public: LayerManager(SPDesktop *desktop); + sigc::connection connectCurrentLayerChanged(const sigc::slot & slot) { + return _layer_changed_signal.connect(slot); + } + + sigc::connection connectLayerDetailsChanged(const sigc::slot & 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 _desktop; SPDocument *_document; + + sigc::signal _layer_changed_signal; + sigc::signal _details_changed_signal; }; } -- 2.30.2