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"
24 #include "support/lassert.h"
32 using namespace lyx::support;
38 Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
39 : name_(name), title_(title), lyxview_(&lv)
47 bool Dialog::canApply() const
49 FuncRequest const fr(getLfun(), fromqstr(name_));
50 FuncStatus const fs(getStatus(fr));
55 void Dialog::dispatch(FuncRequest const & fr) const
57 theLyXFunc().setLyXView(lyxview_);
62 void Dialog::updateDialog() const
64 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
68 void Dialog::disconnect() const
70 lyxview_->disconnectDialog(fromqstr(name_));
74 bool Dialog::isBufferAvailable() const
76 return lyxview_->buffer() != 0;
80 bool Dialog::isBufferReadonly() const
82 if (!lyxview_->buffer())
84 return lyxview_->buffer()->isReadonly();
88 QString Dialog::bufferFilepath() const
90 return toqstr(buffer().filePath());
94 KernelDocType Dialog::docType() const
96 if (buffer().isLatex())
98 if (buffer().isLiterate())
105 BufferView * Dialog::bufferview()
107 return lyxview_->view();
111 BufferView const * Dialog::bufferview() const
113 return lyxview_->view();
117 Buffer & Dialog::buffer()
119 LASSERT(lyxview_->buffer(), /**/);
120 return *lyxview_->buffer();
124 Buffer const & Dialog::buffer() const
126 LASSERT(lyxview_->buffer(), /**/);
127 return *lyxview_->buffer();
131 void Dialog::showData(string const & data)
133 if (isBufferDependent() && !isBufferAvailable())
136 if (!initialiseParams(data)) {
137 LYXERR0("Dialog \"" << name()
138 << "\" failed to translate the data string passed to show()");
148 if (isBufferDependent()) {
149 if (!isBufferAvailable() ||
150 (isBufferReadonly() && !canApplyToReadOnly()))
157 if (disconnectOnApply() && !isClosing()) {
159 initialiseParams(string());
165 void Dialog::showView()
167 // Make sure the dialog controls are correctly enabled/disabled with
173 QWidget * w = asQWidget();
174 w->setWindowTitle(title_);
176 QSize const hint = w->sizeHint();
177 if (hint.height() >= 0 && hint.width() >= 0)
178 w->setMinimumSize(hint);
180 if (w->isVisible()) {
190 void Dialog::hideView()
192 QWidget * w = asQWidget();
201 bool Dialog::isVisibleView() const
203 return asQWidget()->isVisible();
207 void Dialog::checkStatus()
209 // buffer independant dialogs are always active.
210 // This check allows us leave canApply unimplemented for some dialogs.
211 if (!isBufferDependent()) {
216 // deactivate the dialog if we have no buffer
217 if (!isBufferAvailable()) {
222 // check whether this dialog may be active
224 bool const readonly = isBufferReadonly();
225 enableView(!readonly);
226 // refreshReadOnly() is too generous in _enabling_ widgets
227 // update dialog to disable disabled widgets again
229 if (!readonly || canApplyToReadOnly())
237 QString Dialog::sessionKey() const
239 return "view-" + QString::number(lyxview_->id())
244 void Dialog::saveSession() const
247 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
251 void Dialog::restoreSession()
254 asQWidget()->restoreGeometry(
255 settings.value(sessionKey() + "/geometry").toByteArray());
258 } // namespace frontend