Code

Rework dialog management. Use singleton behavior for dialogs when
authorgustav_b <gustav_b@users.sourceforge.net>
Fri, 7 Dec 2007 01:41:04 +0000 (01:41 +0000)
committergustav_b <gustav_b@users.sourceforge.net>
Fri, 7 Dec 2007 01:41:04 +0000 (01:41 +0000)
started in floating dialogs mode and use one dialog/desktop behavior
when started in dockable dialogs mode. Replace the panels use of the
SP_ACTIVE_DESKTOP macro and unify the panels' handling of desktop
activation events.

30 files changed:
src/desktop.cpp
src/dialogs/extensions.cpp
src/dialogs/extensions.h
src/dialogs/iconpreview.cpp
src/dialogs/iconpreview.h
src/dialogs/layers-panel.cpp
src/dialogs/layers-panel.h
src/dialogs/swatches.cpp
src/dialogs/tiledialog.cpp
src/ui/dialog/align-and-distribute.cpp
src/ui/dialog/dialog-manager.cpp
src/ui/dialog/dialog-manager.h
src/ui/dialog/document-metadata.cpp
src/ui/dialog/document-metadata.h
src/ui/dialog/document-properties.cpp
src/ui/dialog/document-properties.h
src/ui/dialog/fill-and-stroke.cpp
src/ui/dialog/filter-effects-dialog.cpp
src/ui/dialog/find.cpp
src/ui/dialog/livepatheffect-editor.cpp
src/ui/dialog/panel-dialog.h
src/ui/dialog/session-player.cpp
src/ui/dialog/transformation.cpp
src/ui/dialog/undo-history.cpp
src/ui/dialog/undo-history.h
src/ui/dialog/whiteboard-connect.cpp
src/ui/dialog/whiteboard-sharewithchat.cpp
src/ui/dialog/whiteboard-sharewithuser.cpp
src/ui/widget/panel.cpp
src/ui/widget/panel.h

index 7cc77cbab82650bfe90d4850b4594c0cded016b3..d31babf87cb1f365a0dfe11e95353fc912ace79d 100644 (file)
@@ -169,7 +169,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     sp_document_ensure_up_to_date (document);
 
     /* Setup Dialog Manager */
-    _dlg_mgr = new Inkscape::UI::Dialog::DialogManager();
+    _dlg_mgr = &Inkscape::UI::Dialog::DialogManager::getInstance();
 
     dkey = sp_item_display_key_new (1);
 
