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
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 QSize const hint = w->sizeHint();
193 if (hint.height() >= 0 && hint.width() >= 0)
194 w->setMinimumSize(hint);
196 if (w->isVisible()) {
206 void Dialog::hideView()
208 QWidget * w = asQWidget();
217 bool Dialog::isVisibleView() const
219 return asQWidget()->isVisible();
223 void Dialog::checkStatus()
225 // buffer independant dialogs are always active.
226 // This check allows us leave canApply unimplemented for some dialogs.
227 if (!isBufferDependent())
230 // deactivate the dialog if we have no buffer
231 if (!isBufferAvailable()) {
236 // check whether this dialog may be active
238 bool const readonly = isBufferReadonly();
239 enableView(!readonly);
240 // refreshReadOnly() is too generous in _enabling_ widgets
241 // update dialog to disable disabled widgets again
243 if (!readonly || canApplyToReadOnly())
251 QString Dialog::sessionKey() const
253 return "view-" + QString::number(lyxview_->id())
254 + "/" + toqstr(name());
258 void Dialog::saveSession() const
261 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
265 void Dialog::restoreSession()
268 asQWidget()->restoreGeometry(
269 settings.value(sessionKey() + "/geometry").toByteArray());
272 } // namespace frontend