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