From: gustav_b Date: Fri, 7 Dec 2007 01:41:04 +0000 (+0000) Subject: Rework dialog management. Use singleton behavior for dialogs when X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1e7c268648bcbae15fc13b8c94dee677b401d9b3;p=inkscape.git Rework dialog management. Use singleton behavior for dialogs when 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. --- diff --git a/src/desktop.cpp b/src/desktop.cpp index 7cc77cbab..d31babf87 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -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); diff --git a/src/dialogs/extensions.cpp b/src/dialogs/extensions.cpp index 36ec67744..e363df607 100644 --- a/src/dialogs/extensions.cpp +++ b/src/dialogs/extensions.cpp @@ -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; } diff --git a/src/dialogs/extensions.h b/src/dialogs/extensions.h index f4dbada9e..e253ab849 100644 --- a/src/dialogs/extensions.h +++ b/src/dialogs/extensions.h @@ -34,7 +34,7 @@ class ExtensionsPanel : public Inkscape::UI::Widget::Panel public: ExtensionsPanel(); - static ExtensionsPanel& getInstance(); + 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(); diff --git a/src/dialogs/iconpreview.cpp b/src/dialogs/iconpreview.cpp index c36414705..e61b7d7f9 100644 --- a/src/dialogs/iconpreview.cpp +++ b/src/dialogs/iconpreview.cpp @@ -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() ) diff --git a/src/dialogs/iconpreview.h b/src/dialogs/iconpreview.h index 0f34dda4e..3a3652334 100644 --- a/src/dialogs/iconpreview.h +++ b/src/dialogs/iconpreview.h @@ -53,8 +53,6 @@ private: void renderPreview( SPObject* obj ); void updateMagnify(); - static IconPreviewPanel* instance; - Gtk::Tooltips tips; Gtk::VBox iconBox; diff --git a/src/dialogs/layers-panel.cpp b/src/dialogs/layers-panel.cpp index ff18c82b4..36105c41c 100644 --- a/src/dialogs/layers-panel.cpp +++ b/src/dialogs/layers-panel.cpp @@ -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(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 ); diff --git a/src/dialogs/layers-panel.h b/src/dialogs/layers-panel.h index 981d32027..7f56b3f7e 100644 --- a/src/dialogs/layers-panel.h +++ b/src/dialogs/layers-panel.h @@ -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 ); diff --git a/src/dialogs/swatches.cpp b/src/dialogs/swatches.cpp index 829b06cb6..e4cf9e926 100644 --- a/src/dialogs/swatches.cpp +++ b/src/dialogs/swatches.cpp @@ -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(); } diff --git a/src/dialogs/tiledialog.cpp b/src/dialogs/tiledialog.cpp index 4a60d4413..3ea423b5b 100644 --- a/src/dialogs/tiledialog.cpp +++ b/src/dialogs/tiledialog.cpp @@ -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; diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 7b616fe18..655a9428e 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -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")); } } diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index f8c07cf53..17215ac00 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -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. */ diff --git a/src/ui/dialog/dialog-manager.h b/src/ui/dialog/dialog-manager.h index cf5a23712..80070f19c 100644 --- a/src/ui/dialog/dialog-manager.h +++ b/src/ui/dialog/dialog-manager.h @@ -29,6 +29,8 @@ public: DialogManager(); virtual ~DialogManager(); + static DialogManager &getInstance(); + sigc::signal show_dialogs; sigc::signal show_f12; sigc::signal hide_dialogs; diff --git a/src/ui/dialog/document-metadata.cpp b/src/ui/dialog/document-metadata.cpp index 5671e08fe..5956cfb9b 100644 --- a/src/ui/dialog/document-metadata.cpp +++ b/src/ui/dialog/document-metadata.cpp @@ -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(data)) + dialog->update(); } - } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/document-metadata.h b/src/ui/dialog/document-metadata.h index 7ee2ee216..1b5c08ce1 100644 --- a/src/ui/dialog/document-metadata.h +++ b/src/ui/dialog/document-metadata.h @@ -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; diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index aa608703a..8d7b6ac52 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -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(_("Creation")); @@ -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(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(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(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) { diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index e80978ccc..a6fe48ffa 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -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; diff --git a/src/ui/dialog/fill-and-stroke.cpp b/src/ui/dialog/fill-and-stroke.cpp index 4f32d3d91..ab25f5bb3 100644 --- a/src/ui/dialog/fill-and-stroke.cpp +++ b/src/ui/dialog/fill-and-stroke.cpp @@ -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 bbox = sp_desktop_selection(SP_ACTIVE_DESKTOP)->bounds(); + NR::Maybe bbox = sp_desktop_selection(desktop)->bounds(); if (bbox) { double perimeter = bbox->extent(NR::X) + bbox->extent(NR::Y); _fe_cb.set_blur_sensitive(true); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index 721a9e27e..98318455a 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -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(); diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index cfc1bfeb2..3ff79a0d3 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -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(); diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index 6ec078ce0..b1dfda573 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -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(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; diff --git a/src/ui/dialog/panel-dialog.h b/src/ui/dialog/panel-dialog.h index 7416e96cc..4efc88622 100644 --- a/src/ui/dialog/panel-dialog.h +++ b/src/ui/dialog/panel-dialog.h @@ -16,21 +16,35 @@ # include #endif -#include "verbs.h" +#include +#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 @@ -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 const &d); // no copy PanelDialog& operator=(PanelDialog const &d); // no assign -}; - +}; template PanelDialog::PanelDialog(Panel &panel, char const *prefs_path, int const verb_num, Glib::ustring const &apply_label) : @@ -70,6 +88,13 @@ PanelDialog::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 * PanelDialog::create() { Panel &panel = P::getInstance(); - return new PanelDialog(panel, panel.getPrefsPath(), - panel.getVerb(), panel.getApplyLabel()); + return new PanelDialog(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 +PanelDialog * +PanelDialog::create() +{ + Panel &panel = P::getInstance(); + PanelDialog *instance = + new PanelDialog(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 @@ -98,6 +141,45 @@ PanelDialog::present() Dialog::present(); } +template +void +PanelDialog::_propagateDocumentReplaced(SPDesktop *desktop, SPDocument *document) +{ + _panel.signalDocumentReplaced().emit(desktop, document); +} + +template +void +PanelDialog::_propagateDesktopActivated(Inkscape::Application *application, SPDesktop *desktop) +{ + _document_replaced_connection = + desktop->connectDocumentReplaced(sigc::mem_fun(*this, &PanelDialog::_propagateDocumentReplaced)); + _panel.signalActivateDesktop().emit(application, desktop); +} + +template +void +PanelDialog::_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(data)->_propagateDesktopActivated(application, desktop); +} + +static void +handle_deactivate_desktop(Inkscape::Application *application, SPDesktop *desktop, void *data) +{ + g_return_if_fail(data != NULL); + static_cast(data)->_propagateDesktopDeactivated(application, desktop); +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/session-player.cpp b/src/ui/dialog/session-player.cpp index 921d71bb8..b378c0b5a 100644 --- a/src/ui/dialog/session-player.cpp +++ b/src/ui/dialog/session-player.cpp @@ -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()); diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index 9e6cd7f50..387510b36 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -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 diff --git a/src/ui/dialog/undo-history.cpp b/src/ui/dialog/undo-history.cpp index b808e57de..c53583741 100644 --- a/src/ui/dialog/undo-history.cpp +++ b/src/ui/dialog/undo-history.cpp @@ -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& 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 diff --git a/src/ui/dialog/undo-history.h b/src/ui/dialog/undo-history.h index e883ec49c..070a1eb22 100644 --- a/src/ui/dialog/undo-history.h +++ b/src/ui/dialog/undo-history.h @@ -127,7 +127,6 @@ public: protected: - SPDesktop *_desktop; SPDocument *_document; EventLog *_event_log; diff --git a/src/ui/dialog/whiteboard-connect.cpp b/src/ui/dialog/whiteboard-connect.cpp index 87bd99944..ae291c03d 100644 --- a/src/ui/dialog/whiteboard-connect.cpp +++ b/src/ui/dialog/whiteboard-connect.cpp @@ -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 diff --git a/src/ui/dialog/whiteboard-sharewithchat.cpp b/src/ui/dialog/whiteboard-sharewithchat.cpp index 8d33328ba..b2b913de0 100644 --- a/src/ui/dialog/whiteboard-sharewithchat.cpp +++ b/src/ui/dialog/whiteboard-sharewithchat.cpp @@ -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(); } diff --git a/src/ui/dialog/whiteboard-sharewithuser.cpp b/src/ui/dialog/whiteboard-sharewithuser.cpp index ea7720f7d..ebe91f0f3 100644 --- a/src/ui/dialog/whiteboard-sharewithuser.cpp +++ b/src/ui/dialog/whiteboard-sharewithuser.cpp @@ -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(); } diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp index cad344e63..a591e7664 100644 --- a/src/ui/widget/panel.cpp +++ b/src/ui/widget/panel.cpp @@ -4,9 +4,11 @@ * Authors: * Bryce Harrington * Jon A. Cruz + * Gustav Broberg * * 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 & +Panel::signalDocumentReplaced() +{ + return _signal_document_replaced; +} + +sigc::signal & +Panel::signalActivateDesktop() +{ + return _signal_activate_desktop; +} + +sigc::signal & +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 diff --git a/src/ui/widget/panel.h b/src/ui/widget/panel.h index 10f74cf2b..40760a4a2 100644 --- a/src/ui/widget/panel.h +++ b/src/ui/widget/panel.h @@ -27,6 +27,7 @@ #include #include +#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 &signalResponse(); virtual sigc::signal &signalPresent(); @@ -65,6 +69,10 @@ public: void setDefaultResponse(int response_id); void setResponseSensitive(int response_id, bool setting); + virtual sigc::signal &signalDocumentReplaced(); + virtual sigc::signal &signalActivateDesktop(); + virtual sigc::signal &signalDeactiveDesktop(); + protected: Gtk::Box *_getContents() { return &_contents; } void _setTargetFillable(PreviewFillable *target); @@ -90,6 +98,9 @@ protected: /** Signals */ sigc::signal _signal_response; sigc::signal _signal_present; + sigc::signal _signal_document_replaced; + sigc::signal _signal_activate_desktop; + sigc::signal _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;