Code

Handle the case of gnome_vfs_init failing. (Fixes Debian bug http://bugs.debian...
[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"
35 #include "ui/dialog/undo-history.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("UndoHistory",         &create<UndoHistory>);
89     registerFactory("XmlEditor",           &create<XmlEditor>);
90 }
92 DialogManager::~DialogManager() {
93     // TODO:  Disconnect the signals
94     // TODO:  Do we need to explicitly delete the dialogs?
95     //        Appears to cause a segfault if we do
96 }
98 /**
99  * Registers a dialog factory function used to create the named dialog.
100  */
101 void DialogManager::registerFactory(gchar const *name,
102                                     DialogManager::DialogFactory factory)
104     registerFactory(g_quark_from_string(name), factory);
107 /**
108  * Registers a dialog factory function used to create the named dialog.
109  */
110 void DialogManager::registerFactory(GQuark name,
111                                     DialogManager::DialogFactory factory)
113     _factory_map[name] = factory;
116 /**
117  * Fetches the named dialog, creating it if it has not already been
118  * created (assuming a factory has been registered for it).
119  */
120 Dialog *DialogManager::getDialog(gchar const *name) {
121     return getDialog(g_quark_from_string(name));
124 /**
125  * Fetches the named dialog, creating it if it has not already been
126  * created (assuming a factory has been registered for it).
127  */
128 Dialog *DialogManager::getDialog(GQuark name) {
129     DialogMap::iterator dialog_found;
130     dialog_found = _dialog_map.find(name);
132     Dialog *dialog=NULL;
133     if ( dialog_found != _dialog_map.end() ) {
134         dialog = dialog_found->second;
135     } else {
136         FactoryMap::iterator factory_found;
137         factory_found = _factory_map.find(name);
139         if ( factory_found != _factory_map.end() ) {
140             dialog = factory_found->second();
141             _dialog_map[name] = dialog;
142         }
143     }
145     return dialog;
148 /**
149  * Shows the named dialog, creating it if necessary.
150  */
151 void DialogManager::showDialog(gchar const *name) {
152     showDialog(g_quark_from_string(name));
155 /**
156  * Shows the named dialog, creating it if necessary.
157  */
158 void DialogManager::showDialog(GQuark name) {
159     Dialog *dialog=getDialog(name);
160     if (dialog) {
161         dialog->present();
162         dialog->read_geometry();
163     }
166 } // namespace Dialog
167 } // namespace UI
168 } // namespace Inkscape
170 /*
171   Local Variables:
172   mode:c++
173   c-file-style:"stroustrup"
174   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
175   indent-tabs-mode:nil
176   fill-column:99
177   End:
178 */
179 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :