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