Code

Added a Rename menu item to the popup for the filter list in the filter effects dialo...
[inkscape.git] / src / ui / dialog / dialog-manager.cpp
1 /**
2  * \brief Object for managing a set of dialogs, including their signals and
3  *        construction/caching/destruction of them.
4  *
5  * Authors:
6  *   Bryce W. Harrington <bryce@bryceharrington.org>
7  *   Jon Phillips <jon@rejon.org>
8  *   Gustav Broberg <broberg@kth.se>
9  *
10  * Copyright (C) 2004--2007 Authors
11  *
12  * Released under GNU GPL.  Read the file 'COPYING' for more information.
13  */
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
19 #include "ui/dialog/dialog-manager.h"
21 #include "ui/dialog/align-and-distribute.h"
22 #include "ui/dialog/document-metadata.h"
23 #include "ui/dialog/document-properties.h"
24 #include "ui/dialog/export.h"
25 #include "ui/dialog/extension-editor.h"
26 #include "ui/dialog/fill-and-stroke.h"
27 #include "ui/dialog/filter-effects-dialog.h"
28 #include "ui/dialog/find.h"
29 #include "ui/dialog/inkscape-preferences.h"
30 #include "ui/dialog/layer-editor.h"
31 #include "ui/dialog/livepatheffect-editor.h"
32 #include "ui/dialog/memory.h"
33 #include "ui/dialog/messages.h"
34 #include "ui/dialog/scriptdialog.h"
35 #include "ui/dialog/text-properties.h"
36 #include "ui/dialog/tracedialog.h"
37 #include "ui/dialog/transformation.h"
38 #include "ui/dialog/undo-history.h"
39 #include "ui/dialog/xml-editor.h"
41 #include "dialogs/layers-panel.h"
42 #include "dialogs/tiledialog.h"
43 #include "dialogs/iconpreview.h"
45 #include "ui/dialog/floating-behavior.h"
46 #include "ui/dialog/dock-behavior.h"
48 namespace Inkscape {
49 namespace UI {
50 namespace Dialog {
52 namespace {
54 template <typename T, typename B>
55 inline Dialog *create() { return T::create(&B::create); }
57 }
59 /**
60  *  This class is provided as a container for Inkscape's various
61  *  dialogs.  This allows Inkscape::Application to treat the various
62  *  dialogs it invokes, as abstractions.
63  *
64  *  DialogManager is essentially a cache of dialogs.  It lets us
65  *  initialize dialogs lazily - instead of constructing them during
66  *  application startup, they're constructed the first time they're
67  *  actually invoked by Inkscape::Application.  The constructed
68  *  dialog is held here after that, so future invokations of the
69  *  dialog don't need to get re-constructed each time.  The memory for
70  *  the dialogs are then reclaimed when the DialogManager is destroyed.
71  *
72  *  In addition, DialogManager also serves as a signal manager for
73  *  dialogs.  It provides a set of signals that can be sent to all
74  *  dialogs for doing things such as hiding/unhiding them, etc.
75  *  DialogManager ensures that every dialog it handles will listen
76  *  to these signals.
77  *
78  */
79 DialogManager::DialogManager() {
81     using namespace Behavior;
82     using namespace Inkscape::UI::Dialogs; // temporary
84     int dialogs_type = prefs_get_int_attribute_limited ("options.dialogtype", "value", DOCK, 0, 1);
86     if (dialogs_type == FLOATING) {
88         registerFactory("AlignAndDistribute",  &create<AlignAndDistribute,   FloatingBehavior>);
89         registerFactory("DocumentMetadata",    &create<DocumentMetadata,     FloatingBehavior>);
90         registerFactory("DocumentProperties",  &create<DocumentProperties,   FloatingBehavior>);
91         registerFactory("Export",              &create<Export,               FloatingBehavior>);
92         registerFactory("ExtensionEditor",     &create<ExtensionEditor,      FloatingBehavior>);
93         registerFactory("FillAndStroke",       &create<FillAndStroke,        FloatingBehavior>);
94         registerFactory("FilterEffectsDialog", &create<FilterEffectsDialog,  FloatingBehavior>);
95         registerFactory("Find",                &create<Find,                 FloatingBehavior>);
96         registerFactory("IconPreviewPanel",    &create<IconPreviewPanel,     FloatingBehavior>);
97         registerFactory("InkscapePreferences", &create<InkscapePreferences,  FloatingBehavior>);
98         registerFactory("LayerEditor",         &create<LayerEditor,          FloatingBehavior>);
99         registerFactory("LayersPanel",         &create<LayersPanel,          FloatingBehavior>);
100         registerFactory("LivePathEffect",      &create<LivePathEffectEditor, FloatingBehavior>);
101         registerFactory("Memory",              &create<Memory,               FloatingBehavior>);
102         registerFactory("Messages",            &create<Messages,             FloatingBehavior>);
103         registerFactory("Script",              &create<ScriptDialog,         FloatingBehavior>);
104         registerFactory("TextProperties",      &create<TextProperties,       FloatingBehavior>);
105         registerFactory("TileDialog",          &create<TileDialog,           FloatingBehavior>);
106         registerFactory("Trace",               &create<TraceDialog,          FloatingBehavior>);
107         registerFactory("Transformation",      &create<Transformation,       FloatingBehavior>);
108         registerFactory("UndoHistory",         &create<UndoHistory,          FloatingBehavior>);
109         registerFactory("XmlEditor",           &create<XmlEditor,            FloatingBehavior>);
111     } else {
113         registerFactory("AlignAndDistribute",  &create<AlignAndDistribute,   DockBehavior>);
114         registerFactory("DocumentMetadata",    &create<DocumentMetadata,     DockBehavior>);
115         registerFactory("DocumentProperties",  &create<DocumentProperties,   DockBehavior>);
116         registerFactory("Export",              &create<Export,               DockBehavior>);
117         registerFactory("ExtensionEditor",     &create<ExtensionEditor,      DockBehavior>);
118         registerFactory("FillAndStroke",       &create<FillAndStroke,        DockBehavior>);
119         registerFactory("FilterEffectsDialog", &create<FilterEffectsDialog,  DockBehavior>);
120         registerFactory("Find",                &create<Find,                 DockBehavior>);
121         registerFactory("IconPreviewPanel",    &create<IconPreviewPanel,     DockBehavior>);
122         registerFactory("InkscapePreferences", &create<InkscapePreferences,  DockBehavior>);
123         registerFactory("LayerEditor",         &create<LayerEditor,          DockBehavior>);
124         registerFactory("LayersPanel",         &create<LayersPanel,          DockBehavior>);
125         registerFactory("LivePathEffect",      &create<LivePathEffectEditor, DockBehavior>);
126         registerFactory("Memory",              &create<Memory,               DockBehavior>);
127         registerFactory("Messages",            &create<Messages,             DockBehavior>);
128         registerFactory("Script",              &create<ScriptDialog,         DockBehavior>);
129         registerFactory("TextProperties",      &create<TextProperties,       DockBehavior>);
130         registerFactory("TileDialog",          &create<TileDialog,           DockBehavior>);
131         registerFactory("Trace",               &create<TraceDialog,          DockBehavior>);
132         registerFactory("Transformation",      &create<Transformation,       DockBehavior>);
133         registerFactory("UndoHistory",         &create<UndoHistory,          DockBehavior>);
134         registerFactory("XmlEditor",           &create<XmlEditor,            DockBehavior>);
136     }
139 DialogManager::~DialogManager() {
140     // TODO:  Disconnect the signals
141     // TODO:  Do we need to explicitly delete the dialogs?
142     //        Appears to cause a segfault if we do
145 /**
146  * Registers a dialog factory function used to create the named dialog.
147  */
148 void DialogManager::registerFactory(gchar const *name,
149                                     DialogManager::DialogFactory factory)
151     registerFactory(g_quark_from_string(name), factory);
154 /**
155  * Registers a dialog factory function used to create the named dialog.
156  */
157 void DialogManager::registerFactory(GQuark name,
158                                     DialogManager::DialogFactory factory)
160     _factory_map[name] = factory;
163 /**
164  * Fetches the named dialog, creating it if it has not already been
165  * created (assuming a factory has been registered for it).
166  */
167 Dialog *DialogManager::getDialog(gchar const *name) {
168     return getDialog(g_quark_from_string(name));
171 /**
172  * Fetches the named dialog, creating it if it has not already been
173  * created (assuming a factory has been registered for it).
174  */
175 Dialog *DialogManager::getDialog(GQuark name) {
176     DialogMap::iterator dialog_found;
177     dialog_found = _dialog_map.find(name);
179     Dialog *dialog=NULL;
180     if ( dialog_found != _dialog_map.end() ) {
181         dialog = dialog_found->second;
182     } else {
183         FactoryMap::iterator factory_found;
184         factory_found = _factory_map.find(name);
186         if ( factory_found != _factory_map.end() ) {
187             dialog = factory_found->second();
188             _dialog_map[name] = dialog;
189         }
190     }
192     return dialog;
195 /**
196  * Shows the named dialog, creating it if necessary.
197  */
198 void DialogManager::showDialog(gchar const *name) {
199     showDialog(g_quark_from_string(name));
202 /**
203  * Shows the named dialog, creating it if necessary.
204  */
205 void DialogManager::showDialog(GQuark name) {
206     Dialog *dialog=getDialog(name);
207     if (dialog) {
208         dialog->present();
209     }
212 } // namespace Dialog
213 } // namespace UI
214 } // namespace Inkscape
216 /*
217   Local Variables:
218   mode:c++
219   c-file-style:"stroustrup"
220   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
221   indent-tabs-mode:nil
222   fill-column:99
223   End:
224 */
225 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :