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