index 36ec67744d57a1f81cbeae38f90c72a86b4d9aa0..e363df6074b8faaa8af17e8c43493ce5deea2533 100644 (file)
@@ -25,18 +25,13 @@ namespace Dialogs {
 
 using Inkscape::Extension::Extension;
 
-ExtensionsPanel* ExtensionsPanel::instance = 0;
-
-
-ExtensionsPanel& ExtensionsPanel::getInstance()
+ExtensionsPanel &ExtensionsPanel::getInstance()
 {
-    if ( !instance ) {
-        instance = new ExtensionsPanel();
-    }
+    ExtensionsPanel &instance = *new ExtensionsPanel();
 
-    instance->rescan();
+    instance.rescan();
 
-    return *instance;
+    return instance;
 }
 
 
index f4dbada9ed83f8aa6eae801e529d87fc84338835..e253ab84987edd34a0df83899c51875240d9a13d 100644 (file)
@@ -34,7 +34,7 @@ class ExtensionsPanel : public Inkscape::UI::Widget::Panel
 public:
     ExtensionsPanel();
 
-    static ExtensionsPanelgetInstance();
+    static ExtensionsPanel &getInstance();
 
     void set_full(bool full);
 
@@ -42,9 +42,7 @@ private:
     ExtensionsPanel(ExtensionsPanel const &); // no copy
     ExtensionsPanel &operator=(ExtensionsPanel const &); // no assign
 
-    static ExtensionsPanel* instance;
-
-    static void listCB( Inkscape::Extension::Extension * in_plug, gpointer in_data );
+    static void listCB(Inkscape::Extension::Extension *in_plug, gpointer in_data);
 
     void rescan();
 
index c364147053bbce60b8dfbf937c8e7c0d4771154e..e61b7d7f9c48a9c783c4a75c4e700d01bc59dc0c 100644 (file)
@@ -47,18 +47,14 @@ namespace UI {
 namespace Dialogs {
 
 
-IconPreviewPanel* IconPreviewPanel::instance = 0;
-
 IconPreviewPanel&
 IconPreviewPanel::getInstance()
 {
-    if ( !instance ) {
-        instance = new IconPreviewPanel();
-    }
+    IconPreviewPanel &instance = *new IconPreviewPanel();
 
-    instance->refreshPreview();
+    instance.refreshPreview();
 
-    return *instance;
+    return instance;
 }
 
 //#########################################################################
@@ -214,7 +210,7 @@ IconPreviewPanel::IconPreviewPanel() :
 
 void IconPreviewPanel::refreshPreview()
 {
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
     if ( desktop ) {
 
         if ( selectionButton && selectionButton->get_active() )
index 0f34dda4e156fd273f265c9fa08104601ec3629e..3a3652334568b39e32b333cfd327772ad90af70e 100644 (file)
@@ -53,8 +53,6 @@ private:
     void renderPreview( SPObject* obj );
     void updateMagnify();
 
-    static IconPreviewPanel* instance;
-
     Gtk::Tooltips   tips;
 
     Gtk::VBox       iconBox;
index ff18c82b463d0b678357d8f7fe6c3b2735c14cb9..36105c41c0de9d7d4b4268393b350608a613f0ad 100644 (file)
@@ -44,16 +44,10 @@ namespace Inkscape {
 namespace UI {
 namespace Dialogs {
 
-LayersPanel* LayersPanel::instance = 0;
-
 LayersPanel&
 LayersPanel::getInstance()
 {
-    if ( !instance ) {
-        instance = new LayersPanel();
-    }
-
-    return *instance;
+    return *new LayersPanel();
 }
 
 enum {
@@ -193,7 +187,7 @@ static gboolean layers_panel_activated( GtkObject */*object*/, GdkEvent * /*even
     if ( data )
     {
         LayersPanel* panel = reinterpret_cast<LayersPanel*>(data);
-        panel->setDesktop( SP_ACTIVE_DESKTOP );
+        panel->setDesktop(panel->getDesktop());
     }
 
     return FALSE;
@@ -783,7 +777,7 @@ LayersPanel::LayersPanel() :
 
     _opacityConnection = _opacity.get_adjustment()->signal_value_changed().connect( sigc::mem_fun(*this, &LayersPanel::_opacityChanged) );
 
-    SPDesktop* targetDesktop = SP_ACTIVE_DESKTOP;
+    SPDesktop* targetDesktop = getDesktop();
 
     _buttonsRow.set_child_min_width( 16 );
 
@@ -880,6 +874,8 @@ LayersPanel::~LayersPanel()
 
 void LayersPanel::setDesktop( SPDesktop* desktop )
 {
+    Panel::setDesktop(desktop);
+
     if ( desktop != _desktop ) {
         _layerChangedConnection.disconnect();
         _layerUpdatedConnection.disconnect();
@@ -891,7 +887,7 @@ void LayersPanel::setDesktop( SPDesktop* desktop )
             _desktop = 0;
         }
 
-        _desktop = SP_ACTIVE_DESKTOP;
+        _desktop = getDesktop();
         if ( _desktop ) {
             //setLabel( _desktop->doc()->name );
 
index 981d320279346231d823c2ade5bd6957a98291c7..7f56b3f7e7cee0baf8a4d34fdf864b34d7328d0a 100644 (file)
@@ -58,8 +58,6 @@ private:
     LayersPanel(LayersPanel const &); // no copy
     LayersPanel &operator=(LayersPanel const &); // no assign
 
-    static LayersPanel* instance;
-
     void _styleButton( Gtk::Button& btn, SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback );
     void _fireAction( unsigned int code );
     Gtk::MenuItem& _addPopupItem( SPDesktop *desktop, unsigned int code, char const* iconName, char const* fallback, int id );
index 829b06cb6009a88f71c7b07eb007f76c6b4b34c2..e4cf9e9265f7f51b8f190fc862b86d543bd5a72b 100644 (file)
@@ -41,8 +41,6 @@ namespace Inkscape {
 namespace UI {
 namespace Dialogs {
 
-SwatchesPanel* SwatchesPanel::instance = 0;
-
 
 ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ) :
     def( r, g, b, name ),
@@ -989,11 +987,7 @@ static void loadEmUp()
 
 SwatchesPanel& SwatchesPanel::getInstance()
 {
-    if ( !instance ) {
-        instance = new SwatchesPanel();
-    }
-
-    return *instance;
+    return *new SwatchesPanel();
 }
 
 
index 4a60d4413d4d6a8bd19bcd891007851355dbdacb..3ea423b5bdf0a97f27db124b877aed6ff9fa9c0d 100644 (file)
@@ -161,7 +161,7 @@ void TileDialog::Grid_Arrange ()
     grid_left = 99999;
     grid_top = 99999;
 
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
     sp_document_ensure_up_to_date(sp_desktop_document(desktop));
 
     Inkscape::Selection *selection = sp_desktop_selection (desktop);
@@ -378,7 +378,7 @@ void TileDialog::on_row_spinbutton_changed()
 
     // in turn, prevent listener from responding
     updating = true;
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
 
     Inkscape::Selection *selection = sp_desktop_selection (desktop);
 
@@ -403,7 +403,7 @@ void TileDialog::on_col_spinbutton_changed()
 
     // in turn, prevent listener from responding
     updating = true;
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
     Inkscape::Selection *selection = sp_desktop_selection (desktop);
 
     GSList const *items = selection->itemList();
@@ -565,7 +565,7 @@ void TileDialog::updateSelection()
     row_height=0;
     // in turn, prevent listener from responding
     updating = true;
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
     Inkscape::Selection *selection = sp_desktop_selection (desktop);
     const GSList *items = selection->itemList();
     int selcount = g_slist_length((GSList *)items);
@@ -632,7 +632,7 @@ TileDialog::TileDialog()
 
     //##Set up the panel
 
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
 
     Inkscape::Selection *selection = sp_desktop_selection (desktop);
     int selcount = 1;
index 7b616fe18fb196334a5301f3e9f319a65a31a619..655a9428e404bbee295eeb5e3307b1282ee3acaa 100644 (file)
@@ -116,7 +116,7 @@ private :
 
     virtual void on_button_click() {
         //Retreive selected objects
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -300,7 +300,7 @@ public :
 private :
     virtual void on_button_click() {
         //Retreive selected objects
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -426,8 +426,8 @@ private :
     virtual void on_button_click()
     {
 
-        if (!SP_ACTIVE_DESKTOP) return;
-       SPEventContext *event_context = sp_desktop_event_context(SP_ACTIVE_DESKTOP);
+        if (!_dialog.getDesktop()) return;
+       SPEventContext *event_context = sp_desktop_event_context(_dialog.getDesktop());
        if (!SP_IS_NODE_CONTEXT (event_context)) return ;
 
         if (_distribute)
@@ -486,7 +486,7 @@ public:
 private :
     virtual void on_button_click()
     {
-        if (!SP_ACTIVE_DESKTOP) return;
+        if (!_dialog.getDesktop()) return;
 
         // see comment in ActionAlign above
         int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
@@ -495,13 +495,13 @@ private :
         // xGap and yGap are the minimum space required between bounding rectangles.
         double const xGap = removeOverlapXGap.get_value();
         double const yGap = removeOverlapYGap.get_value();
-        removeoverlap(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(),
+        removeoverlap(sp_desktop_selection(_dialog.getDesktop())->itemList(),
                       xGap, yGap);
 
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                          _("Remove overlaps"));
     }
 };
@@ -520,18 +520,18 @@ public:
 private :
     virtual void on_button_click()
     {
-        if (!SP_ACTIVE_DESKTOP) return;
+        if (!_dialog.getDesktop()) return;
 
         // see comment in ActionAlign above
         int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
         prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
 
-        graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
+        graphlayout(sp_desktop_selection(_dialog.getDesktop())->itemList());
 
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                          _("Arrange connector network"));
     }
 };
@@ -550,18 +550,18 @@ public :
 private :
     virtual void on_button_click()
     {
-        if (!SP_ACTIVE_DESKTOP) return;
+        if (!_dialog.getDesktop()) return;
 
         // see comment in ActionAlign above
         int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
         prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
 
-        unclump ((GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList());
+        unclump ((GSList *) sp_desktop_selection(_dialog.getDesktop())->itemList());
 
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done (sp_desktop_document (_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                           _("Unclump"));
     }
 };
@@ -580,7 +580,7 @@ public :
 private :
     virtual void on_button_click()
     {
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -631,7 +631,7 @@ private :
         // restore compensation setting
         prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
 
-        sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+        sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                           _("Randomize positions"));
     }
 };
@@ -673,7 +673,7 @@ private :
     bool _distribute;
     virtual void on_button_click()
     {
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         if (!desktop) return;
 
         Inkscape::Selection *selection = sp_desktop_selection(desktop);
@@ -728,7 +728,7 @@ private :
             }
 
             if (changed) {
-                sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+                sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                                   _("Distribute text baselines"));
             }
 
@@ -748,7 +748,7 @@ private :
             }
 
             if (changed) {
-                sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
+                sp_document_done (sp_desktop_document (desktop), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, 
                                   _("Align text baselines"));
             }
         }
index f8c07cf535c16e4bd99c7687a8ae86e02f93f31d..17215ac00a772f5e45be5d7111111a6218780a00 100644 (file)
@@ -147,6 +147,23 @@ DialogManager::~DialogManager() {
     //        Appears to cause a segfault if we do
 }
 
+
+DialogManager &DialogManager::getInstance()
+{
+    int dialogs_type = prefs_get_int_attribute_limited ("options.dialogtype", "value", DOCK, 0, 1);
+
+    /* Use singleton behavior for floating dialogs */
+    if (dialogs_type == FLOATING) {
+        static DialogManager *instance = 0;
+        
+        if (!instance)
+            instance = new DialogManager();
+        return *instance;
+    } 
+
+    return *new DialogManager();
+}
+
 /**
  * Registers a dialog factory function used to create the named dialog.
  */
index cf5a23712e9d60722e263071ca60cfee8b7c408b..80070f19c8024328060a2a9c0de9b635207d50c3 100644 (file)
@@ -29,6 +29,8 @@ public:
     DialogManager();
     virtual ~DialogManager();
 
+    static DialogManager &getInstance();
+
     sigc::signal<void> show_dialogs;
     sigc::signal<void> show_f12;
     sigc::signal<void> hide_dialogs;
index 5671e08fe5631c16bb36508a9c74faba17935165..5956cfb9bca739db16420eda4cb0056696725df8 100644 (file)
@@ -46,12 +46,7 @@ namespace Dialog {
 
 //---------------------------------------------------
 
-static DocumentMetadata *_instance = 0;
-
 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
-static void on_doc_replaced (SPDesktop* dt, SPDocument* doc);
-static void on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
-static void on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
 
 static Inkscape::XML::NodeEventVector const _repr_events = {
     NULL, /* child_added */
@@ -65,21 +60,11 @@ static Inkscape::XML::NodeEventVector const _repr_events = {
 DocumentMetadata &
 DocumentMetadata::getInstance()
 {
-    if (_instance) return *_instance;
-    _instance = new DocumentMetadata();
-    _instance->init();
-    return *_instance;
+    DocumentMetadata &instance = *new DocumentMetadata();
+    instance.init();
+    return instance;
 }
 
-void
-DocumentMetadata::destroy()
-{
-    if (_instance)
-    {
-        delete _instance;
-        _instance = 0;
-    }
-}
 
 DocumentMetadata::DocumentMetadata()
     : UI::Widget::Panel ("", "dialogs.documentmetadata", SP_VERB_DIALOG_METADATA),
@@ -94,6 +79,10 @@ DocumentMetadata::DocumentMetadata()
     _notebook.append_page(_page_metadata1, _("Metadata"));
     _notebook.append_page(_page_metadata2, _("License"));
 
+    signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDocumentReplaced));
+    signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleActivateDesktop));
+    signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDeactivateDesktop));
+
     build_metadata();
 }
 
@@ -102,25 +91,16 @@ DocumentMetadata::init()
 {
     update();
 
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
     repr->addListener (&_repr_events, this);
 
-    _doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
-
-    g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
-                     G_CALLBACK(on_activate_desktop), 0);
-
-    g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop",
-                     G_CALLBACK(on_deactivate_desktop), 0);
-
     show_all_children();
 }
 
 DocumentMetadata::~DocumentMetadata()
 {
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
     repr->removeListenerByData (this);
-    _doc_replaced_connection.disconnect();
 
     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
         delete (*it);
@@ -232,56 +212,41 @@ DocumentMetadata::update()
     _wr.setUpdating (false);
 }
 
-//--------------------------------------------------------------------
-
-
-/**
- * Called when XML node attribute changed; updates dialog widgets.
- */
-static void
-on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
+void 
+DocumentMetadata::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *)
 {
-    if (!_instance)
-        return;
-
-    _instance->update();
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
+    repr->addListener (&_repr_events, this);
+    update();
 }
 
-static void
-on_activate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
+void 
+DocumentMetadata::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
 {
-    if (!_instance)
-        return;
-
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
-    repr->addListener (&_repr_events, _instance);
-    _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
-    _instance->update();
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
+    repr->addListener(&_repr_events, this);
+    update();
 }
 
-static void
-on_deactivate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
+void
+DocumentMetadata::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
 {
-    if (!_instance)
-        return;
-
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
-    repr->removeListenerByData (_instance);
-    _instance->_doc_replaced_connection.disconnect();
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
+    repr->removeListenerByData(this);
 }
 
+//--------------------------------------------------------------------
+
+/**
+ * Called when XML node attribute changed; updates dialog widgets.
+ */
 static void
-on_doc_replaced (SPDesktop* dt, SPDocument* /*doc*/)
+on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
 {
-    if (!_instance)
-        return;
-
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
-    repr->addListener (&_repr_events, _instance);
-    _instance->update();
+    if (DocumentMetadata *dialog = static_cast<DocumentMetadata *>(data))
+       dialog->update();
 }
 
-
 } // namespace Dialog
 } // namespace UI
 } // namespace Inkscape
