]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.C
Removed another historical artefact.
[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                        << "\" could not be initialized" << std::endl;
94                 return;
95         }
96
97         bc().readOnly(kernel().isBufferReadonly());
98         view().update();
99
100         // The widgets may not be valid, so refresh the button controller
101         bc().refresh();
102 }
103
104
105 void Dialog::hide()
106 {
107         if (!view().isVisible())
108                 return;
109
110         controller().clearParams();
111         view().hide();
112         kernel().disconnect(name());
113 }
114
115
116 void Dialog::apply()
117 {
118         if (controller().isBufferDependent()) {
119                 if (!kernel().isBufferAvailable() ||
120                     kernel().isBufferReadonly())
121                         return;
122         }
123
124         view().apply();
125         controller().dispatchParams();
126
127         if (controller().disconnectOnApply() && !is_closing_) {
128                 kernel().disconnect(name());
129                 controller().initialiseParams(string());
130                 view().update();
131         }
132 }
133
134
135 bool Dialog::isVisible() const
136 {
137         return view().isVisible();
138 }
139
140
141 void Dialog::redraw()
142 {
143         view().redraw();
144 }
145
146
147 ButtonController & Dialog::bc() const
148 {
149         BOOST_ASSERT(bc_ptr_.get());
150         return *bc_ptr_.get();
151 }
152
153
154 void Dialog::setController(Controller * i)
155 {
156         BOOST_ASSERT(i && !controller_ptr_.get());
157         controller_ptr_.reset(i);
158 }
159
160
161 void Dialog::setView(View * v)
162 {
163         BOOST_ASSERT(v && !view_ptr_.get());
164         view_ptr_.reset(v);
165 }
166
167
168 Dialog::Controller::Controller(Dialog & parent)
169         : parent_(parent)
170 {}
171
172
173 Dialog::Controller & Dialog::controller() const
174 {
175         BOOST_ASSERT(controller_ptr_.get());
176         return *controller_ptr_.get();
177 }
178
179
180 Dialog::View::View(Dialog & parent, string title) :
181         p_(parent), title_(title)
182 {}
183
184
185 Dialog::View & Dialog::view() const
186 {
187         BOOST_ASSERT(view_ptr_.get());
188         return *view_ptr_.get();
189 }
190
191
192 void Dialog::View::setTitle(string const & newtitle)
193 {
194         title_ = newtitle;
195 }
196
197
198 string const & Dialog::View::getTitle() const
199 {
200         return title_;
201 }
202
203
204 void Dialog::View::partialUpdate(int)
205 {}