4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
16 #include "ButtonController.h"
19 #include "support/LAssert.h"
21 using namespace lyx::support;
23 Dialog::Dialog(LyXView & lv, string const & name)
24 : is_closing_(false), kernel_(lv), name_(name),
25 bc_ptr_(new ButtonController)
33 void Dialog::ApplyButton()
40 void Dialog::OKButton()
50 void Dialog::CancelButton()
57 void Dialog::RestoreButton()
59 // Tell the kernel that a request to refresh the dialog's contents
60 // has been received. It's up to the kernel to supply the necessary
61 // info by calling Dialog::update().
62 kernel().updateDialog(name_);
67 void Dialog::show(string const & data)
69 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
72 if (!controller().initialiseParams(data)) {
73 lyxerr << "Dialog \"" << name_
74 << "\" failed to translate the data "
75 "string passed to show()" << std::endl;
79 bc().readOnly(kernel().isBufferReadonly());
82 // The widgets may not be valid, so refresh the button controller
87 void Dialog::update(string const & data)
89 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
92 if (!controller().initialiseParams(data)) {
93 lyxerr << "Dialog \"" << name_
94 << "\" failed to translate the data "
95 "string passed to update()" << std::endl;
99 bc().readOnly(kernel().isBufferReadonly());
102 // The widgets may not be valid, so refresh the button controller
109 if (!view().isVisible())
112 controller().clearParams();
119 if (kernel().isBufferReadonly())
123 controller().dispatchParams();
125 if (controller().disconnectOnApply() && !is_closing_) {
126 kernel().disconnect(name());
127 controller().initialiseParams(string());
133 bool Dialog::isVisible() const
135 return view().isVisible();
139 void Dialog::redraw()
145 ButtonController & Dialog::bc() const
147 Assert(bc_ptr_.get());
148 return *bc_ptr_.get();
152 Dialog::Controller::Controller(Dialog & parent)
157 Dialog::Controller & Dialog::controller() const
159 Assert(controller_ptr_.get());
160 return *controller_ptr_.get();
164 Dialog::View::View(Dialog & parent, string title) :
165 p_(parent), title_(title)
169 Dialog::View & Dialog::view() const
171 Assert(view_ptr_.get());
172 return *view_ptr_.get();
176 void Dialog::View::setTitle(string const & newtitle)
182 string const & Dialog::View::getTitle() const
188 void Dialog::setController(Controller * i)
190 Assert(i && !controller_ptr_.get());
191 controller_ptr_.reset(i);
195 void Dialog::setView(View * v)
197 Assert(v && !view_ptr_.get());