]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.C
s/DocumentIterator/DocIterator/g a.k.a showing off my sed abilities. Sorry for the...
[lyx.git] / src / frontends / controllers / Dialog.C
1 /**
2  * \file Dialog.C
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
11 #include <config.h>
12
13 #include "Dialog.h"
14
15 #include "ButtonController.h"
16 #include "BCView.h"
17
18
19 using std::string;
20
21
22 Dialog::Dialog(LyXView & lv, string const & name)
23         : is_closing_(false), kernel_(lv), name_(name),
24           bc_ptr_(new ButtonController)
25 {}
26
27
28 Dialog::~Dialog()
29 {}
30
31
32 void Dialog::ApplyButton()
33 {
34         apply();
35         bc().apply();
36 }
37
38
39 void Dialog::OKButton()
40 {
41         is_closing_ = true;
42         apply();
43         is_closing_ = false;
44         hide();
45         bc().ok();
46 }
47
48
49 void Dialog::CancelButton()
50 {
51         hide();
52         bc().cancel();
53 }
54
55
56 void Dialog::RestoreButton()
57 {
58         // Tell the kernel that a request to refresh the dialog's contents
59         // has been received. It's up to the kernel to supply the necessary
60         // info by calling Dialog::update().
61         kernel().updateDialog(name_);
62         bc().restore();
63 }
64
65
66 void Dialog::show(string const & data)
67 {
68         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
69                 return;
70
71         if (!controller().initialiseParams(data)) {
72                 lyxerr << "Dialog \"" << name_
73                        << "\" failed to translate the data "
74                         "string passed to show()" << std::endl;
75                 return;
76         }
77
78         bc().readOnly(kernel().isBufferReadonly());
79         view().show();
80
81         // The widgets may not be valid, so refresh the button controller
82         bc().refresh();
83 }
84
85
86 void Dialog::update(string const & data)
87 {
88         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
89                 return;
90
91         if (!controller().initialiseParams(data)) {
92                 lyxerr << "Dialog \"" << name_
93                        << "\" failed to translate the data "
94                         "string passed to update()" << std::endl;
95                 return;
96         }
97
98         bc().readOnly(kernel().isBufferReadonly());
99         view().update();
100
101         // The widgets may not be valid, so refresh the button controller
102         bc().refresh();
103 }
104
105
106 void Dialog::hide()
107 {
108         if (!view().isVisible())
109                 return;
110
111         controller().clearParams();
112         view().hide();
113         kernel().disconnect(name());
114 }
115
116
117 void Dialog::apply()
118 {
119         if (controller().isBufferDependent()) {
120                 if (!kernel().isBufferAvailable() ||
121                     kernel().isBufferReadonly())
122                         return;
123         }
124
125         view().apply();
126         controller().dispatchParams();
127
128         if (controller().disconnectOnApply() && !is_closing_) {
129                 kernel().disconnect(name());
130                 controller().initialiseParams(string());
131                 view().update();
132         }
133 }
134
135
136 bool Dialog::isVisible() const
137 {
138         return view().isVisible();
139 }
140
141
142 void Dialog::redraw()
143 {
144         view().redraw();
145 }
146
147
148 ButtonController & Dialog::bc() const
149 {
150         BOOST_ASSERT(bc_ptr_.get());
151         return *bc_ptr_.get();
152 }
153
154
155 void Dialog::setController(Controller * i)
156 {
157         BOOST_ASSERT(i && !controller_ptr_.get());
158         controller_ptr_.reset(i);
159 }
160
161
162 void Dialog::setView(View * v)
163 {
164         BOOST_ASSERT(v && !view_ptr_.get());
165         view_ptr_.reset(v);
166 }
167
168
169 Dialog::Controller::Controller(Dialog & parent)
170         : parent_(parent)
171 {}
172
173
174 Dialog::Controller & Dialog::controller() const
175 {
176         BOOST_ASSERT(controller_ptr_.get());
177         return *controller_ptr_.get();
178 }
179
180
181 Dialog::View::View(Dialog & parent, string title) :
182         p_(parent), title_(title)
183 {}
184
185
186 Dialog::View & Dialog::view() const
187 {
188         BOOST_ASSERT(view_ptr_.get());
189         return *view_ptr_.get();
190 }
191
192
193 void Dialog::View::setTitle(string const & newtitle)
194 {
195         title_ = newtitle;
196 }
197
198
199 string const & Dialog::View::getTitle() const
200 {
201         return title_;
202 }
203
204
205 void Dialog::View::partialUpdate(int)
206 {}