index 7ee2ee2167b93d3f2c5609fb4fc91a86661560b8..1b5c08ce17265fd046b59ea656211a2adc0ecabf 100644 (file)
@@ -44,12 +44,15 @@ public:
     static DocumentMetadata &getInstance();
 
     static void destroy();
-    sigc::connection _doc_replaced_connection;
 
 protected:
     void  build_metadata();
     void  init();
 
+    void _handleDocumentReplaced(SPDesktop* desktop, SPDocument *document);
+    void _handleActivateDesktop(Inkscape::Application *application, SPDesktop *desktop);
+    void _handleDeactivateDesktop(Inkscape::Application *application, SPDesktop *desktop);
+
     Gtk::Tooltips _tt;
     Gtk::Notebook  _notebook;
 
index aa608703ad01bc58ed8bffb39d2194cf6c79afbc..8d7b6ac52291d88ce86a8fe786095af59862df9f 100644 (file)
@@ -53,14 +53,9 @@ namespace Dialog {
 
 //---------------------------------------------------
 
-static DocumentProperties *_instance = 0;
-
 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
-static void on_doc_replaced (SPDesktop* dt, SPDocument* doc);
-static void on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
-static void on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
 
 static Inkscape::XML::NodeEventVector const _repr_events = {
     on_child_added, /* child_added */
@@ -74,20 +69,10 @@ static Inkscape::XML::NodeEventVector const _repr_events = {
 DocumentProperties &
 DocumentProperties::getInstance()
 {
-    if (_instance) return *_instance;
-    _instance = new DocumentProperties();
-    _instance->init();
-    return *_instance;
-}
+    DocumentProperties &instance = *new DocumentProperties();
+    instance.init();
 
-void
-DocumentProperties::destroy()
-{
-    if (_instance)
-    {
-        delete _instance;
-        _instance = 0;
-    }
+    return instance;
 }
 
 DocumentProperties::DocumentProperties()
@@ -118,6 +103,10 @@ DocumentProperties::DocumentProperties()
 
     _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
     _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
+
+    signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
+    signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
+    signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
 }
 
 void
@@ -125,30 +114,21 @@ DocumentProperties::init()
 {
     update();
 
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
     repr->addListener (&_repr_events, this);
-    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
+    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
     root->addListener (&_repr_events, this);
 
-    _doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
-
-    g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
-                     G_CALLBACK(on_activate_desktop), 0);
-
-    g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop",
-                     G_CALLBACK(on_deactivate_desktop), 0);
-
     show_all_children();
     _grids_button_remove.hide();
 }
 
 DocumentProperties::~DocumentProperties()
 {
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
     repr->removeListenerByData (this);
-    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
+    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
     root->removeListenerByData (this);
-    _doc_replaced_connection.disconnect();
 }
 
 //========================================================================
