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 "BufferParams.h"
20 #include "BufferView.h"
22 #include "FuncRequest.h"
23 #include "FuncStatus.h"
26 #include "insets/Inset.h"
28 #include "support/debug.h"
29 #include "support/lassert.h"
41 using namespace lyx::support;
46 Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
47 : name_(name), title_(title), lyxview_(&lv)
55 bool Dialog::canApply() const
57 FuncRequest const fr(getLfun(), fromqstr(name_));
58 FuncStatus const fs(getStatus(fr));
63 void Dialog::dispatch(FuncRequest const & fr) const
69 void Dialog::updateDialog() const
71 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
75 void Dialog::disconnect() const
77 lyxview_->disconnectDialog(fromqstr(name_));
81 bool Dialog::isBufferAvailable() const
83 return lyxview_->currentBufferView() != 0;
87 bool Dialog::isBufferReadonly() const
89 if (!lyxview_->documentBufferView())
91 return lyxview_->documentBufferView()->buffer().isReadonly();
95 QString Dialog::bufferFilePath() const
97 return toqstr(buffer().filePath());
101 KernelDocType Dialog::docType() const
103 if (buffer().params().isLatex())
105 if (buffer().params().isLiterate())
112 BufferView const * Dialog::bufferview() const
114 return lyxview_->currentBufferView();
118 Buffer const & Dialog::buffer() const
120 LASSERT(lyxview_->currentBufferView(), /**/);
121 return lyxview_->currentBufferView()->buffer();
125 Buffer const & Dialog::documentBuffer() const
127 LASSERT(lyxview_->documentBufferView(), /**/);
128 return lyxview_->documentBufferView()->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::prepareView()
168 // Make sure the dialog controls are correctly enabled/disabled with
172 QWidget * w = asQWidget();
173 w->setWindowTitle(title_);
175 QSize const hint = w->sizeHint();
176 if (hint.height() >= 0 && hint.width() >= 0)
177 w->setMinimumSize(hint);
181 void Dialog::showView()
185 QWidget * w = asQWidget();
186 if (w->isVisible()) {
192 if (wantInitialFocus())
196 lyxview_->activateWindow();
197 lyxview_->setFocus();
202 void Dialog::hideView()
204 QWidget * w = asQWidget();
213 bool Dialog::isVisibleView() const
215 return asQWidget()->isVisible();
219 Inset const * Dialog::inset(InsetCode code) const
221 Inset * ins = bufferview()->cursor().innerInsetOfType(code);
223 ins = bufferview()->cursor().nextInset();
224 if (!ins || ins->lyxCode() != code)
230 void Dialog::checkStatus()
232 // buffer independent dialogs are always active.
233 // This check allows us leave canApply unimplemented for some dialogs.
234 if (!isBufferDependent()) {
239 // deactivate the dialog if we have no buffer
240 if (!isBufferAvailable()) {
245 // check whether this dialog may be active
247 bool const readonly = isBufferReadonly();
248 enableView(!readonly || canApplyToReadOnly());
249 // refreshReadOnly() is too generous in _enabling_ widgets
250 // update dialog to disable disabled widgets again
258 QString Dialog::sessionKey() const
260 return "views/" + QString::number(lyxview_->id())
265 void Dialog::saveSession() const
268 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
272 void Dialog::restoreSession()
275 asQWidget()->restoreGeometry(
276 settings.value(sessionKey() + "/geometry").toByteArray());
279 } // namespace frontend