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"
36 using namespace lyx::support;
42 Dialog::Dialog(GuiView & lv, QString const & name, QString const & title)
43 : name_(name), title_(title), lyxview_(&lv)
51 bool Dialog::canApply() const
53 FuncRequest const fr(getLfun(), fromqstr(name_));
54 FuncStatus const fs(getStatus(fr));
59 void Dialog::dispatch(FuncRequest const & fr) const
65 void Dialog::updateDialog() const
67 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
71 void Dialog::disconnect() const
73 lyxview_->disconnectDialog(fromqstr(name_));
77 bool Dialog::isBufferAvailable() const
79 return lyxview_->currentBufferView() != 0;
83 bool Dialog::isBufferReadonly() const
85 if (!lyxview_->documentBufferView())
87 return lyxview_->documentBufferView()->buffer().isReadonly();
91 QString Dialog::bufferFilepath() const
93 return toqstr(buffer().filePath());
97 KernelDocType Dialog::docType() const
99 if (buffer().isLatex())
101 if (buffer().isLiterate())
108 BufferView const * Dialog::bufferview() const
110 return lyxview_->currentBufferView();
114 Buffer const & Dialog::buffer() const
116 LASSERT(lyxview_->currentBufferView(), /**/);
117 return lyxview_->currentBufferView()->buffer();
121 void Dialog::showData(string const & data)
123 if (isBufferDependent() && !isBufferAvailable())
126 if (!initialiseParams(data)) {
127 LYXERR0("Dialog \"" << name()
128 << "\" failed to translate the data string passed to show()");
138 if (isBufferDependent()) {
139 if (!isBufferAvailable() ||
140 (isBufferReadonly() && !canApplyToReadOnly()))
147 if (disconnectOnApply() && !isClosing()) {
149 initialiseParams(string());
155 void Dialog::prepareView()
157 // Make sure the dialog controls are correctly enabled/disabled with
161 QWidget * w = asQWidget();
162 w->setWindowTitle(title_);
164 QSize const hint = w->sizeHint();
165 if (hint.height() >= 0 && hint.width() >= 0)
166 w->setMinimumSize(hint);
170 void Dialog::showView()
174 QWidget * w = asQWidget();
175 if (w->isVisible()) {
181 if (wantInitialFocus())
185 lyxview_->activateWindow();
186 lyxview_->setFocus();
191 void Dialog::hideView()
193 QWidget * w = asQWidget();
202 bool Dialog::isVisibleView() const
204 return asQWidget()->isVisible();
208 Inset const * Dialog::inset(InsetCode code) const
210 Inset * ins = bufferview()->cursor().innerInsetOfType(code);
212 ins = bufferview()->cursor().nextInset();
213 if (!ins || ins->lyxCode() != code)
219 void Dialog::checkStatus()
221 // buffer independent dialogs are always active.
222 // This check allows us leave canApply unimplemented for some dialogs.
223 if (!isBufferDependent()) {
228 // deactivate the dialog if we have no buffer
229 if (!isBufferAvailable()) {
234 // check whether this dialog may be active
236 bool const readonly = isBufferReadonly();
237 enableView(!readonly || canApplyToReadOnly());
238 // refreshReadOnly() is too generous in _enabling_ widgets
239 // update dialog to disable disabled widgets again
247 QString Dialog::sessionKey() const
249 return "views/" + QString::number(lyxview_->id())
254 void Dialog::saveSession() const
257 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
261 void Dialog::restoreSession()
264 asQWidget()->restoreGeometry(
265 settings.value(sessionKey() + "/geometry").toByteArray());
268 } // namespace frontend