Code

Correct desktop tracking for layers dialog. Fixes bug #427514.
authorJon A. Cruz <jon@joncruz.org>
Tue, 27 Apr 2010 07:48:04 +0000 (00:48 -0700)
committerJon A. Cruz <jon@joncruz.org>
Tue, 27 Apr 2010 07:48:04 +0000 (00:48 -0700)
src/document-subset.cpp
src/layer-manager.cpp
src/layer-manager.h
src/ui/dialog/layers.cpp
src/ui/dialog/layers.h

index eb7265b2d269171bdb3f4c4b027f3c44033ac088..1988865d10c98b88221d875eb5292d5b1c6ba92b 100644 (file)
@@ -301,7 +301,7 @@ void DocumentSubset::Relations::remove(SPObject *obj, bool subtree) {
         /* remove obj's record */
         _doRemove(obj);
     }
-    
+
     changed_signal.emit();
 }
 
index 8c45c7e53642fdebabb75b930ce24efb09909ab2..db7384622ee6dc6d007b73e69588402baabfe551 100644 (file)
@@ -142,6 +142,7 @@ LayerManager::~LayerManager()
     _layer_connection.disconnect();
     _document_connection.disconnect();
     _resource_connection.disconnect();
+    _document = 0;
 }
 
 void LayerManager::setCurrentLayer( SPObject* obj )
@@ -315,7 +316,7 @@ void LayerManager::_rebuild() {
                 LayerWatcher *eye = new LayerWatcher(this, layer, connection);
                 _watchers.push_back( eye );
                 SP_OBJECT_REPR(layer)->addObserver(*eye);
-                
+
                 _addOne(layer);
             }
         }
index 81f75e002aef5144ef16cbc8937a5a3d27b7ccb2..5b5d25eb2aaf5deb342bae5baa017fe2f94b0bae 100644 (file)
@@ -32,11 +32,11 @@ public:
     void renameLayer( SPObject* obj, gchar const *label, bool uniquify );
 
     sigc::connection connectCurrentLayerChanged(const sigc::slot<void, SPObject *> & slot) {
-       return _layer_changed_signal.connect(slot);
+        return _layer_changed_signal.connect(slot);
     }
 
     sigc::connection connectLayerDetailsChanged(const sigc::slot<void, SPObject *> & slot) {
-       return _details_changed_signal.connect(slot);
+        return _details_changed_signal.connect(slot);
     }
 
 private:
index 98bf236fc0c3bf1c106b447e6e32a431f9de218f..ff3a13ab2dd74d62e9ddb7806a4da8effffb495b 100644 (file)
@@ -4,7 +4,7 @@
  * Authors:
  *   Jon A. Cruz
  *
