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 "support/lassert.h"
33 using namespace lyx::support;
39 Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
40 : name_(name), title_(title), lyxview_(&lv)
48 bool Dialog::canApply() const
50 FuncRequest const fr(getLfun(), fromqstr(name_));
51 FuncStatus const fs(getStatus(fr));
56 void Dialog::dispatch(FuncRequest const & fr) const
58 theLyXFunc().setLyXView(lyxview_);
63 void Dialog::updateDialog() const
65 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
69 void Dialog::disconnect() const
71 lyxview_->disconnectDialog(fromqstr(name_));
75 bool Dialog::isBufferAvailable() const
77 return lyxview_->buffer() != 0;
81 bool Dialog::isBufferReadonly() const
83 if (!lyxview_->buffer())
85 return lyxview_->buffer()->isReadonly();
89 QString Dialog::bufferFilepath() const
91 return toqstr(buffer().filePath());
95 KernelDocType Dialog::docType() const
97 if (buffer().isLatex())
99 if (buffer().isLiterate())
106 BufferView * Dialog::bufferview()
108 return lyxview_->view();
112 BufferView const * Dialog::bufferview() const
114 return lyxview_->view();
118 Buffer & Dialog::buffer()
120 LASSERT(lyxview_->buffer(), /**/);
121 return *lyxview_->buffer();
125 Buffer const & Dialog::buffer() const
127 LASSERT(lyxview_->buffer(), /**/);
128 return *lyxview_->buffer();
132 void Dialog::showData(string const & data)
134 if (isBufferDependent() && !isBufferAvailable())
137 if (!initialiseParams(data)) {
138 LYXERR0("Dialog \"" << name()
139 << "\" failed to translate the data string passed to show()");
149 if (isBufferDependent()) {
150 if (!isBufferAvailable() ||
151 (isBufferReadonly() && !canApplyToReadOnly()))
158 if (disconnectOnApply() && !isClosing()) {
160 initialiseParams(string());
166 void Dialog::showView()
168 // Make sure the dialog controls are correctly enabled/disabled with
174 QWidget * w = asQWidget();
175 w->setWindowTitle(title_);
177 QSize const hint = w->sizeHint();
178 if (hint.height() >= 0 && hint.width() >= 0)
179 w->setMinimumSize(hint);
181 if (w->isVisible()) {
191 void Dialog::hideView()
193 QWidget * w = asQWidget();
202 bool Dialog::isVisibleView() const
204 return asQWidget()->isVisible();
208 void Dialog::checkStatus()
210 // buffer independant dialogs are always active.
211 // This check allows us leave canApply unimplemented for some dialogs.
212 if (!isBufferDependent())
215 // deactivate the dialog if we have no buffer
216 if (!isBufferAvailable()) {
221 // check whether this dialog may be active
223 bool const readonly = isBufferReadonly();
224 enableView(!readonly);
225 // refreshReadOnly() is too generous in _enabling_ widgets
226 // update dialog to disable disabled widgets again
228 if (!readonly || canApplyToReadOnly())
236 QString Dialog::sessionKey() const
238 return "view-" + QString::number(lyxview_->id())
243 void Dialog::saveSession() const
246 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
250 void Dialog::restoreSession()
253 asQWidget()->restoreGeometry(
254 settings.value(sessionKey() + "/geometry").toByteArray());
257 } // namespace frontend