@@ -405,7 +385,7 @@ DocumentProperties::build_snap_dtls()
 void
 DocumentProperties::update_gridspage()
 {
-    SPDesktop *dt = SP_ACTIVE_DESKTOP;
+    SPDesktop *dt = getDesktop();
     SPNamedView *nv = sp_desktop_namedview(dt);
 
     //remove all tabs
@@ -437,7 +417,7 @@ DocumentProperties::build_gridspage()
     /// \todo FIXME: gray out snapping when grid is off.
     /// Dissenting view: you want snapping without grid.
 
-    SPDesktop *dt = SP_ACTIVE_DESKTOP;
+    SPDesktop *dt = getDesktop();
     SPNamedView *nv = sp_desktop_namedview(dt);
 
     _grids_label_crea.set_markup(_("<b>Creation</b>"));
@@ -477,7 +457,7 @@ DocumentProperties::update()
 {
     if (_wr.isUpdating()) return;
 
-    SPDesktop *dt = SP_ACTIVE_DESKTOP;
+    SPDesktop *dt = getDesktop();
     SPNamedView *nv = sp_desktop_namedview(dt);
 
     _wr.setUpdating (true);
@@ -542,83 +522,62 @@ DocumentProperties::on_response (int id)
         hide();
 }
 
-
-
-static void
-on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
+void 
+DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
 {
-    if (!_instance)
-        return;
-
-    _instance->update_gridspage();
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
+    repr->addListener(&_repr_events, this);
+    Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
+    root->addListener(&_repr_events, this);
+    update();
 }
 
-static void
-on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
+void 
+DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
 {
-    if (!_instance)
-        return;
-
-    _instance->update_gridspage();
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
+    repr->addListener(&_repr_events, this);
+    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
+    root->addListener(&_repr_events, this);
+    update();
 }
 
-
-
-/**
- * Called when XML node attribute changed; updates dialog widgets.
- */
-static void
-on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
+void
+DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
 {
-    if (!_instance)
-        return;
-
-    _instance->update();
+    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
+    repr->removeListenerByData(this);
+    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
+    root->removeListenerByData(this);
 }
 
 static void
-on_activate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
+on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
 {
-    if (!_instance)
-        return;
-
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
-    repr->addListener (&_repr_events, _instance);
-    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
-    root->addListener (&_repr_events, _instance);
-    _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
-    _instance->update();
+    if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
+       dialog->update_gridspage();
 }
 
 static void
-on_deactivate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
+on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
 {
-    if (!_instance)
-        return;
-
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
-    repr->removeListenerByData (_instance);
-    Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
-    root->removeListenerByData (_instance);
-    _instance->_doc_replaced_connection.disconnect();
+    if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
+       dialog->update_gridspage();
 }
 
+
+
+/**
+ * Called when XML node attribute changed; updates dialog widgets.
+ */
 static void
-on_doc_replaced (SPDesktop* dt, SPDocument* doc)
+on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
 {
-    if (!_instance)
-        return;
-
-    Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
-    repr->addListener (&_repr_events, _instance);
-    Inkscape::XML::Node *root = SP_OBJECT_REPR(doc->root);
-    root->addListener (&_repr_events, _instance);
-    _instance->update();
+    if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
+       dialog->update();
 }
 
 
-
-
 /*########################################################################
 # BUTTON CLICK HANDLERS    (callbacks)
 ########################################################################*/
@@ -626,7 +585,7 @@ on_doc_replaced (SPDesktop* dt, SPDocument* doc)
 void
 DocumentProperties::onNewGrid()
 {
-    SPDesktop *dt = SP_ACTIVE_DESKTOP;
+    SPDesktop *dt = getDesktop();
     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
     SPDocument *doc = sp_desktop_document(dt);
 
@@ -648,7 +607,7 @@ DocumentProperties::onRemoveGrid()
     Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
 
     // find the grid with name tabtext (it's id) and delete that one.
-    SPDesktop *dt = SP_ACTIVE_DESKTOP;
+    SPDesktop *dt = getDesktop();
     SPNamedView *nv = sp_desktop_namedview(dt);
     Inkscape::CanvasGrid * found_grid = NULL;
     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
index e80978ccc8c73e336afb2a5ebaaf6d107b089355..a6fe48ffa0ea475f22b0a64b4c160f7ef5cf2041 100644 (file)
@@ -40,7 +40,6 @@ public:
     void  update();
     static DocumentProperties &getInstance();
     static void destroy();
-    sigc::connection _doc_replaced_connection;
 
     void  update_gridspage();
     
@@ -54,6 +53,10 @@ protected:
     void  init();
     virtual void  on_response (int);
 
+    void _handleDocumentReplaced(SPDesktop* desktop, SPDocument *document);
+    void _handleActivateDesktop(Inkscape::Application *application, SPDesktop *desktop);
+    void _handleDeactivateDesktop(Inkscape::Application *application, SPDesktop *desktop);
+
     Gtk::Tooltips _tt;
     Gtk::Notebook  _notebook;
 
index 4f32d3d91df7be99afff404d479597fffba13737..ab25f5bb3da0d5055a9d7795989fa78e66a5d8b7 100644 (file)
@@ -107,7 +107,7 @@ FillAndStroke::FillAndStroke()
     g_signal_connect ( G_OBJECT (INKSCAPE), "modify_selection", G_CALLBACK (on_selection_modified), this );
     g_signal_connect ( G_OBJECT (INKSCAPE), "activate_desktop", G_CALLBACK (on_selection_changed), this );
 
-    selectionChanged(INKSCAPE, sp_desktop_selection(SP_ACTIVE_DESKTOP));
+    selectionChanged(INKSCAPE, sp_desktop_selection(getDesktop()));
 
     show_all_children();
 }
@@ -167,7 +167,7 @@ FillAndStroke::_blendBlurValueChanged()
     _blocked = true;
 
     //get desktop
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
     if (!desktop) {
         return;
     }
@@ -217,7 +217,7 @@ FillAndStroke::_blendBlurValueChanged()
         }
     }
 
-    sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "fillstroke:blur", SP_VERB_DIALOG_FILL_STROKE,  _("Change blur"));
+    sp_document_maybe_done (sp_desktop_document (desktop), "fillstroke:blur", SP_VERB_DIALOG_FILL_STROKE,  _("Change blur"));
 
     // resume interruptibility
     sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop));
@@ -232,10 +232,12 @@ FillAndStroke::_opacityValueChanged()
         return;
     _blocked = true;
 
+    SPDesktop *desktop = getDesktop();
+
     // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in crash 1580903
     // UPDATE: crash fixed in GTK+ 2.10.7 (bug 374378), remove this as soon as it's reasonably common
     // (though this only fixes the crash, not the multiple change events)
