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.
16 #include "qt_helpers.h"
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
23 #include "support/debug.h"
28 #include <boost/assert.hpp>
33 using namespace lyx::support;
39 Dialog::Dialog(GuiView & lv, string const & name, QString const & title)
40 : name_(name), title_(title), lyxview_(&lv)
48 string const & Dialog::name() const
54 bool Dialog::canApply() const
56 FuncRequest const fr(getLfun(), from_ascii(name_));
57 FuncStatus const fs(getStatus(fr));
62 void Dialog::dispatch(FuncRequest const & fr) const
64 theLyXFunc().setLyXView(lyxview_);
69 void Dialog::updateDialog() const
71 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, from_ascii(name_)));
75 void Dialog::disconnect() const
77 lyxview_->disconnectDialog(name_);
81 bool Dialog::isBufferAvailable() const
83 return lyxview_->buffer() != 0;
87 bool Dialog::isBufferReadonly() const
89 if (!lyxview_->buffer())
91 return lyxview_->buffer()->isReadonly();
95 string const Dialog::bufferFilepath() const
97 return buffer().filePath();
101 KernelDocType Dialog::docType() const
103 if (buffer().isLatex())
105 if (buffer().isLiterate())
112 BufferView * Dialog::bufferview()
114 return lyxview_->view();
118 BufferView const * Dialog::bufferview() const
120 return lyxview_->view();
124 Buffer & Dialog::buffer()
126 BOOST_ASSERT(lyxview_->buffer());
127 return *lyxview_->buffer();
131 Buffer const & Dialog::buffer() const
133 BOOST_ASSERT(lyxview_->buffer());
134 return *lyxview_->buffer();
138 void Dialog::showData(string const & data)
140 if (isBufferDependent() && !isBufferAvailable())
143 if (!initialiseParams(data)) {
144 LYXERR0("Dialog \"" << name()
145 << "\" failed to translate the data string passed to show()");
155 if (isBufferDependent()) {
156 if (!isBufferAvailable() ||
157 (isBufferReadonly() && !canApplyToReadOnly()))
164 if (disconnectOnApply() && !isClosing()) {
166 initialiseParams(string());
172 void Dialog::updateData(string const & data)
174 if (isBufferDependent() && !isBufferAvailable())
177 if (!initialiseParams(data)) {
178 LYXERR0("Dialog \"" << name()
179 << "\" could not be initialized");
187 void Dialog::showView()
189 // Make sure the dialog is up-to-date.
191 // Make sure the dialog controls are correctly enabled/disabled with
197 QWidget * w = asQWidget();
198 w->setWindowTitle(title_);
200 QSize const hint = w->sizeHint();
201 if (hint.height() >= 0 && hint.width() >= 0)
202 w->setMinimumSize(hint);
204 if (w->isVisible()) {
214 void Dialog::hideView()
216 QWidget * w = asQWidget();
225 bool Dialog::isVisibleView() const
227 return asQWidget()->isVisible();
231 void Dialog::checkStatus()
233 // buffer independant dialogs are always active.
234 // This check allows us leave canApply unimplemented for some dialogs.
235 if (!isBufferDependent())
238 // deactivate the dialog if we have no buffer
239 if (!isBufferAvailable()) {
244 // check whether this dialog may be active
246 bool const readonly = isBufferReadonly();
247 enableView(!readonly);
248 // refreshReadOnly() is too generous in _enabling_ widgets
249 // update dialog to disable disabled widgets again
251 if (!readonly || canApplyToReadOnly())
259 QString Dialog::sessionKey() const
261 return "view-" + QString::number(lyxview_->id())
262 + "/" + toqstr(name());
266 void Dialog::saveSession() const
269 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
273 void Dialog::restoreSession()
276 asQWidget()->restoreGeometry(
277 settings.value(sessionKey() + "/geometry").toByteArray());
280 } // namespace frontend