]> git.lyx.org Git - lyx.git/blob - src/frontends/Dialogs.cpp
Move Color::color enum to ColorCode.h
[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 "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 = dialogs_.find(name);
69         if (it == dialogs_.end())
70                 return false;
71         return it->second.get()->isVisibleView();
72 }
73
74
75 void Dialogs::update(string const & name, string const & data)
76 {
77         std::map<string, DialogPtr>::const_iterator it = dialogs_.find(name);
78         if (it == dialogs_.end())
79                 return;
80
81         Dialog * const dialog = it->second.get();
82         if (dialog->isVisibleView())
83                 dialog->updateData(data);
84 }
85
86
87 void Dialogs::hide(string const & name, Inset* inset)
88 {
89         // Don't send the signal if we are quitting, because on MSVC it is
90         // destructed before the cut stack in CutAndPaste.cpp, and this method
91         // is called from some inset destructor if the cut stack is not empty
92         // on exit.
93         if (quitting)
94                 return;
95
96         std::map<string, DialogPtr>::const_iterator it =
97                 dialogs_.find(name);
98         if (it == dialogs_.end())
99                 return;
100
101         if (inset && inset != getOpenInset(name))
102                 return;
103
104         Dialog * const dialog = it->second.get();
105         if (dialog->isVisibleView())
106                 dialog->hide();
107         open_insets_[name] = 0;
108 }
109
110
111 void Dialogs::disconnect(string const & name)
112 {
113         if (!isValidName(name))
114                 return;
115
116         if (open_insets_.find(name) != open_insets_.end())
117                 open_insets_[name] = 0;
118 }
119
120
121 Inset * Dialogs::getOpenInset(string const & name) const
122 {
123         if (!isValidName(name))
124                 return 0;
125
126         std::map<string, Inset *>::const_iterator it =
127                 open_insets_.find(name);
128         return it == open_insets_.end() ? 0 : it->second;
129 }
130
131
132 void Dialogs::hideAll() const
133 {
134         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
135         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
136
137         for(; it != end; ++it)
138                 it->second->hide();
139 }
140
141
142 void Dialogs::hideBufferDependent() const
143 {
144         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
145         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
146
147         for(; it != end; ++it) {
148                 Dialog * dialog = it->second.get();
149                 if (dialog->isBufferDependent())
150                         dialog->hide();
151         }
152 }
153
154
155 void Dialogs::updateBufferDependent(bool switched) const
156 {
157         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
158         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
159
160         for(; it != end; ++it) {
161                 Dialog * dialog = it->second.get();
162                 if (switched && dialog->isBufferDependent()) {
163                         if (dialog->isVisibleView() && dialog->initialiseParams(""))
164                                 dialog->updateView();
165                         else
166                                 dialog->hide();
167                 } else {
168                         // A bit clunky, but the dialog will request
169                         // that the kernel provides it with the necessary
170                         // data.
171                         dialog->slotRestore();
172                 }
173         }
174 }
175
176
177 void Dialogs::redraw() const
178 {
179         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
180         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
181
182         for(; it != end; ++it)
183                 it->second->redraw();
184 }
185
186
187 void Dialogs::checkStatus()
188 {
189         std::map<string, DialogPtr>::const_iterator it  = dialogs_.begin();
190         std::map<string, DialogPtr>::const_iterator end = dialogs_.end();
191
192         for(; it != end; ++it) {
193                 Dialog * const dialog = it->second.get();
194                 if (dialog && dialog->isVisibleView())
195                         dialog->checkStatus();
196         }
197 }
198
199 } // namespace frontend
200 } // namespace lyx