-    sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(SP_ACTIVE_DESKTOP), 0);
+    sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0);
 
     SPCSSAttr *css = sp_repr_css_attr_new ();
 
@@ -243,15 +245,15 @@ FillAndStroke::_opacityValueChanged()
     os << CLAMP (_opacity_adjustment.get_value() / 100, 0.0, 1.0);
     sp_repr_css_set_property (css, "opacity", os.str().c_str());
 
-    sp_desktop_set_style (SP_ACTIVE_DESKTOP, css);
+    sp_desktop_set_style (desktop, css);
 
     sp_repr_css_attr_unref (css);
 
-    sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "fillstroke:opacity", SP_VERB_DIALOG_FILL_STROKE,
+    sp_document_maybe_done (sp_desktop_document (desktop), "fillstroke:opacity", SP_VERB_DIALOG_FILL_STROKE,
                             _("Change opacity"));
 
     // resume interruptibility
-    sp_canvas_end_forced_full_redraws(sp_desktop_canvas(SP_ACTIVE_DESKTOP));
+    sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop));
 
     _blocked = false;
 }
@@ -264,10 +266,12 @@ FillAndStroke::selectionChanged(Inkscape::Application */*inkscape*/,
         return;
     _blocked = true;
 
+    SPDesktop *desktop = getDesktop();
+
     // create temporary style
-    SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT);
+    SPStyle *query = sp_style_new (sp_desktop_document(desktop));
     // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection
