f4099b0500bb9c46bcfb82faa979a4ec8a370d6b
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/find.h"
27 #include "ui/dialog/inkscape-preferences.h"
28 #include "ui/dialog/layer-editor.h"
29 #include "ui/dialog/memory.h"
30 #include "ui/dialog/messages.h"
31 #include "ui/dialog/scriptdialog.h"
32 #include "ui/dialog/text-properties.h"
33 #include "ui/dialog/tracedialog.h"
34 #include "ui/dialog/transformation.h"
36 #include "ui/dialog/xml-editor.h"
38 #include "dialogs/tiledialog.h"
40 namespace Inkscape {
41 namespace UI {
42 namespace Dialog {
44 namespace {
46 template <typename T>
47 Dialog *create() { return T::create(); }
49 }
51 /**
52 * This class is provided as a container for Inkscape's various
53 * dialogs. This allows Inkscape::Application to treat the various
54 * dialogs it invokes, as abstractions.
55 *
56 * DialogManager is essentially a cache of dialogs. It lets us
57 * initialize dialogs lazily - instead of constructing them during
58 * application startup, they're constructed the first time they're
59 * actually invoked by Inkscape::Application. The constructed
60 * dialog is held here after that, so future invokations of the
61 * dialog don't need to get re-constructed each time. The memory for
62 * the dialogs are then reclaimed when the DialogManager is destroyed.
63 *
64 * In addition, DialogManager also serves as a signal manager for
65 * dialogs. It provides a set of signals that can be sent to all
66 * dialogs for doing things such as hiding/unhiding them, etc.
67 * DialogManager ensures that every dialog it handles will listen
68 * to these signals.
69 *
70 */
71 DialogManager::DialogManager() {
72 registerFactory("AlignAndDistribute", &create<AlignAndDistribute>);
73 registerFactory("DocumentMetadata", &create<DocumentMetadata>);
74 registerFactory("DocumentProperties", &create<DocumentProperties>);
75 registerFactory("Export", &create<Export>);
76 registerFactory("ExtensionEditor", &create<ExtensionEditor>);
77 registerFactory("FillAndStroke", &create<FillAndStroke>);
78 registerFactory("Find", &create<Find>);
79 registerFactory("InkscapePreferences", &create<InkscapePreferences>);
80 registerFactory("LayerEditor", &create<LayerEditor>);
81 registerFactory("Memory", &create<Memory>);
82 registerFactory("Messages", &create<Messages>);
83 registerFactory("Script", &create<ScriptDialog>);
84 registerFactory("TextProperties", &create<TextProperties>);
85 registerFactory("TileDialog", &create<TileDialog>);
86 registerFactory("Trace", &create<TraceDialog>);
87 registerFactory("Transformation", &create<Transformation>);
88 registerFactory("XmlEditor", &create<XmlEditor>);
89 }
91 DialogManager::~DialogManager() {
92 // TODO: Disconnect the signals
93 // TODO: Do we need to explicitly delete the dialogs?
94 // Appears to cause a segfault if we do
95 }
97 /**
98 * Registers a dialog factory function used to create the named dialog.
99 */
100 void DialogManager::registerFactory(gchar const *name,
101 DialogManager::DialogFactory factory)
102 {
103 registerFactory(g_quark_from_string(name), factory);
104 }
106 /**
107 * Registers a dialog factory function used to create the named dialog.
108 */
109 void DialogManager::registerFactory(GQuark name,
110 DialogManager::DialogFactory factory)
111 {
112 _factory_map[name] = factory;
113 }
115 /**
116 * Fetches the named dialog, creating it if it has not already been
117 * created (assuming a factory has been registered for it).
118 */
119 Dialog *DialogManager::getDialog(gchar const *name) {
120 return getDialog(g_quark_from_string(name));
121 }
123 /**
124 * Fetches the named dialog, creating it if it has not already been
125 * created (assuming a factory has been registered for it).
126 */
127 Dialog *DialogManager::getDialog(GQuark name) {
128 DialogMap::iterator dialog_found;
129 dialog_found = _dialog_map.find(name);
131 Dialog *dialog=NULL;
132 if ( dialog_found != _dialog_map.end() ) {
133 dialog = dialog_found->second;
134 } else {
135 FactoryMap::iterator factory_found;
136 factory_found = _factory_map.find(name);
138 if ( factory_found != _factory_map.end() ) {
139 dialog = factory_found->second();
140 _dialog_map[name] = dialog;
141 }
142 }
144 return dialog;
145 }
147 /**
148 * Shows the named dialog, creating it if necessary.
149 */
150 void DialogManager::showDialog(gchar const *name) {
151 showDialog(g_quark_from_string(name));
152 }
154 /**
155 * Shows the named dialog, creating it if necessary.
156 */
157 void DialogManager::showDialog(GQuark name) {
158 Dialog *dialog=getDialog(name);
159 if (dialog) {
160 dialog->present();
161 dialog->read_geometry();
162 }
163 }
165 } // namespace Dialog
166 } // namespace UI
167 } // namespace Inkscape
169 /*
170 Local Variables:
171 mode:c++
172 c-file-style:"stroustrup"
173 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
174 indent-tabs-mode:nil
175 fill-column:99
176 End:
177 */
178 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :