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