diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2017-02-27 13:55:09 +0000 |
|---|---|---|
| committer | tavmjong-free <tavmjong@free.fr> | 2017-02-27 13:55:09 +0000 |
| commit | c6ec9680ac0320a038c0eb1d3776faad9dfc2af5 (patch) | |
| tree | 63c98bc42e0476cf916902887e4a199a5109b6ca /src | |
| parent | Fix desktop/document tracking. (diff) | |
| download | inkscape-c6ec9680ac0320a038c0eb1d3776faad9dfc2af5.tar.gz inkscape-c6ec9680ac0320a038c0eb1d3776faad9dfc2af5.zip | |
Add a very simple prototype dialog as an example and test of deriving from Panel.
To be disabled for releases.
(bzr r15551)
Diffstat (limited to 'src')
| -rw-r--r-- | src/menus-skeleton.h | 1 | ||||
| -rw-r--r-- | src/ui/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/ui/dialog/dialog-manager.cpp | 3 | ||||
| -rw-r--r-- | src/ui/dialog/prototype.cpp | 167 | ||||
| -rw-r--r-- | src/ui/dialog/prototype.h | 80 | ||||
| -rw-r--r-- | src/verbs.cpp | 5 | ||||
| -rw-r--r-- | src/verbs.h | 1 |
7 files changed, 259 insertions, 0 deletions
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index 39bcf0c20..7d00ffa86 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -225,6 +225,7 @@ static char const menus_skeleton[] = " <verb verb-id=\"DialogTransform\" />\n" " <verb verb-id=\"DialogAlignDistribute\" />\n" " <verb verb-id=\"DialogArrange\" />\n" +" <verb verb-id=\"DialogPrototype\" />\n" " </submenu>\n" " <submenu name=\"" N_("_Path") "\">\n" " <verb verb-id=\"ObjectToPath\" />\n" diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 11a0c351f..259a06013 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -99,6 +99,7 @@ set(ui_SRC dialog/polar-arrange-tab.cpp dialog/print-colors-preview-dialog.cpp dialog/print.cpp + dialog/prototype.cpp dialog/spellcheck.cpp dialog/styledialog.cpp dialog/svg-fonts-dialog.cpp @@ -241,6 +242,7 @@ set(ui_SRC dialog/polar-arrange-tab.h dialog/print-colors-preview-dialog.h dialog/print.h + dialog/prototype.h dialog/spellcheck.h dialog/styledialog.h dialog/svg-fonts-dialog.h diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index b407f8200..01cd9dd0f 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -19,6 +19,7 @@ #include "ui/dialog/dialog-manager.h" +#include "ui/dialog/prototype.h" #include "ui/dialog/align-and-distribute.h" #include "ui/dialog/document-metadata.h" #include "ui/dialog/document-properties.h" @@ -105,6 +106,7 @@ DialogManager::DialogManager() { registerFactory("InkscapePreferences", &create<InkscapePreferences, FloatingBehavior>); if (dialogs_type == FLOATING) { + registerFactory("Prototype", &create<Prototype, FloatingBehavior>); registerFactory("AlignAndDistribute", &create<AlignAndDistribute, FloatingBehavior>); registerFactory("DocumentMetadata", &create<DocumentMetadata, FloatingBehavior>); registerFactory("DocumentProperties", &create<DocumentProperties, FloatingBehavior>); @@ -146,6 +148,7 @@ DialogManager::DialogManager() { } else { + registerFactory("Prototype", &create<Prototype, DockBehavior>); registerFactory("AlignAndDistribute", &create<AlignAndDistribute, DockBehavior>); registerFactory("DocumentMetadata", &create<DocumentMetadata, DockBehavior>); registerFactory("DocumentProperties", &create<DocumentProperties, DockBehavior>); diff --git a/src/ui/dialog/prototype.cpp b/src/ui/dialog/prototype.cpp new file mode 100644 index 000000000..4d7492c18 --- /dev/null +++ b/src/ui/dialog/prototype.cpp @@ -0,0 +1,167 @@ +/* + * A bare minimum example of deriving from Inkscape::UI:Widget::Panel. + * + * Author: + * Tavmjong Bah + * + * Copyright (C) Tavmjong Bah <tavmjong@free.fr> + * + * Released under the GNU GPL, read the file 'COPYING' for more information. + */ + +#include "ui/dialog/prototype.h" +#include "verbs.h" +#include "desktop.h" +#include "document.h" +#include "selection.h" + +// Only for use in demonstration widget. +#include "sp-root.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +Prototype::Prototype() : + // UI::Widget::Panel("Prototype Label", "/dialogs/prototype", SP_VERB_DIALOG_PROTOTYPE, + // "Prototype Apply Label", true), + UI::Widget::Panel("Prototype Label", "/dialogs/prototype", SP_VERB_DIALOG_PROTOTYPE), + + desktopTracker() //, + // desktopChangedConnection() +{ + std::cout << "Prototype::Prototype()" << std::endl; + + // A widget for demonstration that displays the current SVG's id. + _getContents()->pack_start(label); // Panel::_getContents() + + // desktop is set by Panel constructor so this should never be NULL. + // Note, we need to use getDesktop() since _desktop is private in Panel.h. + // It should probably be protected instead... but need to verify in doesn't break anything. + if (getDesktop() == NULL) { + std::cerr << "Prototype::Prototype: desktop is NULL!" << std::endl; + } + + desktopChangedConnection = desktopTracker.connectDesktopChanged( + sigc::mem_fun(*this, &Prototype::handleDesktopChanged) ); + desktopTracker.connect(GTK_WIDGET(gobj())); + + documentReplacedConnection = getDesktop()->connectDocumentReplaced( + sigc::mem_fun(this, &Prototype::handleDocumentReplaced)); + + selectionChangedConnection = getDesktop()->getSelection()->connectChanged( + sigc::hide(sigc::mem_fun(this, &Prototype::handleSelectionChanged))); + + updateLabel(); +} + +Prototype::~Prototype() +{ + // Never actually called. + std::cout << "Prototype::~Prototype()" << std::endl; + desktopChangedConnection.disconnect(); + documentReplacedConnection.disconnect(); + selectionChangedConnection.disconnect(); +} + +/* + * Called when a dialog is displayed, including when a dialog is reopened. + * (When a dialog is closed, it is not destroyed so the contructor is not called. + * This function can handle any reinitialization needed.) + */ +void +Prototype::present() +{ + std::cout << "Prototype::present()" << std::endl; + UI::Widget::Panel::present(); +} + +/* + * When Inkscape is first opened, a default document is shown. If another document is immediately + * opened, it will replace the default document in the same desktop. This function handles the + * change. Bug: This is called twice for some reason. + */ +void +Prototype::handleDocumentReplaced(SPDesktop *desktop, SPDocument * /* document */) +{ + std::cout << "Prototype::handleDocumentReplaced()" << std::endl; + if (getDesktop() != desktop) { + std::cerr << "Prototype::handleDocumentReplaced(): Error: panel desktop not equal to existing desktop!" << std::endl; + } + + selectionChangedConnection.disconnect(); + + selectionChangedConnection = desktop->getSelection()->connectChanged( + sigc::hide(sigc::mem_fun(this, &Prototype::handleSelectionChanged))); + + // Update demonstration widget. + updateLabel(); +} + +/* + * When a dialog is floating, it is connected to the active desktop. + */ +void +Prototype::handleDesktopChanged(SPDesktop* desktop) { + std::cout << "Prototype::handleDesktopChanged(): " << desktop << std::endl; + + if (getDesktop() == desktop) { + // This will happen after construction of Prototype. We've already + // set up signals so just return. + std::cout << " getDesktop() == desktop" << std::endl; + return; + } + + // Need to either remove return above or connect these in constructor. + // We've choosen the later. + selectionChangedConnection.disconnect(); + documentReplacedConnection.disconnect(); + + setDesktop( desktop ); + + selectionChangedConnection = desktop->getSelection()->connectChanged( + sigc::hide(sigc::mem_fun(this, &Prototype::handleSelectionChanged))); + documentReplacedConnection = desktop->connectDocumentReplaced( + sigc::mem_fun(this, &Prototype::handleDocumentReplaced)); + + // Update demonstration widget. + updateLabel(); +} + +/* + * Handle a change in which objects are selected in a document. + */ +void +Prototype::handleSelectionChanged() { + std::cout << "Prototype::handleSelectionChanged()" << std::endl; + + // Update demonstration widget. + label.set_label("Selection Changed!"); +} + +/* + * Update label... just a utility function for this example. + */ +void +Prototype::updateLabel() { + + const gchar* root_id = getDesktop()->getDocument()->getRoot()->getId(); + Glib::ustring label_string("Document's SVG id: "); + label_string += (root_id?root_id:"null"); + label.set_label(label_string); +} + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/ui/dialog/prototype.h b/src/ui/dialog/prototype.h new file mode 100644 index 000000000..65522c41f --- /dev/null +++ b/src/ui/dialog/prototype.h @@ -0,0 +1,80 @@ +/* + * A bare minimum example of deriving from Inkscape::UI:Widget::Panel. + * + * Author: + * Tavmjong Bah + * + * Copyright (C) Tavmjong Bah <tavmjong@free.fr> + * + * Released under the GNU GPL, read the file 'COPYING' for more information. + */ + +#ifndef SEEN_PROTOTYPE_PANEL_H +#define SEEN_PROTOTYPE_PANEL_H + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <iostream> +#include "ui/widget/panel.h" +#include "ui/dialog/desktop-tracker.h" + +// Only to display status. +#include <gtkmm/label.h> + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * A panel that does almost nothing! + */ +class Prototype : public UI::Widget::Panel +{ +public: + virtual ~Prototype(); + + static Prototype& getInstance() { return *new Prototype(); }; + + virtual void present(); + +private: + + // No default constructor, noncopyable, nonassignable + Prototype(); + Prototype(Prototype const &d); + Prototype operator=(Prototype const &d); + + // Signals and handlers + sigc::connection documentReplacedConnection; + sigc::connection desktopChangedConnection; + sigc::connection selectionChangedConnection; + + void handleDocumentReplaced(SPDesktop* desktop, SPDocument *document); + void handleDesktopChanged(SPDesktop* desktop); + void handleSelectionChanged(); + + DesktopTracker desktopTracker; + + // Just for example + Gtk::Label label; + void updateLabel(); +}; + +} //namespace Dialogs +} //namespace UI +} //namespace Inkscape + +#endif // SEEN_PROTOTYPE_PANEL_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/verbs.cpp b/src/verbs.cpp index fce823408..d67e68392 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2058,6 +2058,9 @@ void DialogVerb::perform(SPAction *action, void *data) g_assert(dt->_dlg_mgr != NULL); switch (reinterpret_cast<std::size_t>(data)) { + case SP_VERB_DIALOG_PROTOTYPE: + dt->_dlg_mgr->showDialog("Prototype"); + break; case SP_VERB_DIALOG_DISPLAY: //sp_display_dialog(); dt->_dlg_mgr->showDialog("InkscapePreferences"); @@ -2956,6 +2959,8 @@ Verb *Verb::_base_verbs[] = { N_("Zoom to fit selection in window"), INKSCAPE_ICON("zoom-fit-selection")), // Dialogs + new DialogVerb(SP_VERB_DIALOG_PROTOTYPE, "DialogPrototype", N_("Prototype..."), + N_("Prototype Dialog"), INKSCAPE_ICON("gtk-preferences")), new DialogVerb(SP_VERB_DIALOG_DISPLAY, "DialogPreferences", N_("P_references..."), N_("Edit global Inkscape preferences"), INKSCAPE_ICON("gtk-preferences")), new DialogVerb(SP_VERB_DIALOG_NAMEDVIEW, "DialogDocumentProperties", N_("_Document Properties..."), diff --git a/src/verbs.h b/src/verbs.h index 21e9b5547..b6b7b54dc 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -291,6 +291,7 @@ enum { SP_VERB_ZOOM_DRAWING, SP_VERB_ZOOM_SELECTION, /* Dialogs */ + SP_VERB_DIALOG_PROTOTYPE, SP_VERB_DIALOG_DISPLAY, SP_VERB_DIALOG_NAMEDVIEW, SP_VERB_DIALOG_METADATA, |
