]> git.lyx.org Git - lyx.git/blob - src/frontends/Dialogs.cpp
merge controllers/Makefile.am and controllers/tests/Makefile.am
[lyx.git] / src / frontends / Dialogs.cpp
1 /**
2  * \file frontends/Dialogs.cpp
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
17 #include "callback.h"
18
19 #include "controllers/Dialog.h"
20
21 #include <boost/signal.hpp>
22 #include <boost/bind.hpp>
23
24 using std::string;
25
26 namespace lyx {
27
28 using lyx::frontend::Dialog;
29
30
31 Dialogs::Dialogs(LyXView & lyxview)
32         : lyxview_(lyxview), in_show_(false)
33 {
34 }
35
36
37 Dialog * Dialogs::find_or_build(string const & name)
38 {
39         if (!isValidName(name))
40                 return 0;
41
42         std::map<string, DialogPtr>::iterator it =
43                 dialogs_.find(name);
44
45         if (it != dialogs_.end())
46                 return it->second.get();
47
48         dialogs_[name] = build(name);
49         return dialogs_[name].get();
50 }
51
52
53 void Dialogs::show(string const & name, string const & data)
54 {
55         if (in_show_) {
56                 return;
57         }
58         in_show_ = true;
59         Dialog * dialog = find_or_build(name);
60         if (dialog) {
61                 // FIXME! Should check that the dialog is NOT an inset dialog.
62                 dialog->show(data);
63         }
64         in_show_ = false;
65 }
66
67
68 void Dialogs::show(string const & name, string const & data, Inset * inset)
69 {
70         if (in_show_) {
71                 return;
72         }
73         in_show_ = true;
74         Dialog * dialog = find_or_build(name);
75         if (dialog) {
76                 // FIXME! Should check that the dialog IS an inset dialog.
77                 dialog->show(data);
78                 open_insets_[name] = inset;
79         }
80         in_show_ = false;
81 }
82
83
84 bool Dialogs::visible(string const & name) const
85 {
86         std::map<string, DialogPtr>::const_iterator it =
87                 dialogs_.find(name);
88         if (it == dialogs_.end())
89                 return false;
90         return it->second.get()->isVisible();
91 }
92
93
94 void Dialogs::update(string const & name, string const & data)
95 {
96         std::map<string, DialogPtr>::const_iterator it =
97                 dialogs_.find(name);
98         if (it == dialogs_.end())
99                 return;
100
101         Dialog * const dialog = it->second.get();
102         if (dialog->isVisible())
103                 dialog->update(data);
104 }
105
106
107 void Dialogs::hide(string const & name, Inset* inset)
108 {
109         // Don't send the signal if we are quitting, because on MSVC it is
110         // destructed before the cut stack in CutAndPaste.cpp, and this method
111         // is called from some inset destructor if the cut stack is not empty
112         // on exit.
113         if (quitting)
114                 return;
115
116         std::map<string, DialogPtr>::const_iterator it =
117                 dialogs_.find(name);
118         if (it == dialogs_.end())
119                 return;
120
121         if (inset && inset != getOpenInset(name))
122                 return;
123
124         Dialog * const dialog = it->second.get();
125         if (dialog->isVisible())
126                 dialog->hide();
127         open_insets_[name] = 0;
128 }
129
130
131 void Dialogs::disconnect(string const & name)
132 {
133         if (!isValidName(name))
134                 return;
135
136         if (open_insets_.find(name) != open_insets_.end())
137                 open_insets_[name] = 0;
138 }
139
140
141 Inset * Dialogs::getOpenInset(string const & name) const
142 {
143         if (!isValidName(name))
144                 return 0;
145
146         std::map<string, Inset *>::const_iterator it =
147                 open_insets_.find(name);
148         return it == open_insets_.end() ? 0 : it->second;
149 }
150
151
152 void Dialogs::hideAll() const
153 {
154         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
155         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
156
157         for(; it != end; ++it) {
158                 it->second->hide();
159         }
160 }
161
162
163 void Dialogs::hideBufferDependent() const
164 {
165         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
166         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
167
168         for(; it != end; ++it) {
169                 Dialog * dialog =  it->second.get();
170                 if (dialog->controller().isBufferDependent())
171                         dialog->hide();
172         }
173 }
174
175
176 void Dialogs::updateBufferDependent(bool switched) const
177 {
178         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
179         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
180
181         for(; it != end; ++it) {
182                 Dialog * dialog =  it->second.get();
183                 if (switched && dialog->controller().isBufferDependent()) {
184                         if (dialog->isVisible() && dialog->controller().initialiseParams(""))
185                                 dialog->view().update();
186                         else
187                                 dialog->hide();
188                 } else {
189                         // A bit clunky, but the dialog will request
190                         // that the kernel provides it with the necessary
191                         // data.
192                         dialog->RestoreButton();
193                 }
194         }
195 }
196
197
198 void Dialogs::redraw() 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                 it->second->redraw();
205         }
206 }
207
208
209 void Dialogs::checkStatus()
210 {
211         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
212         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
213
214         for(; it != end; ++it) {
215                 Dialog * const dialog = it->second.get();
216                 if (dialog->isVisible())
217                         dialog->checkStatus();
218         }
219 }
220
221
222 } // namespace lyx