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