1 /**
2 * \brief Object for managing a set of dialogs, including their signals and
3 * construction/caching/destruction of them.
4 *
5 * Author:
6 * Bryce W. Harrington <bryce@bryceharrington.org>
7 * Jon Phillips <jon@rejon.org>
8 *
9 * Copyright (C) 2004, 2005 Authors
10 *
11 * Released under GNU GPL. Read the file 'COPYING' for more information.
12 */
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
18 #include "ui/dialog/dialog-manager.h"
20 #include "ui/dialog/align-and-distribute.h"
21 #include "ui/dialog/document-metadata.h"
22 #include "ui/dialog/document-properties.h"
23 #include "ui/dialog/export.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/layer-editor.h"
30 #include "ui/dialog/memory.h"
31 #include "ui/dialog/messages.h"
32 #include "ui/dialog/scriptdialog.h"
33 #include "ui/dialog/text-properties.h"
34 #include "ui/dialog/tracedialog.h"
35 #include "ui/dialog/transformation.h"
36 #include "ui/dialog/undo-history.h"
37 #include "ui/dialog/xml-editor.h"
39 #include "dialogs/tiledialog.h"
41 namespace Inkscape {
42 namespace UI {
43 namespace Dialog {
45 namespace {
47 template <typename T>
48 Dialog *create() { return T::create(); }
50 }
52 /**
53 * This class is provided as a container for Inkscape's various
54 * dialogs. This allows Inkscape::Application to treat the various
55 * dialogs it invokes, as abstractions.
56 *
57 * DialogManager is essentially a cache of dialogs. It lets us
58 * initialize dialogs lazily - instead of constructing them during
59 * application startup, they're constructed the first time they're
60 * actually invoked by Inkscape::Application. The constructed
61 * dialog is held here after that, so future invokations of the
62 * dialog don't need to get re-constructed each time. The memory for
63 * the dialogs are then reclaimed when the DialogManager is destroyed.
64 *
65 * In addition, DialogManager also serves as a signal manager for
66 * dialogs. It provides a set of signals that can be sent to all
67 * dialogs for doing things such as hiding/unhiding them, etc.
68 * DialogManager ensures that every dialog it handles will listen
69 * to these signals.
70 *
71 */
72 DialogManager::DialogManager() {
73 registerFactory("AlignAndDistribute", &create<AlignAndDistribute>);
74 registerFactory("DocumentMetadata", &create<DocumentMetadata>);
75 registerFactory("DocumentProperties", &create<DocumentProperties>);
76 registerFactory("Export", &create<Export>);
77 registerFactory("ExtensionEditor", &create<ExtensionEditor>);
78 registerFactory("FillAndStroke", &create<FillAndStroke>);
79 registerFactory("FilterEffectsDialog", &create<FilterEffectsDialog>);
80 registerFactory("Find", &create<Find>);
81 registerFactory("InkscapePreferences", &create<InkscapePreferences>);
82 registerFactory("LayerEditor", &create<LayerEditor>);
83 registerFactory("Memory", &create<Memory>);
84 registerFactory("Messages", &create<Messages>);
85 registerFactory("Script", &create<ScriptDialog>);
86 registerFactory("TextProperties", &create<TextProperties>);
87 registerFactory("TileDialog", &create<TileDialog>);
88 registerFactory("Trace", &create<TraceDialog>);
89 registerFactory("Transformation", &create<Transformation>);
90 registerFactory("UndoHistory", &create<UndoHistory>);
91 registerFactory("XmlEditor", &create<XmlEditor>);
92 }
94 DialogManager::~DialogManager() {
95 // TODO: Disconnect the signals
96 // TODO: Do we need to explicitly delete the dialogs?
97 // Appears to cause a segfault if we do
98 }
100 /**
101 * Registers a dialog factory function used to create the named dialog.
102 */
103 void DialogManager::registerFactory(gchar const *name,
104 DialogManager::DialogFactory factory)
105 {
106 registerFactory(g_quark_from_string(name), factory);
107 }
109 /**
110 * Registers a dialog factory function used to create the named dialog.
111 */
112 void DialogManager::registerFactory(GQuark name,
113 DialogManager::DialogFactory factory)
114 {
115 _factory_map[name] = factory;
116 }
118 /**
119 * Fetches the named dialog, creating it if it has not already been
120 * created (assuming a factory has been registered for it).
121 */
122 Dialog *DialogManager::getDialog(gchar const *name) {
123 return getDialog(g_quark_from_string(name));
124 }
126 /**
127 * Fetches the named dialog, creating it if it has not already been
128 * created (assuming a factory has been registered for it).
129 */
130 Dialog *DialogManager::getDialog(GQuark name) {
131 DialogMap::iterator dialog_found;
132 dialog_found = _dialog_map.find(name);
134 Dialog *dialog=NULL;
135 if ( dialog_found != _dialog_map.end() ) {
136 dialog = dialog_found->second;
137 } else {
138 FactoryMap::iterator factory_found;
139 factory_found = _factory_map.find(name);
141 if ( factory_found != _factory_map.end() ) {
142 dialog = factory_found->second();
143 _dialog_map[name] = dialog;
144 }
145 }
147 return dialog;
148 }
150 /**
151 * Shows the named dialog, creating it if necessary.
152 */
153 void DialogManager::showDialog(gchar const *name) {
154 showDialog(g_quark_from_string(name));
155 }
157 /**
158 * Shows the named dialog, creating it if necessary.
159 */
160 void DialogManager::showDialog(GQuark name) {
161 Dialog *dialog=getDialog(name);
162 if (dialog) {
163 dialog->present();
164 dialog->read_geometry();
165 }
166 }
168 } // namespace Dialog
169 } // namespace UI
170 } // namespace Inkscape
172 /*
173 Local Variables:
174 mode:c++
175 c-file-style:"stroustrup"
176 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
177 indent-tabs-mode:nil
178 fill-column:99
179 End:
180 */
181 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :