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 \"" << fromqstr(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::updateData(string const & data)
168 if (!initialiseParams(data)) {
169 LYXERR0("Dialog \"" << fromqstr(name())
170 << "\" could not be initialized");
174 if (lyxview_->buffer())
181 void Dialog::showView()
183 // Make sure the dialog controls are correctly enabled/disabled with
189 QWidget * w = asQWidget();
190 w->setWindowTitle(title_);
192 QSize const hint = w->sizeHint();
193 if (hint.height() >= 0 && hint.width() >= 0)
194 w->setMinimumSize(hint);
196 if (w->isVisible()) {
206 void Dialog::hideView()
208 QWidget * w = asQWidget();
217 bool Dialog::isVisibleView() const
219 return asQWidget()->isVisible();
223 void Dialog::checkStatus()
225 // buffer independant dialogs are always active.
226 // This check allows us leave canApply unimplemented for some dialogs.
227 if (!isBufferDependent())
230 // deactivate the dialog if we have no buffer
231 if (!isBufferAvailable()) {
236 // check whether this dialog may be active
238 bool const readonly = isBufferReadonly();
239 enableView(!readonly);
240 // refreshReadOnly() is too generous in _enabling_ widgets
241 // update dialog to disable disabled widgets again
243 if (!readonly || canApplyToReadOnly())
251 QString Dialog::sessionKey() const
253 return "view-" + QString::number(lyxview_->id())
258 void Dialog::saveSession() const
261 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
265 void Dialog::restoreSession()
268 asQWidget()->restoreGeometry(
269 settings.value(sessionKey() + "/geometry").toByteArray());
272 } // namespace frontend