15ebcef5ac133824f50c35381345a001e88d2de0
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/input.h"
31 #include "ui/dialog/layer-editor.h"
32 #include "ui/dialog/livepatheffect-editor.h"
33 #include "ui/dialog/memory.h"
34 #include "ui/dialog/messages.h"
35 #include "ui/dialog/scriptdialog.h"
36 #include "ui/dialog/text-properties.h"
37 #include "ui/dialog/tracedialog.h"
38 #include "ui/dialog/transformation.h"
39 #include "ui/dialog/undo-history.h"
40 #include "ui/dialog/xml-editor.h"
41 #include "ui/dialog/panel-dialog.h"
43 #include "dialogs/layers-panel.h"
44 #include "dialogs/tiledialog.h"
45 #include "dialogs/iconpreview.h"
47 #include "ui/dialog/floating-behavior.h"
48 #include "ui/dialog/dock-behavior.h"
50 namespace Inkscape {
51 namespace UI {
52 namespace Dialog {
54 namespace {
56 using namespace Behavior;
58 template <typename T, typename B>
59 inline Dialog *create() { return PanelDialog<B>::template create<T>(); }
61 }
63 /**
64 * This class is provided as a container for Inkscape's various
65 * dialogs. This allows Inkscape::Application to treat the various
66 * dialogs it invokes, as abstractions.
67 *
68 * DialogManager is essentially a cache of dialogs. It lets us
69 * initialize dialogs lazily - instead of constructing them during
70 * application startup, they're constructed the first time they're
71 * actually invoked by Inkscape::Application. The constructed
72 * dialog is held here after that, so future invokations of the
73 * dialog don't need to get re-constructed each time. The memory for
74 * the dialogs are then reclaimed when the DialogManager is destroyed.
75 *
76 * In addition, DialogManager also serves as a signal manager for
77 * dialogs. It provides a set of signals that can be sent to all
78 * dialogs for doing things such as hiding/unhiding them, etc.
79 * DialogManager ensures that every dialog it handles will listen
80 * to these signals.
81 *
82 */
83 DialogManager::DialogManager() {
85 using namespace Behavior;
86 using namespace Inkscape::UI::Dialogs; // temporary
88 int dialogs_type = prefs_get_int_attribute_limited ("options.dialogtype", "value", DOCK, 0, 1);
90 if (dialogs_type == FLOATING) {
92 registerFactory("AlignAndDistribute", &create<AlignAndDistribute, FloatingBehavior>);
93 registerFactory("DocumentMetadata", &create<DocumentMetadata, FloatingBehavior>);
94 registerFactory("DocumentProperties", &create<DocumentProperties, FloatingBehavior>);
95 registerFactory("Export", &create<Export, FloatingBehavior>);
96 registerFactory("ExtensionEditor", &create<ExtensionEditor, FloatingBehavior>);
97 registerFactory("FillAndStroke", &create<FillAndStroke, FloatingBehavior>);
98 registerFactory("FilterEffectsDialog", &create<FilterEffectsDialog, FloatingBehavior>);
99 registerFactory("Find", &create<Find, FloatingBehavior>);
100 registerFactory("IconPreviewPanel", &create<IconPreviewPanel, FloatingBehavior>);
101 registerFactory("InkscapePreferences", &create<InkscapePreferences, FloatingBehavior>);
102 registerFactory("LayerEditor", &create<LayerEditor, FloatingBehavior>);
103 registerFactory("LayersPanel", &create<LayersPanel, FloatingBehavior>);
104 registerFactory("LivePathEffect", &create<LivePathEffectEditor, FloatingBehavior>);
105 registerFactory("Memory", &create<Memory, FloatingBehavior>);
106 registerFactory("Messages", &create<Messages, FloatingBehavior>);
107 registerFactory("Script", &create<ScriptDialog, FloatingBehavior>);
108 registerFactory("Swatches", &create<SwatchesPanel, FloatingBehavior>);
109 registerFactory("TextProperties", &create<TextProperties, FloatingBehavior>);
110 registerFactory("TileDialog", &create<TileDialog, FloatingBehavior>);
111 registerFactory("Trace", &create<TraceDialog, FloatingBehavior>);
112 registerFactory("Transformation", &create<Transformation, FloatingBehavior>);
113 registerFactory("UndoHistory", &create<UndoHistory, FloatingBehavior>);
114 registerFactory("XmlEditor", &create<XmlEditor, FloatingBehavior>);
116 registerFactory("InputDevices", &create<InputDialog, FloatingBehavior>);
118 } else {
120 registerFactory("AlignAndDistribute", &create<AlignAndDistribute, DockBehavior>);
121 registerFactory("DocumentMetadata", &create<DocumentMetadata, DockBehavior>);
122 registerFactory("DocumentProperties", &create<DocumentProperties, DockBehavior>);
123 registerFactory("Export", &create<Export, DockBehavior>);
124 registerFactory("ExtensionEditor", &create<ExtensionEditor, DockBehavior>);
125 registerFactory("FillAndStroke", &create<FillAndStroke, DockBehavior>);
126 registerFactory("FilterEffectsDialog", &create<FilterEffectsDialog, DockBehavior>);
127 registerFactory("Find", &create<Find, DockBehavior>);
128 registerFactory("IconPreviewPanel", &create<IconPreviewPanel, DockBehavior>);
129 registerFactory("InkscapePreferences", &create<InkscapePreferences, DockBehavior>);
130 registerFactory("LayerEditor", &create<LayerEditor, DockBehavior>);
131 registerFactory("LayersPanel", &create<LayersPanel, DockBehavior>);
132 registerFactory("LivePathEffect", &create<LivePathEffectEditor, DockBehavior>);
133 registerFactory("Memory", &create<Memory, DockBehavior>);
134 registerFactory("Messages", &create<Messages, DockBehavior>);
135 registerFactory("Script", &create<ScriptDialog, DockBehavior>);
136 registerFactory("Swatches", &create<SwatchesPanel, DockBehavior>);
137 registerFactory("TextProperties", &create<TextProperties, DockBehavior>);
138 registerFactory("TileDialog", &create<TileDialog, DockBehavior>);
139 registerFactory("Trace", &create<TraceDialog, DockBehavior>);
140 registerFactory("Transformation", &create<Transformation, DockBehavior>);
141 registerFactory("UndoHistory", &create<UndoHistory, DockBehavior>);
142 registerFactory("XmlEditor", &create<XmlEditor, DockBehavior>);
144 registerFactory("InputDevices", &create<InputDialog, DockBehavior>);
146 }
147 }
149 DialogManager::~DialogManager() {
150 // TODO: Disconnect the signals
151 // TODO: Do we need to explicitly delete the dialogs?
152 // Appears to cause a segfault if we do
153 }
156 DialogManager &DialogManager::getInstance()
157 {
158 int dialogs_type = prefs_get_int_attribute_limited ("options.dialogtype", "value", DOCK, 0, 1);
160 /* Use singleton behavior for floating dialogs */
161 if (dialogs_type == FLOATING) {
162 static DialogManager *instance = 0;
164 if (!instance)
165 instance = new DialogManager();
166 return *instance;
167 }
169 return *new DialogManager();
170 }
172 /**
173 * Registers a dialog factory function used to create the named dialog.
174 */
175 void DialogManager::registerFactory(gchar const *name,
176 DialogManager::DialogFactory factory)
177 {
178 registerFactory(g_quark_from_string(name), factory);
179 }
181 /**
182 * Registers a dialog factory function used to create the named dialog.
183 */
184 void DialogManager::registerFactory(GQuark name,
185 DialogManager::DialogFactory factory)
186 {
187 _factory_map[name] = factory;
188 }
190 /**
191 * Fetches the named dialog, creating it if it has not already been
192 * created (assuming a factory has been registered for it).
193 */
194 Dialog *DialogManager::getDialog(gchar const *name) {
195 return getDialog(g_quark_from_string(name));
196 }
198 /**
199 * Fetches the named dialog, creating it if it has not already been
200 * created (assuming a factory has been registered for it).
201 */
202 Dialog *DialogManager::getDialog(GQuark name) {
203 DialogMap::iterator dialog_found;
204 dialog_found = _dialog_map.find(name);
206 Dialog *dialog=NULL;
207 if ( dialog_found != _dialog_map.end() ) {
208 dialog = dialog_found->second;
209 } else {
210 FactoryMap::iterator factory_found;
211 factory_found = _factory_map.find(name);
213 if ( factory_found != _factory_map.end() ) {
214 dialog = factory_found->second();
215 _dialog_map[name] = dialog;
216 }
217 }
219 return dialog;
220 }
222 /**
223 * Shows the named dialog, creating it if necessary.
224 */
225 void DialogManager::showDialog(gchar const *name) {
226 showDialog(g_quark_from_string(name));
227 }
229 /**
230 * Shows the named dialog, creating it if necessary.
231 */
232 void DialogManager::showDialog(GQuark name) {
233 Dialog *dialog=getDialog(name);
234 if (dialog) {
235 dialog->present();
236 }
237 }
239 } // namespace Dialog
240 } // namespace UI
241 } // namespace Inkscape
243 /*
244 Local Variables:
245 mode:c++
246 c-file-style:"stroustrup"
247 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
248 indent-tabs-mode:nil
249 fill-column:99
250 End:
251 */
252 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :