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
61 theLyXFunc().setLyXView(lyxview_);
66 void Dialog::updateDialog() const
68 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_)));
72 void Dialog::disconnect() const
74 lyxview_->disconnectDialog(fromqstr(name_));
78 bool Dialog::isBufferAvailable() const
80 return lyxview_->buffer() != 0;
84 bool Dialog::isBufferReadonly() const
86 if (!lyxview_->buffer())
88 return lyxview_->buffer()->isReadonly();
92 QString Dialog::bufferFilepath() const
94 return toqstr(buffer().filePath());
98 KernelDocType Dialog::docType() const
100 if (buffer().isLatex())
102 if (buffer().isLiterate())
109 BufferView * Dialog::bufferview()
111 return lyxview_->view();
115 BufferView const * Dialog::bufferview() const
117 return lyxview_->view();
121 Buffer & Dialog::buffer()
123 LASSERT(lyxview_->buffer(), /**/);
124 return *lyxview_->buffer();
128 Buffer const & Dialog::buffer() const
130 LASSERT(lyxview_->buffer(), /**/);
131 return *lyxview_->buffer();
135 void Dialog::showData(string const & data)
137 if (isBufferDependent() && !isBufferAvailable())
140 if (!initialiseParams(data)) {
141 LYXERR0("Dialog \"" << name()
142 << "\" failed to translate the data string passed to show()");
152 if (isBufferDependent()) {
153 if (!isBufferAvailable() ||
154 (isBufferReadonly() && !canApplyToReadOnly()))
161 if (disconnectOnApply() && !isClosing()) {
163 initialiseParams(string());
169 void Dialog::showView()
171 // Make sure the dialog controls are correctly enabled/disabled with
177 QWidget * w = asQWidget();
178 w->setWindowTitle(title_);
180 QSize const hint = w->sizeHint();
181 if (hint.height() >= 0 && hint.width() >= 0)
182 w->setMinimumSize(hint);
184 if (w->isVisible()) {
190 if (wantInitialFocus())
194 lyxview_->activateWindow();
195 lyxview_->setFocus();
200 void Dialog::hideView()
202 QWidget * w = asQWidget();
211 bool Dialog::isVisibleView() const
213 return asQWidget()->isVisible();
217 Inset const * Dialog::inset(InsetCode code) const
219 Inset * ins = bufferview()->cursor().innerInsetOfType(code);
221 ins = bufferview()->cursor().nextInset();
222 if (!ins || ins->lyxCode() != code)
228 void Dialog::checkStatus()
230 // buffer independant dialogs are always active.
231 // This check allows us leave canApply unimplemented for some dialogs.
232 if (!isBufferDependent()) {
237 // deactivate the dialog if we have no buffer
238 if (!isBufferAvailable()) {
243 // check whether this dialog may be active
245 bool const readonly = isBufferReadonly();
246 enableView(!readonly);
247 // refreshReadOnly() is too generous in _enabling_ widgets
248 // update dialog to disable disabled widgets again
250 if (!readonly || canApplyToReadOnly())
258 QString Dialog::sessionKey() const
260 return "view-" + 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