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 "BufferView.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
25 #include "insets/Inset.h"
27 #include "support/debug.h"
28 #include "support/lassert.h"
40 using namespace lyx::support;
45 bool CheckedLineEdit2::check() const
47 bool const valid = input_->hasAcceptableInput();
49 setValid(input_, valid);
51 setValid(label_, valid);
56 Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
57 : name_(name), title_(title), lyxview_(&lv)
65 void Dialog::addCheckedWidget(QLineEdit * input, QWidget * label)
67 checked_line_edits_.append(CheckedLineEdit2(input, label));
71 bool Dialog::checkWidgets() const
74 Q_FOREACH(CheckedLineEdit2 const & le, checked_line_edits_)
80 bool Dialog::canApply() const
82 FuncRequest const fr(getLfun(), fromqstr(name_));
83 FuncStatus const fs(getStatus(fr));
88 void Dialog::dispatch(FuncRequest const & fr) const
94 void Dialog::updateDialog() const
96 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
100 void Dialog::disconnect() const
102 lyxview_->disconnectDialog(fromqstr(name_));
106 bool Dialog::isBufferAvailable() const
108 return lyxview_->currentBufferView() != 0;
112 bool Dialog::isBufferReadonly() const
114 if (!lyxview_->documentBufferView())
116 return lyxview_->documentBufferView()->buffer().isReadonly();
120 QString Dialog::bufferFilepath() const
122 return toqstr(buffer().filePath());
126 KernelDocType Dialog::docType() const
128 if (buffer().isLatex())
130 if (buffer().isLiterate())
137 BufferView const * Dialog::bufferview() const
139 return lyxview_->currentBufferView();
143 Buffer const & Dialog::buffer() const
145 LASSERT(lyxview_->currentBufferView(), /**/);
146 return lyxview_->currentBufferView()->buffer();
150 void Dialog::showData(string const & data)
152 if (isBufferDependent() && !isBufferAvailable())
155 if (!initialiseParams(data)) {
156 LYXERR0("Dialog \"" << name()
157 << "\" failed to translate the data string passed to show()");
167 if (isBufferDependent()) {
168 if (!isBufferAvailable() ||
169 (isBufferReadonly() && !canApplyToReadOnly()))
176 if (disconnectOnApply() && !isClosing()) {
178 initialiseParams(string());
184 void Dialog::prepareView()
186 // Make sure the dialog controls are correctly enabled/disabled with
190 QWidget * w = asQWidget();
191 w->setWindowTitle(title_);
193 QSize const hint = w->sizeHint();
194 if (hint.height() >= 0 && hint.width() >= 0)
195 w->setMinimumSize(hint);
199 void Dialog::showView()
203 QWidget * w = asQWidget();
204 if (w->isVisible()) {
210 if (wantInitialFocus())
214 lyxview_->activateWindow();
215 lyxview_->setFocus();
220 void Dialog::hideView()
222 QWidget * w = asQWidget();
231 bool Dialog::isVisibleView() const
233 return asQWidget()->isVisible();
237 Inset const * Dialog::inset(InsetCode code) const
239 Inset * ins = bufferview()->cursor().innerInsetOfType(code);
241 ins = bufferview()->cursor().nextInset();
242 if (!ins || ins->lyxCode() != code)
248 void Dialog::checkStatus()
250 // buffer independent dialogs are always active.
251 // This check allows us leave canApply unimplemented for some dialogs.
252 if (!isBufferDependent()) {
257 // deactivate the dialog if we have no buffer
258 if (!isBufferAvailable()) {
263 // check whether this dialog may be active
265 bool const readonly = isBufferReadonly();
266 enableView(!readonly || canApplyToReadOnly());
267 // refreshReadOnly() is too generous in _enabling_ widgets
268 // update dialog to disable disabled widgets again
276 QString Dialog::sessionKey() const
278 return "views/" + QString::number(lyxview_->id())
283 void Dialog::saveSession() const
286 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
290 void Dialog::restoreSession()
293 asQWidget()->restoreGeometry(
294 settings.value(sessionKey() + "/geometry").toByteArray());
297 } // namespace frontend