3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
13 #include "GuiDialog.h"
15 #include "qt_helpers.h"
16 #include "frontends/LyXView.h"
23 GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
24 : is_closing_(false), name_(name), controller_(0)
30 GuiDialog::~GuiDialog()
36 void GuiDialog::setViewTitle(docstring const & title)
38 setWindowTitle("LyX: " + toqstr(title));
42 void GuiDialog::setButtonsValid(bool valid)
48 void GuiDialog::slotApply()
55 void GuiDialog::slotOK()
65 void GuiDialog::slotClose()
72 void GuiDialog::slotRestore()
74 // Tell the controller that a request to refresh the dialog's contents
75 // has been received. It's up to the controller to supply the necessary
76 // info by calling GuiDialog::updateView().
77 controller().updateDialog(name_);
81 void GuiDialog::checkStatus()
83 // buffer independant dialogs are always active.
84 // This check allows us leave canApply unimplemented for some dialogs.
85 if (!controller().isBufferDependent())
88 // deactivate the dialog if we have no buffer
89 if (!controller().isBufferAvailable()) {
90 bc().setReadOnly(true);
94 // check whether this dialog may be active
95 if (controller().canApply()) {
96 bool const readonly = controller().isBufferReadonly();
97 bc().setReadOnly(readonly);
98 // refreshReadOnly() is too generous in _enabling_ widgets
99 // update dialog to disable disabled widgets again
102 if (!readonly || controller().canApplyToReadOnly())
106 bc().setReadOnly(true);
111 bool GuiDialog::isVisibleView() const
113 return QDialog::isVisible();
117 bool GuiDialog::readOnly() const
119 return controller().isBufferReadonly();
123 void GuiDialog::showView()
125 QSize const hint = sizeHint();
126 if (hint.height() >= 0 && hint.width() >= 0)
127 setMinimumSize(hint);
129 updateView(); // make sure its up-to-date
130 if (controller().exitEarly())
133 if (QWidget::isVisible()) {
143 void GuiDialog::hideView()
149 void GuiDialog::changed()
153 bc().setValid(isValid());
157 void GuiDialog::updateView()
159 setUpdatesEnabled(false);
161 // protect the BC from unwarranted state transitions
166 setUpdatesEnabled(true);
171 void GuiDialog::showData(string const & data)
173 if (controller().isBufferDependent() && !controller().isBufferAvailable())
176 if (!controller().initialiseParams(data)) {
177 lyxerr << "Dialog \"" << name_
178 << "\" failed to translate the data "
179 "string passed to show()" << std::endl;
183 bc().setReadOnly(controller().isBufferReadonly());
185 // The widgets may not be valid, so refresh the button controller
190 void GuiDialog::updateData(string const & data)
192 if (controller().isBufferDependent() && !controller().isBufferAvailable())
195 if (!controller().initialiseParams(data)) {
196 lyxerr << "Dialog \"" << name_
197 << "\" could not be initialized" << std::endl;
201 bc().setReadOnly(controller().isBufferReadonly());
203 // The widgets may not be valid, so refresh the button controller
208 void GuiDialog::hide()
210 if (!isVisibleView())
213 controller().clearParams();
215 controller().disconnect(name_);
219 void GuiDialog::apply()
221 if (controller().isBufferDependent()) {
222 if (!controller().isBufferAvailable() ||
223 (controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
228 controller().dispatchParams();
230 if (controller().disconnectOnApply() && !is_closing_) {
231 controller().disconnect(name_);
232 controller().initialiseParams(string());
238 void GuiDialog::setController(Controller * controller)
240 BOOST_ASSERT(controller);
241 BOOST_ASSERT(!controller_);
242 controller_ = controller;
243 controller_->setLyXView(*lyxview_);
247 } // namespace frontend
250 #include "GuiDialog_moc.cpp"