- * Copyright (C) 2006 Jon A. Cruz
+ * Copyright (C) 2006,2010 Jon A. Cruz
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
 namespace Inkscape {
 namespace UI {
-namespace Dialogs {
+namespace Dialog {
 
-LayersPanel&
-LayersPanel::getInstance()
+LayersPanel& LayersPanel::getInstance()
 {
     return *new LayersPanel();
 }
@@ -73,28 +72,6 @@ public:
     SPObject* _target;
 };
 
-static gboolean layers_panel_activated(Inkscape::Application * /*inkscape*/, SPDesktop *desktop, gpointer data )
-{
-    if ( data )
-    {
-        LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
-        panel->setDesktop(desktop);
-    }
-
-    return FALSE;
-}
-
-static gboolean layers_panel_deactivated( GtkObject */*object*/, GdkEvent * /*event*/, gpointer data )
-{
-    if ( data )
-    {
-        LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
-        panel->setDesktop(NULL);
-    }
-
-    return FALSE;
-}
-
 void LayersPanel::_styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback )
 {
     bool set = false;
@@ -348,12 +325,12 @@ bool LayersPanel::_checkForSelected(const Gtk::TreePath &path, const Gtk::TreeIt
 void LayersPanel::_layersChanged()
 {
 //    g_message("_layersChanged()");
-    if(_desktop) {
+    if (_desktop) {
         SPDocument* document = _desktop->doc();
         SPObject* root = document->root;
         if ( root ) {
             _selectedConnection.block();
-            if ( _mgr && _mgr->includes( root ) ) {
+            if ( _desktop->layer_manager && _desktop->layer_manager->includes( root ) ) {
                 SPObject* target = _desktop->currentLayer();
                 _store->clear();
 
@@ -369,10 +346,10 @@ void LayersPanel::_layersChanged()
 
 void LayersPanel::_addLayer( SPDocument* doc, SPObject* layer, Gtk::TreeModel::Row* parentRow, SPObject* target, int level )
 {
-    if ( layer && (level < _maxNestDepth) ) {
-        unsigned int counter = _mgr->childCount(layer);
+    if ( _desktop && _desktop->layer_manager && layer && (level < _maxNestDepth) ) {
+        unsigned int counter = _desktop->layer_manager->childCount(layer);
         for ( unsigned int i = 0; i < counter; i++ ) {
-            SPObject *child = _mgr->nthChildOf(layer, i);
+            SPObject *child = _desktop->layer_manager->nthChildOf(layer, i);
             if ( child ) {
 #if DUMP_LAYERS
                 g_message(" %3d    layer:%p  {%s}   [%s]", level, child, child->id, child->label() );
@@ -416,15 +393,15 @@ SPObject* LayersPanel::_selectedLayer()
 void LayersPanel::_pushTreeSelectionToCurrent()
 {
     // TODO hunt down the possible API abuse in getting NULL
-    if ( _desktop && _desktop->currentRoot() ) {
+    if ( _desktop && _desktop->layer_manager && _desktop->currentRoot() ) {
         SPObject* inTree = _selectedLayer();
         if ( inTree ) {
             SPObject* curr = _desktop->currentLayer();
             if ( curr != inTree ) {
-                _mgr->setCurrentLayer( inTree );
+                _desktop->layer_manager->setCurrentLayer( inTree );
             }
         } else {
-            _mgr->setCurrentLayer( _desktop->doc()->root );
+            _desktop->layer_manager->setCurrentLayer( _desktop->doc()->root );
         }
     }
 }
@@ -537,13 +514,13 @@ void LayersPanel::_handleButtonEvent(GdkEventButton* evt)
 void LayersPanel::_handleRowChange( Gtk::TreeModel::Path const& /*path*/, Gtk::TreeModel::iterator const& iter )
 {
     Gtk::TreeModel::Row row = *iter;
-    if ( row ) {
+    if ( row && _desktop && _desktop->layer_manager) {
         SPObject* obj = row[_model->_colObject];
         if ( obj ) {
             gchar const* oldLabel = obj->label();
             Glib::ustring tmp = row[_model->_colLabel];
             if ( oldLabel && oldLabel[0] && !tmp.empty() && (tmp != oldLabel) ) {
-                _mgr->renameLayer( obj, tmp.c_str(), FALSE );
+                _desktop->layer_manager->renameLayer( obj, tmp.c_str(), FALSE );
                 row[_model->_colLabel] = obj->label();
             }
         }
@@ -583,13 +560,14 @@ bool LayersPanel::_rowSelectFunction( Glib::RefPtr<Gtk::TreeModel> const & /*mod
  */
 LayersPanel::LayersPanel() :
     UI::Widget::Panel("", "/dialogs/layers", SP_VERB_DIALOG_LAYERS),
+    deskTrack(),
     _maxNestDepth(20),
-    _mgr(0),
     _desktop(0),
     _model(0),
     _pending(0),
     _toggleEvent(0),
-    _compositeSettings(SP_VERB_DIALOG_LAYERS, "layers", UI::Widget::SimpleFilterModifier::BLEND)
+    _compositeSettings(SP_VERB_DIALOG_LAYERS, "layers", UI::Widget::SimpleFilterModifier::BLEND),
+    desktopChangeConn()
 {
     Inkscape::Preferences *prefs = Inkscape::Preferences::get();
     _maxNestDepth = prefs->getIntLimited("/dialogs/layers/maxDepth", 20, 1, 1000);
@@ -724,14 +702,15 @@ LayersPanel::LayersPanel() :
         (*it)->set_sensitive( false );
     }
 
-    g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK( layers_panel_activated ), this );
-    g_signal_connect( G_OBJECT(INKSCAPE), "deactivate_desktop", G_CALLBACK( layers_panel_deactivated ), this );
-
     setDesktop( targetDesktop );
 
     show_all_children();
 
     // restorePanelPrefs();
+
+    // Connect this up last
+    desktopChangeConn = deskTrack.connectDesktopChanged( sigc::mem_fun(*this, &LayersPanel::setDesktop) );
+    deskTrack.connect(GTK_WIDGET(gobj()));
 }
 
 LayersPanel::~LayersPanel()
@@ -743,6 +722,12 @@ LayersPanel::~LayersPanel()
     if ( _model )
     {
         delete _model;
+        _model = 0;
+    }
+
+    if (_pending) {
+        delete _pending;
+        _pending = 0;
     }
 
     if ( _toggleEvent )
@@ -750,6 +735,9 @@ LayersPanel::~LayersPanel()
         gdk_event_free( _toggleEvent );
         _toggleEvent = 0;
     }
+
+    desktopChangeConn.disconnect();
+    deskTrack.disconnect();
 }
 
 
@@ -761,9 +749,6 @@ void LayersPanel::setDesktop( SPDesktop* desktop )
         _layerChangedConnection.disconnect();
         _layerUpdatedConnection.disconnect();
         _changedConnection.disconnect();
-        if ( _mgr ) {
-            _mgr = 0;
-        }
         if ( _desktop ) {
             _desktop = 0;
         }
@@ -772,11 +757,11 @@ void LayersPanel::setDesktop( SPDesktop* desktop )
         if ( _desktop ) {
             //setLabel( _desktop->doc()->name );
 
-            _mgr = _desktop->layer_manager;
-            if ( _mgr ) {
-                _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) );
+            LayerManager *mgr = _desktop->layer_manager;
+            if ( mgr ) {
+                _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();
@@ -790,6 +775,7 @@ void LayersPanel::setDesktop( SPDesktop* desktop )
         g_message("  {%s}   [%s]", layer->id, layer->label() );
     }
 */
+    deskTrack.setBase(desktop);
 }
 
 
index 16b3be3508802fc239e6d8e7e00b25ba02217b53..4f2a654350901a671a6bd185a85693800c18beb2 100644 (file)
@@ -4,7 +4,7 @@
  * Authors:
  *   Jon A. Cruz
  *
- * Copyright (C) 2006 Jon A. Cruz
+ * Copyright (C) 2006,2010 Jon A. Cruz
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
@@ -25,6 +25,7 @@
 //#include "ui/previewholder.h"
 #include "ui/widget/panel.h"
 #include "ui/widget/object-composite-settings.h"
+#include "desktop-tracker.h"
 
 class SPObject;
 
@@ -33,7 +34,7 @@ namespace Inkscape {
 class LayerManager;
 
 namespace UI {
-namespace Dialogs {
+namespace Dialog {
 
 
 /**
@@ -46,7 +47,7 @@ public:
     virtual ~LayersPanel();
 
     //virtual void setOrientation( Gtk::AnchorType how );
-    
+
     static LayersPanel& getInstance();
 
     void setDesktop( SPDesktop* desktop );
@@ -100,8 +101,8 @@ private:
     // Internal
     sigc::connection _selectedConnection;
 
+    DesktopTracker deskTrack;
     int _maxNestDepth;
-    Inkscape::LayerManager* _mgr;
     SPDesktop* _desktop;
     ModelColumns* _model;
     InternalUIBounce* _pending;
@@ -121,6 +122,7 @@ private:
 
     UI::Widget::StyleSubject::CurrentLayer _subject;
     UI::Widget::ObjectCompositeSettings _compositeSettings;
+    sigc::connection desktopChangeConn;
 };