]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.cpp
make lyx compile
[lyx.git] / src / frontends / controllers / Dialog.cpp
1 /**
2  * \file Dialog.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
11 #include <config.h>
12
13 #include "Dialog.h"
14
15 #include "frontends/LyXView.h"
16
17 #include "debug.h"
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
20 #include "LyXFunc.h"
21
22
23 using std::string;
24
25 namespace lyx {
26 namespace frontend {
27
28 Dialog::Dialog(LyXView & lv, string const & name)
29         : is_closing_(false), kernel_(lv), name_(name)
30 {}
31
32
33 Dialog::~Dialog()
34 {}
35
36
37 void Dialog::setButtonsValid(bool valid)
38 {}
39
40
41 void Dialog::show(string const & data)
42 {
43         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
44                 return;
45
46         if (!controller().initialiseParams(data)) {
47                 lyxerr << "Dialog \"" << name_
48                        << "\" failed to translate the data "
49                         "string passed to show()" << std::endl;
50                 return;
51         }
52
53         preShow();
54         view().show();
55         postShow();
56 }
57
58
59 void Dialog::update(string const & data)
60 {
61         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
62                 return;
63
64         if (!controller().initialiseParams(data)) {
65                 lyxerr << "Dialog \"" << name_
66                        << "\" could not be initialized" << std::endl;
67                 return;
68         }
69
70         preUpdate();
71         view().update();
72         postUpdate();
73 }
74
75
76 void Dialog::checkStatus()
77 {
78 }
79
80
81 void Dialog::hide()
82 {
83         if (!view().isVisible())
84                 return;
85
86         controller().clearParams();
87         view().hide();
88         kernel().disconnect(name());
89 }
90
91
92 void Dialog::apply()
93 {
94         if (controller().isBufferDependent()) {
95                 if (!kernel().isBufferAvailable() ||
96                     (kernel().isBufferReadonly() &&
97                      !controller().canApplyToReadOnly()))
98                         return;
99         }
100
101         view().apply();
102         controller().dispatchParams();
103
104         if (controller().disconnectOnApply() && !is_closing_) {
105                 kernel().disconnect(name());
106                 controller().initialiseParams(string());
107                 view().update();
108         }
109 }
110
111
112 bool Dialog::isVisible() const
113 {
114         return view().isVisible();
115 }
116
117
118 void Dialog::redraw()
119 {
120         view().redraw();
121 }
122
123
124 void Dialog::setController(Controller * i)
125 {
126         BOOST_ASSERT(i && !controller_ptr_.get());
127         controller_ptr_.reset(i);
128 }
129
130
131 void Dialog::setView(View * v)
132 {
133         BOOST_ASSERT(v && !view_ptr_.get());
134         view_ptr_.reset(v);
135 }
136
137
138
139 Dialog::Controller::Controller(Dialog & parent)
140         : parent_(parent)
141 {}
142
143
144 bool Dialog::Controller::canApply() const
145 {
146         FuncRequest const fr(getLfun(), dialog().name());
147         FuncStatus const fs(getStatus(fr));
148         return fs.enabled();
149 }
150
151
152 Dialog::Controller & Dialog::controller() const
153 {
154         BOOST_ASSERT(controller_ptr_.get());
155         return *controller_ptr_.get();
156 }
157
158
159 Dialog::View::View(Dialog & parent, docstring title) :
160         p_(parent), title_(title)
161 {}
162
163
164 Dialog::View & Dialog::view() const
165 {
166         BOOST_ASSERT(view_ptr_.get());
167         return *view_ptr_.get();
168 }
169
170
171 void Dialog::View::setTitle(docstring const & newtitle)
172 {
173         title_ = newtitle;
174 }
175
176
177 docstring const & Dialog::View::getTitle() const
178 {
179         return title_;
180 }
181
182
183 void Dialog::View::partialUpdate(int)
184 {}
185
186 } // namespace frontend
187 } // namespace lyx