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