-    int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
+    int result = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_MASTEROPACITY);
 
     switch (result) {
         case QUERY_STYLE_NOTHING:
@@ -283,7 +287,7 @@ FillAndStroke::selectionChanged(Inkscape::Application */*inkscape*/,
     }
 
     //query now for current filter mode and average blurring of selection
-    const int blend_result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BLEND);
+    const int blend_result = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_BLEND);
     switch(blend_result) {
         case QUERY_STYLE_NOTHING:
             _fe_cb.set_sensitive(false);
@@ -300,7 +304,7 @@ FillAndStroke::selectionChanged(Inkscape::Application */*inkscape*/,
     }
 
     if(blend_result == QUERY_STYLE_SINGLE || blend_result == QUERY_STYLE_MULTIPLE_SAME) {
-        int blur_result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_BLUR);
+        int blur_result = sp_desktop_query_style (desktop, query, QUERY_STYLE_PROPERTY_BLUR);
         switch (blur_result) {
             case QUERY_STYLE_NOTHING: //no blurring
                 _fe_cb.set_blur_sensitive(false);
@@ -308,7 +312,7 @@ FillAndStroke::selectionChanged(Inkscape::Application */*inkscape*/,
             case QUERY_STYLE_SINGLE:
             case QUERY_STYLE_MULTIPLE_AVERAGED:
             case QUERY_STYLE_MULTIPLE_SAME:
-                NR::Maybe<NR::Rect> bbox = sp_desktop_selection(SP_ACTIVE_DESKTOP)->bounds();
+                NR::Maybe<NR::Rect> bbox = sp_desktop_selection(desktop)->bounds();
                 if (bbox) {
                     double perimeter = bbox->extent(NR::X) + bbox->extent(NR::Y);
                     _fe_cb.set_blur_sensitive(true);
index 721a9e27e792047327b94193229b650e859be584..98318455a57fef14defd02e512426d3a1eed19b5 100644 (file)
@@ -932,7 +932,7 @@ FilterEffectsDialog::FilterModifier::FilterModifier(FilterEffectsDialog& d)
     g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
                      G_CALLBACK(&FilterModifier::on_activate_desktop), this);
 
-    on_activate_desktop(INKSCAPE, SP_ACTIVE_DESKTOP, this);
+    on_activate_desktop(INKSCAPE, d.getDesktop(), this);
     update_filters();
 }
 
@@ -1024,7 +1024,7 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri
     Gtk::TreeIter iter = _model->get_iter(path);
 
     if(iter) {
-        SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+        SPDesktop *desktop = _dialog.getDesktop();
         SPDocument *doc = sp_desktop_document(desktop);
         SPFilter* filter = (*iter)[_columns.filter];
         Inkscape::Selection *sel = sp_desktop_selection(desktop);
@@ -1057,7 +1057,7 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri
    Keeps the same selection if possible, otherwise selects the first element */
 void FilterEffectsDialog::FilterModifier::update_filters()
 {
-    SPDesktop* desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop* desktop = _dialog.getDesktop();
     SPDocument* document = sp_desktop_document(desktop);
     const GSList* filters = sp_document_get_resource_list(document, "filter");
 
@@ -1112,7 +1112,7 @@ void FilterEffectsDialog::FilterModifier::filter_list_button_release(GdkEventBut
 
 void FilterEffectsDialog::FilterModifier::add_filter()
 {
-    SPDocument* doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
+    SPDocument* doc = sp_desktop_document(_dialog.getDesktop());
     SPFilter* filter = new_filter(doc);
 
     const int count = _model->children().size();
@@ -2007,7 +2007,7 @@ void FilterEffectsDialog::remove_primitive()
     if(prim) {
         sp_repr_unparent(prim->repr);
 
-        sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_FILTER_EFFECTS,
+        sp_document_done(sp_desktop_document(getDesktop()), SP_VERB_DIALOG_FILTER_EFFECTS,
                          _("Remove filter primitive"));
 
         _primitive_list.update();
index cfc1bfeb256da45dd1e0dffa90636a656c484625..3ff79a0d3b2e8efdeb556c9d3b3a42c95bb2dd06 100644 (file)
@@ -275,7 +275,7 @@ Find::filter_fields (GSList *l, bool exact)
 bool
 Find::item_type_match (SPItem *item)
 {
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
 
     if (SP_IS_RECT(item)) {
         return (_check_all_shapes.get_active() || _check_rects.get_active());
@@ -337,7 +337,7 @@ Find::filter_list (GSList *l, bool exact)
 GSList *
 Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked)
 {
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
 
     if (SP_IS_DEFS(r))
         return l; // we're not interested in items in defs
@@ -359,9 +359,9 @@ Find::all_items (SPObject *r, GSList *l, bool hidden, bool locked)
 GSList *
 Find::all_selection_items (Inkscape::Selection *s, GSList *l, SPObject *ancestor, bool hidden, bool locked)
 {
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
 
-   for (GSList *i = (GSList *) s->itemList(); i != NULL; i = i->next) {
+    for (GSList *i = (GSList *) s->itemList(); i != NULL; i = i->next) {
         if (SP_IS_ITEM (i->data) && !SP_OBJECT_IS_CLONED (i->data) && !desktop->isLayer(SP_ITEM(i->data))) {
             if (!ancestor || ancestor->isAncestorOf(SP_OBJECT (i->data))) {
                 if ((hidden || !desktop->itemIsHidden(SP_ITEM(i->data))) && (locked || !SP_ITEM(i->data)->isLocked())) {
@@ -398,7 +398,7 @@ Find::onClear()
 void
 Find::onFind()
 {   
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+    SPDesktop *desktop = getDesktop();
 
     bool hidden = _check_include_hidden.get_active();
     bool locked = _check_include_locked.get_active();
index 6ec078ce034ad940a313b642b1a70b838e9d7ba4..b1dfda573861272d7e91e45cd4e368687b27e493 100644 (file)
@@ -52,16 +52,6 @@ static void lpeeditor_selection_modified( Inkscape::Selection *selection, guint
 }
 
 
-static void lpeeditor_desktop_change(Inkscape::Application*, SPDesktop* desktop, void *data)
-{
-    if (!desktop) {
-        return;
-    }
-    LivePathEffectEditor* editor = reinterpret_cast<LivePathEffectEditor*>(data);
-    editor->setDesktop(desktop);
-}
-
-
 /*#######################
  * LivePathEffectEditor
  */
@@ -98,14 +88,6 @@ LivePathEffectEditor::LivePathEffectEditor()
     button_apply.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onApply));
     button_remove.signal_clicked().connect(sigc::mem_fun(*this, &LivePathEffectEditor::onRemove));
 
-    // connect callback functions to changes in selected desktop.
-    g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop",
-                       G_CALLBACK(lpeeditor_desktop_change), this);
-
-    g_signal_connect( G_OBJECT(INKSCAPE), "deactivate_desktop",
-                       G_CALLBACK(lpeeditor_desktop_change), this);
-
-    setDesktop(SP_ACTIVE_DESKTOP);
     show_all_children();
 
     button_remove.hide();
@@ -202,6 +184,7 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
 void 
 LivePathEffectEditor::setDesktop(SPDesktop *desktop)
 {
+    Panel::setDesktop(desktop);
 
     if ( desktop == current_desktop ) {
         return;
index 7416e96cc753c6543f1342efa623f35c0a1b7c17..4efc8862280cbbd35c3a72486f590854021218c0 100644 (file)
 # include <config.h>
 #endif
 
-#include "verbs.h"
+#include <gtkmm/stock.h>
 
+#include "verbs.h"
 #include "dialog.h"
 #include "dialogs/swatches.h"
-#include "ui/dialog/undo-history.h"
+#include "ui/dialog/floating-behavior.h"
+#include "ui/dialog/dock-behavior.h"
 #include "prefs-utils.h"
 
 namespace Inkscape {
 namespace UI {
 namespace Dialog {
 
+/* local desktop event handlers */
+static void handle_activate_desktop(Inkscape::Application *, SPDesktop *, void *);
+static void handle_deactivate_desktop(Inkscape::Application *, SPDesktop *, void *);
+
 struct PanelDialogBase {
     virtual void present() =0;
     virtual Panel &getPanel() =0;
     virtual ~PanelDialogBase() {}
+
+private:
+    virtual void _propagateDocumentReplaced(SPDesktop* desktop, SPDocument *document) =0;
+    virtual void _propagateDesktopActivated(Inkscape::Application *, SPDesktop *) =0;
+    virtual void _propagateDesktopDeactivated(Inkscape::Application *, SPDesktop *) =0;
+
+    friend void handle_activate_desktop(Inkscape::Application *, SPDesktop *, void *);
+    friend void handle_deactivate_desktop(Inkscape::Application *, SPDesktop *, void *);
 };
 
 template <typename Behavior>
@@ -50,14 +64,18 @@ public:
     Panel &getPanel() { return _panel; }
 
 private:
+    void _propagateDocumentReplaced(SPDesktop* desktop, SPDocument *document);
+    void _propagateDesktopActivated(Inkscape::Application *, SPDesktop *);
+    void _propagateDesktopDeactivated(Inkscape::Application *, SPDesktop *);
+
     Panel &_panel;
+    sigc::connection _document_replaced_connection;
 
     PanelDialog();  // no constructor without params
     PanelDialog(PanelDialog<Behavior> const &d);                      // no copy
     PanelDialog<Behavior>& operator=(PanelDialog<Behavior> const &d); // no assign
-};
-
 
+};
 
 template <typename B>
 PanelDialog<B>::PanelDialog(Panel &panel, char const *prefs_path, int const verb_num, Glib::ustring const &apply_label) :
@@ -70,6 +88,13 @@ PanelDialog<B>::PanelDialog(Panel &panel, char const *prefs_path, int const verb
 
     vbox->pack_start(_panel, true, true, 0);
 
+    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+
+    _propagateDesktopActivated(INKSCAPE, desktop);
+
+    _document_replaced_connection = 
+        desktop->connectDocumentReplaced(sigc::mem_fun(*this, &PanelDialog::_propagateDocumentReplaced));
+
     if (prefs_get_int_attribute ("dialogs", "showclose", 0) || !apply_label.empty()) {
         // TODO: make the order of buttons obey the global preference
         if (!apply_label.empty()) {
@@ -87,8 +112,26 @@ PanelDialog<B> *
 PanelDialog<B>::create()
 {
     Panel &panel = P::getInstance();
-    return new PanelDialog<B>(panel, panel.getPrefsPath(), 
-                              panel.getVerb(), panel.getApplyLabel());
+    return new PanelDialog<B>(panel, panel.getPrefsPath(), panel.getVerb(), panel.getApplyLabel());
+}
+
+/** 
+ * Specialize factory method for panel dialogs with floating behavior in order to make them work as
+ * singletons, i.e. allow them track the current active desktop.
+ */
+template <> template <typename P>
+PanelDialog<Behavior::FloatingBehavior> *
+PanelDialog<Behavior::FloatingBehavior>::create()
+{
+    Panel &panel = P::getInstance();
+    PanelDialog<Behavior::FloatingBehavior> *instance = 
+        new PanelDialog<Behavior::FloatingBehavior>(panel, panel.getPrefsPath(), 
+                                                    panel.getVerb(), panel.getApplyLabel());
+
+    g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(handle_activate_desktop), instance);
+    g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop", G_CALLBACK(handle_deactivate_desktop), instance);
+
+    return instance;
 }
 
 template <typename B>
@@ -98,6 +141,45 @@ PanelDialog<B>::present()
     Dialog::present();
 }
 
+template <typename B>
+void
+PanelDialog<B>::_propagateDocumentReplaced(SPDesktop *desktop, SPDocument *document)
+{
+    _panel.signalDocumentReplaced().emit(desktop, document);
+}
+
+template <typename B>
+void
+PanelDialog<B>::_propagateDesktopActivated(Inkscape::Application *application, SPDesktop *desktop)
+{
+    _document_replaced_connection = 
+        desktop->connectDocumentReplaced(sigc::mem_fun(*this, &PanelDialog::_propagateDocumentReplaced));
+    _panel.signalActivateDesktop().emit(application, desktop);
+}
+
+template <typename B>
+void
+PanelDialog<B>::_propagateDesktopDeactivated(Inkscape::Application *application, SPDesktop *desktop)
+{
+    _document_replaced_connection.disconnect();
+    _panel.signalDeactiveDesktop().emit(application, desktop);
+}
+
+
+static void
+handle_activate_desktop(Inkscape::Application *application, SPDesktop *desktop, void *data)
+{
+    g_return_if_fail(data != NULL);
+    static_cast<PanelDialogBase *>(data)->_propagateDesktopActivated(application, desktop);
+}
+
+static void
+handle_deactivate_desktop(Inkscape::Application *application, SPDesktop *desktop, void *data)
+{
+    g_return_if_fail(data != NULL);
+    static_cast<PanelDialogBase *>(data)->_propagateDesktopDeactivated(application, desktop);
+}
+
 } // namespace Dialog
 } // namespace UI
 } // namespace Inkscape
index 921d71bb8c5c8063770c1071d1972d1300aa6119..b378c0b5a96500a7cff365b687094ea387c7c171 100644 (file)
@@ -50,7 +50,7 @@ SessionPlaybackDialog::create()
 SessionPlaybackDialogImpl::SessionPlaybackDialogImpl() 
        : _delay(100, 1, 5000, 10, 100), _delayentry(_delay)
 {
-       this->_desktop = SP_ACTIVE_DESKTOP;
+        this->_desktop = this->getDesktop();
        this->_sm = this->_desktop->whiteboard_session_manager();
        this->_sfp = this->_sm->session_player();
        this->_openfile.set_text(this->_sfp->filename());
index 9e6cd7f50f3dae59ceedf0cfa4569f95b89d6a1b..387510b361473ae64f689d3f17e52d6db555d514 100644 (file)
@@ -446,7 +446,7 @@ void
 Transformation::onSwitchPage(GtkNotebookPage */*page*/,
                                    guint pagenum)
 {
-    updateSelection((PageType)pagenum, sp_desktop_selection(SP_ACTIVE_DESKTOP));
+    updateSelection((PageType)pagenum, sp_desktop_selection(getDesktop()));
 }
 
 void
index b808e57dee7076d7bcdba25d20f26b418eafef88..c53583741f5b13613ac515316c94613cc87ecaec 100644 (file)
@@ -22,6 +22,7 @@
 #include "inkscape.h"
 #include "ui/icons.h"
 #include "verbs.h"
+#include "desktop-handles.h"
 
 #include "undo-history.h"
 
@@ -95,27 +96,19 @@ CellRendererInt::render_vfunc(const Glib::RefPtr<Gdk::Drawable>& window,
 
 const CellRendererInt::Filter& CellRendererInt::no_filter = CellRendererInt::NoFilter();
 
-static UndoHistory *_instance = 0;
-
-/* local desktop event handlers */
-static void on_document_replaced(SPDesktop* desktop, SPDocument*);
-static void on_activate_desktop(Inkscape::Application*, SPDesktop* desktop, void*);
-static void on_deactivate_desktop(Inkscape::Application*, SPDesktop* desktop, void*);
-
 UndoHistory& UndoHistory::getInstance()
 {
-    if (!_instance)
-        _instance = new UndoHistory();
-
-    return *_instance;
+    return *new UndoHistory();
 }
 
 void
 UndoHistory::setDesktop(SPDesktop* desktop)
 {
-    if (!desktop || !SP_ACTIVE_DOCUMENT) return;
+    Panel::setDesktop(desktop);
 
-    _document = SP_ACTIVE_DOCUMENT;
+    if (!desktop) return;
+
+    _document = sp_desktop_document(desktop);
 
     _event_log = desktop->event_log;
 
@@ -133,9 +126,8 @@ UndoHistory::setDesktop(SPDesktop* desktop)
 
 UndoHistory::UndoHistory()
     : UI::Widget::Panel ("", "dialogs.undo-history", SP_VERB_DIALOG_UNDO_HISTORY),
-      _desktop (SP_ACTIVE_DESKTOP),
-      _document (SP_ACTIVE_DOCUMENT),
-      _event_log (_desktop ? _desktop->event_log : NULL),
+      _document (sp_desktop_document(getDesktop())),
+      _event_log (getDesktop() ? getDesktop()->event_log : NULL),
       _columns (_event_log ? &_event_log->getColumns() : NULL),
       _event_list_selection (_event_list_view.get_selection())
 {
@@ -181,11 +173,6 @@ UndoHistory::UndoHistory()
 
     _scrolled_window.add(_event_list_view);
 
-    // connect desktop event callbacks
-    _document_replaced_connection = _desktop->connectDocumentReplaced(sigc::ptr_fun(on_document_replaced));
-    g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK(on_activate_desktop), 0);
-    g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop", G_CALLBACK(on_deactivate_desktop), 0);
-
     // connect EventLog callbacks
     _callback_connections[EventLog::CALLB_SELECTION_CHANGE] =
         _event_list_selection->signal_changed().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::UndoHistory::_onListSelectionChange));
@@ -317,8 +304,7 @@ UndoHistory::_onListSelectionChange()
 void
 UndoHistory::_onExpandEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &/*path*/)
 {
-    if ( iter == _event_list_selection->get_selected() )
-    {
+    if ( iter == _event_list_selection->get_selected() ) {
         _event_list_selection->select(_event_log->getCurrEvent());
     }
 }
@@ -327,8 +313,7 @@ void
 UndoHistory::_onCollapseEvent(const Gtk::TreeModel::iterator &iter, const Gtk::TreeModel::Path &/*path*/)
 {
     // Collapsing a branch we're currently in is equal to stepping to the last event in that branch
-    if ( iter == _event_log->getCurrEvent() )
-    {
+    if ( iter == _event_log->getCurrEvent() ) {
         EventLog::const_iterator curr_event_parent = _event_log->getCurrEvent();
         EventLog::const_iterator curr_event = curr_event_parent->children().begin();
         EventLog::const_iterator last = curr_event_parent->children().end();
@@ -349,33 +334,6 @@ UndoHistory::_onCollapseEvent(const Gtk::TreeModel::iterator &iter, const Gtk::T
 
 const CellRendererInt::Filter& UndoHistory::greater_than_1 = UndoHistory::GreaterThan(1);
 
-static void
-on_activate_desktop(Inkscape::Application*, SPDesktop* desktop, void*)
-{
-    if (!_instance) return;
-
-    _instance->_document_replaced_connection =
-        SP_ACTIVE_DESKTOP->connectDocumentReplaced(sigc::ptr_fun(on_document_replaced));
-
-    _instance->setDesktop(desktop);
-}
-
-static void
-on_deactivate_desktop(Inkscape::Application*, SPDesktop* /*desktop*/, void*)
-{
-    if (!_instance) return;
-
-    _instance->_document_replaced_connection.disconnect();
-}
-
-static void
-on_document_replaced(SPDesktop* desktop, SPDocument*)
-{
-    if (!_instance) return;
-
-    _instance->setDesktop(desktop);
-}
-
 } // namespace Dialog
 } // namespace UI
 } // namespace Inkscape
index e883ec49c546b3150496d50cbd08b19d4b3ded91..070a1eb22b77e332c1970749271ee063cb9e967b 100644 (file)
@@ -127,7 +127,6 @@ public:
 
 protected:
 
-    SPDesktop *_desktop;
     SPDocument *_document;
     EventLog *_event_log;
 
index 87bd9994467f961c853f8c8ad1212ee0ccb93597..ae291c03d74aa09e9a17662a4448e42c2899285c 100644 (file)
@@ -62,9 +62,8 @@ void WhiteboardConnectDialogImpl::present()
 void
 WhiteboardConnectDialogImpl::setSessionManager()
 {
-       this->_desktop = SP_ACTIVE_DESKTOP;
-       this->_sm = SP_ACTIVE_DESKTOP->whiteboard_session_manager();
-
+       this->_desktop = this->getDesktop();
+       this->_sm = this->_desktop->whiteboard_session_manager();
 }
 
 void
index 8d33328bab90c510852869b809b063f02ae03144..b2b913de06e3981bc0dff34a23c6c032597e8130 100644 (file)
@@ -60,8 +60,8 @@ WhiteboardShareWithChatroomDialogImpl::~WhiteboardShareWithChatroomDialogImpl()
 void
 WhiteboardShareWithChatroomDialogImpl::setSessionManager()
 {
-       this->_desktop = SP_ACTIVE_DESKTOP;
-       this->_sm = SP_ACTIVE_DESKTOP->whiteboard_session_manager();
+        this->_desktop = this->getDesktop();
+       this->_sm = this->_desktop->whiteboard_session_manager();
 
 }
 
index ea7720f7dd7827e86461841c0951e727ba490fe6..ebe91f0f3289b25bc95743cb28f91a532858544e 100644 (file)
@@ -61,8 +61,8 @@ WhiteboardShareWithUserDialogImpl::~WhiteboardShareWithUserDialogImpl()
 void
 WhiteboardShareWithUserDialogImpl::setSessionManager()
 {
-       this->_desktop = SP_ACTIVE_DESKTOP;
-       this->_sm = SP_ACTIVE_DESKTOP->whiteboard_session_manager();
+        this->_desktop = this->getDesktop();
+       this->_sm = this->_desktop->whiteboard_session_manager();
 
 }
 
index cad344e63f8fdaa44a3b8290068a1c8ed8d9eb64..a591e76640acd8ec51b69f63d4c79327079483c9 100644 (file)
@@ -4,9 +4,11 @@
  * Authors:
  *   Bryce Harrington <bryce@bryceharrington.org>
  *   Jon A. Cruz <jon@joncruz.org>
+ *   Gustav Broberg <broberg@kth.se>
  *
  * Copyright (C) 2004 Bryce Harrington
  * Copyright (C) 2005 Jon A. Cruz
+ * Copyright (C) 2007 Gustav Broberg
  *
  * Released under GNU GPL.  Read the file 'COPYING' for more information
  */
@@ -44,6 +46,7 @@ Panel::Panel(Glib::ustring const &label, gchar const *prefs_path,
              bool menu_desired) :
     _prefs_path(prefs_path),
     _menu_desired(menu_desired),
+    _desktop(SP_ACTIVE_DESKTOP),
     _label(label),
     _apply_label(apply_label),
     _verb_num(verb_num),
@@ -181,6 +184,8 @@ void Panel::_init()
 
     signalResponse().connect(sigc::mem_fun(*this, &Panel::_handleResponse));
 
+    signalActivateDesktop().connect(sigc::hide<0>(sigc::mem_fun(*this, &Panel::setDesktop)));
+
     show_all_children();
 
     _bounceCall(PANEL_SETTING_SIZE, panel_size);
@@ -383,6 +388,11 @@ Glib::ustring const &Panel::getApplyLabel() const
     return _apply_label;
 }
 
+void Panel::setDesktop(SPDesktop *desktop)
+{
+    _desktop = desktop;
+}
+
 void Panel::_setTargetFillable(PreviewFillable *target)
 {
     _fillable = target;
@@ -461,6 +471,24 @@ Panel::setResponseSensitive(int response_id, bool setting)
         _response_map[response_id]->set_sensitive(setting);
 }
 
+sigc::signal<void, SPDesktop *, SPDocument *> &
+Panel::signalDocumentReplaced()
+{
+    return _signal_document_replaced;
+}
+
+sigc::signal<void, Inkscape::Application *, SPDesktop *> &
+Panel::signalActivateDesktop()
+{
+    return _signal_activate_desktop;
+}
+
+sigc::signal<void, Inkscape::Application *, SPDesktop *> &
+Panel::signalDeactiveDesktop()
+{
+    return _signal_deactive_desktop;
+}
+
 void
 Panel::_handleResponse(int response_id)
 {
@@ -474,7 +502,7 @@ Panel::_handleResponse(int response_id)
 
 Inkscape::Selection *Panel::_getSelection()
 {
-    return sp_desktop_selection(SP_ACTIVE_DESKTOP);
+    return sp_desktop_selection(_desktop);
 }
 
 } // namespace Widget
index 10f74cf2b3f571eed61c3db0916faf93740bbce5..40760a4a2658e431d16b855cdc128690d6b1649a 100644 (file)
@@ -27,6 +27,7 @@
 #include <gtkmm/table.h>
 #include <gtkmm/tooltips.h>
 
+#include "inkscape.h"
 #include "ui/previewfillable.h"
 #include "selection.h"
 
@@ -54,6 +55,9 @@ public:
 
     void restorePanelPrefs();
 
+    virtual void setDesktop(SPDesktop *desktop);
+    SPDesktop *getDesktop() { return _desktop; }
+    
     /** Signal accessors */
     virtual sigc::signal<void, int> &signalResponse();
     virtual sigc::signal<void> &signalPresent();
@@ -65,6 +69,10 @@ public:
     void setDefaultResponse(int response_id);
     void setResponseSensitive(int response_id, bool setting);
 
+    virtual sigc::signal<void, SPDesktop *, SPDocument *> &signalDocumentReplaced();
+    virtual sigc::signal<void, Inkscape::Application *, SPDesktop *> &signalActivateDesktop();
+    virtual sigc::signal<void, Inkscape::Application *, SPDesktop *> &signalDeactiveDesktop();
+
 protected:
     Gtk::Box *_getContents() { return &_contents; }
     void _setTargetFillable(PreviewFillable *target);
@@ -90,6 +98,9 @@ protected:
     /** Signals */
     sigc::signal<void, int> _signal_response;
     sigc::signal<void>      _signal_present;
+    sigc::signal<void, SPDesktop *, SPDocument *> _signal_document_replaced;
+    sigc::signal<void, Inkscape::Application *, SPDesktop *> _signal_activate_desktop;
+    sigc::signal<void, Inkscape::Application *, SPDesktop *> _signal_deactive_desktop;
 
 private:
     void _init();
@@ -98,6 +109,8 @@ private:
     void _popper(GdkEventButton *btn);
     void _wrapToggled(Gtk::CheckMenuItem *toggler);
 
+    SPDesktop       *_desktop;
+
     Glib::ustring    _label;
     Glib::ustring    _apply_label;
     int              _verb_num;