Code

moving trunk for module inkscape
[inkscape.git] / src / ui / dialog / dialog-manager.cpp
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 #ifdef WITH_INKBOARD
37 #include "ui/dialog/whiteboard-sharewithchat.h"
38 #include "ui/dialog/whiteboard-sharewithuser.h"
39 #include "ui/dialog/whiteboard-connect.h"
40 #include "ui/dialog/session-player.h"
41 #endif
43 #include "ui/dialog/xml-editor.h"
45 #include "dialogs/tiledialog.h"
47 namespace Inkscape {
48 namespace UI {
49 namespace Dialog {
51 namespace {
53 template <typename T>
54 Dialog *create() { return T::create(); }
56 }
58 /**
59  *  This class is provided as a container for Inkscape's various
60  *  dialogs.  This allows Inkscape::Application to treat the various
61  *  dialogs it invokes, as abstractions.
62  *
63  *  DialogManager is essentially a cache of dialogs.  It lets us
64  *  initialize dialogs lazily - instead of constructing them during
65  *  application startup, they're constructed the first time they're
66  *  actually invoked by Inkscape::Application.  The constructed
67  *  dialog is held here after that, so future invokations of the
68  *  dialog don't need to get re-constructed each time.  The memory for
69  *  the dialogs are then reclaimed when the DialogManager is destroyed.
70  *
71  *  In addition, DialogManager also serves as a signal manager for
72  *  dialogs.  It provides a set of signals that can be sent to all
73  *  dialogs for doing things such as hiding/unhiding them, etc.
74  *  DialogManager ensures that every dialog it handles will listen
75  *  to these signals.
76  *
77  */
78 DialogManager::DialogManager() {
79     registerFactory("AlignAndDistribute",  &create<AlignAndDistribute>);
80     registerFactory("DocumentMetadata",    &create<DocumentMetadata>);
81     registerFactory("DocumentProperties",  &create<DocumentProperties>);
82     registerFactory("Export",              &create<Export>);
83     registerFactory("ExtensionEditor",     &create<ExtensionEditor>);
84     registerFactory("FillAndStroke",       &create<FillAndStroke>);
85     registerFactory("Find",                &create<Find>);
86     registerFactory("InkscapePreferences", &create<InkscapePreferences>);
87     registerFactory("LayerEditor",         &create<LayerEditor>);
88     registerFactory("Memory",              &create<Memory>);
89     registerFactory("Messages",            &create<Messages>);
90     registerFactory("Script",              &create<ScriptDialog>);
91     registerFactory("TextProperties",      &create<TextProperties>);
92     registerFactory("TileDialog",          &create<TileDialog>);
93     registerFactory("Trace",               &create<TraceDialog>);
94     registerFactory("Transformation",      &create<Transformation>);
95 #ifdef WITH_INKBOARD
96         registerFactory("SessionPlayer",       &create<SessionPlaybackDialog>);
97     registerFactory("WhiteboardConnect",   &create<WhiteboardConnectDialog>);
98     registerFactory("WhiteboardShareWithUser",   &create<WhiteboardShareWithUserDialog>);
99     registerFactory("WhiteboardShareWithChat",   &create<WhiteboardShareWithChatroomDialog>);
100 #endif
101     registerFactory("XmlEditor",           &create<XmlEditor>);
104 DialogManager::~DialogManager() {
105     // TODO:  Disconnect the signals
106     // TODO:  Do we need to explicitly delete the dialogs?
107     //        Appears to cause a segfault if we do
110 /**
111  * Registers a dialog factory function used to create the named dialog.
112  */
113 void DialogManager::registerFactory(gchar const *name,
114                                     DialogManager::DialogFactory factory)
116     registerFactory(g_quark_from_string(name), factory);
119 /**
120  * Registers a dialog factory function used to create the named dialog.
121  */
122 void DialogManager::registerFactory(GQuark name,
123                                     DialogManager::DialogFactory factory)
125     _factory_map[name] = factory;
128 /**
129  * Fetches the named dialog, creating it if it has not already been
130  * created (assuming a factory has been registered for it).
131  */
132 Dialog *DialogManager::getDialog(gchar const *name) {
133     return getDialog(g_quark_from_string(name));
136 /**
137  * Fetches the named dialog, creating it if it has not already been
138  * created (assuming a factory has been registered for it).
139  */
140 Dialog *DialogManager::getDialog(GQuark name) {
141     DialogMap::iterator dialog_found;
142     dialog_found = _dialog_map.find(name);
144     Dialog *dialog=NULL;
145     if ( dialog_found != _dialog_map.end() ) {
146         dialog = dialog_found->second;
147     } else {
148         FactoryMap::iterator factory_found;
149         factory_found = _factory_map.find(name);
151         if ( factory_found != _factory_map.end() ) {
152             dialog = factory_found->second();
153             _dialog_map[name] = dialog;
154         }
155     }
157     return dialog;
160 /**
161  * Shows the named dialog, creating it if necessary.
162  */
163 void DialogManager::showDialog(gchar const *name) {
164     showDialog(g_quark_from_string(name));
167 /**
168  * Shows the named dialog, creating it if necessary.
169  */
170 void DialogManager::showDialog(GQuark name) {
171     Dialog *dialog=getDialog(name);
172     if (dialog) {
173         dialog->present();
174         dialog->read_geometry();
175     }
178 } // namespace Dialog
179 } // namespace UI
180 } // namespace Inkscape
182 /*
183   Local Variables:
184   mode:c++
185   c-file-style:"stroustrup"
186   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
187   indent-tabs-mode:nil
188   fill-column:99
189   End:
190 */
191 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :