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"
31 using namespace lyx::support;
37 Dialog::Dialog(GuiView & lv, string const & name)
38 : name_(name), lyxview_(&lv)
46 string const & Dialog::name() const
51 bool Dialog::canApply() const
53 FuncRequest const fr(getLfun(), from_ascii(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, from_ascii(name_)));
72 void Dialog::disconnect() const
74 lyxview_->disconnectDialog(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 string const Dialog::bufferFilepath() const
94 return 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 BOOST_ASSERT(lyxview_->buffer());
124 return *lyxview_->buffer();
128 Buffer const & Dialog::buffer() const
130 BOOST_ASSERT(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::updateData(string const & data)
171 if (isBufferDependent() && !isBufferAvailable())
174 if (!initialiseParams(data)) {
175 LYXERR0("Dialog \"" << name()
176 << "\" could not be initialized");
184 void Dialog::showView()
186 updateView(); // make sure its up-to-date
190 QWidget * w = asQWidget();
191 QSize const hint = w->sizeHint();
192 if (hint.height() >= 0 && hint.width() >= 0)
193 w->setMinimumSize(hint);
195 if (w->isVisible()) {
205 void Dialog::hideView()
207 QWidget * w = asQWidget();
216 bool Dialog::isVisibleView() const
218 return asQWidget()->isVisible();
222 void Dialog::checkStatus()
224 // buffer independant dialogs are always active.
225 // This check allows us leave canApply unimplemented for some dialogs.
226 if (!isBufferDependent())
229 // deactivate the dialog if we have no buffer
230 if (!isBufferAvailable()) {
235 // check whether this dialog may be active
237 bool const readonly = isBufferReadonly();
238 enableView(!readonly);
239 // refreshReadOnly() is too generous in _enabling_ widgets
240 // update dialog to disable disabled widgets again
242 if (!readonly || canApplyToReadOnly())
250 QString Dialog::sessionKey() const
252 return "view-" + QString::number(lyxview_->id())
253 + "/" + toqstr(name());
257 void Dialog::saveSession() const
260 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
264 void Dialog::restoreSession()
267 asQWidget()->restoreGeometry(
268 settings.value(sessionKey() + "/geometry").toByteArray());
271 } // namespace frontend