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