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, QString const & title)
38 : name_(name), title_(title), lyxview_(&lv)
46 string const & Dialog::name() const
52 bool Dialog::canApply() const
54 FuncRequest const fr(getLfun(), from_ascii(name_));
55 FuncStatus const fs(getStatus(fr));
60 void Dialog::dispatch(FuncRequest const & fr) const
62 theLyXFunc().setLyXView(lyxview_);
67 void Dialog::updateDialog() const
69 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, from_ascii(name_)));
73 void Dialog::disconnect() const
75 lyxview_->disconnectDialog(name_);
79 bool Dialog::isBufferAvailable() const
81 return lyxview_->buffer() != 0;
85 bool Dialog::isBufferReadonly() const
87 if (!lyxview_->buffer())
89 return lyxview_->buffer()->isReadonly();
93 string const Dialog::bufferFilepath() const
95 return buffer().filePath();
99 KernelDocType Dialog::docType() const
101 if (buffer().isLatex())
103 if (buffer().isLiterate())
110 BufferView * Dialog::bufferview()
112 return lyxview_->view();
116 BufferView const * Dialog::bufferview() const
118 return lyxview_->view();
122 Buffer & Dialog::buffer()
124 BOOST_ASSERT(lyxview_->buffer());
125 return *lyxview_->buffer();
129 Buffer const & Dialog::buffer() const
131 BOOST_ASSERT(lyxview_->buffer());
132 return *lyxview_->buffer();
136 void Dialog::showData(string const & data)
138 if (isBufferDependent() && !isBufferAvailable())
141 if (!initialiseParams(data)) {
142 LYXERR0("Dialog \"" << name()
143 << "\" failed to translate the data string passed to show()");
153 if (isBufferDependent()) {
154 if (!isBufferAvailable() ||
155 (isBufferReadonly() && !canApplyToReadOnly()))
162 if (disconnectOnApply() && !isClosing()) {
164 initialiseParams(string());
170 void Dialog::updateData(string const & data)
172 if (isBufferDependent() && !isBufferAvailable())
175 if (!initialiseParams(data)) {
176 LYXERR0("Dialog \"" << name()
177 << "\" could not be initialized");
185 void Dialog::showView()
187 updateView(); // make sure its up-to-date
191 QWidget * w = asQWidget();
192 w->setWindowTitle(title_);
194 QSize const hint = w->sizeHint();
195 if (hint.height() >= 0 && hint.width() >= 0)
196 w->setMinimumSize(hint);
198 if (w->isVisible()) {
208 void Dialog::hideView()
210 QWidget * w = asQWidget();
219 bool Dialog::isVisibleView() const
221 return asQWidget()->isVisible();
225 void Dialog::checkStatus()
227 // buffer independant dialogs are always active.
228 // This check allows us leave canApply unimplemented for some dialogs.
229 if (!isBufferDependent())
232 // deactivate the dialog if we have no buffer
233 if (!isBufferAvailable()) {
238 // check whether this dialog may be active
240 bool const readonly = isBufferReadonly();
241 enableView(!readonly);
242 // refreshReadOnly() is too generous in _enabling_ widgets
243 // update dialog to disable disabled widgets again
245 if (!readonly || canApplyToReadOnly())
253 QString Dialog::sessionKey() const
255 return "view-" + QString::number(lyxview_->id())
256 + "/" + toqstr(name());
260 void Dialog::saveSession() const
263 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
267 void Dialog::restoreSession()
270 asQWidget()->restoreGeometry(
271 settings.value(sessionKey() + "/geometry").toByteArray());
274 } // namespace frontend