]> git.lyx.org Git - lyx.git/blob - src/frontends/Dialogs.C
More 'standard conformant blurb' nonsense.
[lyx.git] / src / frontends / Dialogs.C
1 /**
2  * \file frontends/Dialogs.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS
9  *
10  * Common to all frontends' Dialogs
11  */
12
13 #include <config.h>
14
15 #include "Dialogs.h"
16 #include "controllers/Dialog.h"
17 #include <boost/signals/signal2.hpp>
18 #include <boost/bind.hpp>
19
20
21 // Note that static boost signals break some compilers, so this wrapper
22 // initialises the signal dynamically when it is first invoked.
23 template<typename Signal>
24 class BugfixSignal {
25 public:
26         Signal & operator()() { return thesignal(); }
27         Signal const & operator()() const { return thesignal(); }
28
29 private:
30         Signal & thesignal() const
31         {
32                 if (!signal_.get())
33                         signal_.reset(new Signal);
34                 return *signal_;
35         }
36
37         mutable boost::scoped_ptr<Signal> signal_;
38 };
39
40
41 boost::signal0<void> & Dialogs::redrawGUI()
42 {
43         static BugfixSignal<boost::signal0<void> > thesignal;
44         return thesignal();
45 }
46
47
48 namespace {
49
50 BugfixSignal<boost::signal2<void, string const &, InsetBase*> > hideSignal;
51
52 }
53
54
55 void Dialogs::hide(string const & name, InsetBase* inset)
56 {
57         hideSignal()(name, inset);
58 }
59
60
61 Dialogs::Dialogs(LyXView & lyxview)
62         : lyxview_(lyxview)
63 {
64         // Connect signals
65         redrawGUI().connect(boost::bind(&Dialogs::redraw, this));
66         hideSignal().connect(boost::bind(&Dialogs::hideSlot, this, _1, _2));
67
68         // All this is slated to go
69         init_pimpl();
70         // reduce the number of connections needed in
71         // dialogs by a simple connection here.
72         hideAllSignal.connect(hideBufferDependentSignal);
73 }
74
75
76 Dialog * Dialogs::find(string const & name)
77 {
78         if (!isValidName(name))
79                 return 0;
80
81         std::map<string, DialogPtr>::iterator it =
82                 dialogs_.find(name);
83
84         if (it == dialogs_.end()) {
85                 dialogs_[name] = DialogPtr(build(name));
86                 return dialogs_[name].get();
87         }
88
89         return it->second.get();
90 }
91
92
93 void Dialogs::show(string const & name, string const & data)
94 {
95         Dialog * dialog = find(name);
96         if (!dialog)
97                 return;
98
99         // FIXME! Should check that the dialog is NOT an inset dialog.
100         dialog->show(data);
101 }
102
103
104 void Dialogs::show(string const & name, string const & data, InsetBase * inset)
105 {
106         Dialog * dialog = find(name);
107         if (!dialog)
108                 return;
109
110         // FIXME! Should check that the dialog IS an inset dialog.
111         dialog->show(data);
112         open_insets_[name] = inset;
113 }
114
115
116 bool Dialogs::visible(string const & name) const
117 {
118         std::map<string, DialogPtr>::const_iterator it =
119                 dialogs_.find(name);
120         if (it == dialogs_.end())
121                 return false;
122         return it->second.get()->isVisible();
123 }
124
125
126 void Dialogs::update(string const & name, string const & data)
127 {
128         Dialog * dialog = find(name);
129         if (!dialog)
130                 return;
131
132         if (dialog->isVisible())
133                 dialog->update(data);
134 }
135
136
137 void Dialogs::hideSlot(string const & name, InsetBase * inset)
138 {
139         Dialog * dialog = find(name);
140         if (!dialog)
141                 return;
142
143         if (inset && inset != getOpenInset(name))
144                 return;
145
146         if (dialog->isVisible())
147                 dialog->hide();
148         open_insets_[name] = 0;
149 }
150
151
152 void Dialogs::disconnect(string const & name)
153 {
154         if (!isValidName(name))
155                 return;
156
157         open_insets_[name] = 0;
158 }
159
160
161 InsetBase * Dialogs::getOpenInset(string const & name) const
162 {
163         if (!isValidName(name))
164                 return 0;
165
166         std::map<string, InsetBase *>::const_iterator it =
167                 open_insets_.find(name);
168         return it == open_insets_.end() ? 0 : it->second;
169 }
170
171
172 void Dialogs::hideAll() const
173 {
174         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
175         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
176
177         for(; it != end; ++it) {
178                 it->second->hide();
179         }
180         hideAllSignal();
181 }
182
183
184 void Dialogs::hideBufferDependent() const
185 {
186         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
187         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
188
189         for(; it != end; ++it) {
190                 Dialog * dialog =  it->second.get();
191                 if (dialog->controller().isBufferDependent())
192                         dialog->hide();
193         }
194         hideBufferDependentSignal();
195 }
196
197
198 void Dialogs::updateBufferDependent(bool switched) const
199 {
200         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
201         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
202
203         for(; it != end; ++it) {
204                 Dialog * dialog =  it->second.get();
205                 if (switched && dialog->controller().isBufferDependent()) {
206                         dialog->hide();
207                 } else {
208                         // A bit clunky, but the dialog will request
209                         // that the kernel provides it with the necessary
210                         // data.
211                         dialog->RestoreButton();
212                 }
213         }
214         updateBufferDependentSignal(switched);
215 }
216
217
218 void Dialogs::redraw() const
219 {
220         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
221         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
222
223         for(; it != end; ++it) {
224                 it->second->redraw();
225         }
226 }