Code

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