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"
36 Dialog::Dialog(GuiView & lv, std::string const & name)
37 : name_(name), lyxview_(&lv)
45 std::string const & Dialog::name() const
50 bool Dialog::canApply() const
52 FuncRequest const fr(getLfun(), from_ascii(name_));
53 FuncStatus const fs(getStatus(fr));
58 void Dialog::dispatch(FuncRequest const & fr) const
60 theLyXFunc().setLyXView(lyxview_);
65 void Dialog::updateDialog() const
67 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, from_ascii(name_)));
71 void Dialog::disconnect() const
73 lyxview_->disconnectDialog(name_);
77 bool Dialog::isBufferAvailable() const
79 return lyxview_->buffer() != 0;
83 bool Dialog::isBufferReadonly() const
85 if (!lyxview_->buffer())
87 return lyxview_->buffer()->isReadonly();
91 std::string const Dialog::bufferFilepath() const
93 return buffer().filePath();
97 KernelDocType Dialog::docType() const
99 if (buffer().isLatex())
101 if (buffer().isLiterate())
108 BufferView * Dialog::bufferview()
110 return lyxview_->view();
114 BufferView const * Dialog::bufferview() const
116 return lyxview_->view();
120 Buffer & Dialog::buffer()
122 BOOST_ASSERT(lyxview_->buffer());
123 return *lyxview_->buffer();
127 Buffer const & Dialog::buffer() const
129 BOOST_ASSERT(lyxview_->buffer());
130 return *lyxview_->buffer();
134 void Dialog::showData(string const & data)
136 if (isBufferDependent() && !isBufferAvailable())
139 if (!initialiseParams(data)) {
140 LYXERR0("Dialog \"" << name()
141 << "\" failed to translate the data string passed to show()");
151 if (isBufferDependent()) {
152 if (!isBufferAvailable() ||
153 (isBufferReadonly() && !canApplyToReadOnly()))
160 if (disconnectOnApply() && !isClosing()) {
162 initialiseParams(string());
168 void Dialog::updateData(string const & data)
170 if (isBufferDependent() && !isBufferAvailable())
173 if (!initialiseParams(data)) {
174 LYXERR0("Dialog \"" << name()
175 << "\" could not be initialized");
183 void Dialog::showView()
185 updateView(); // make sure its up-to-date
189 QWidget * w = asQWidget();
190 QSize const hint = w->sizeHint();
191 if (hint.height() >= 0 && hint.width() >= 0)
192 w->setMinimumSize(hint);
194 if (w->isVisible()) {
204 void Dialog::hideView()
206 QWidget * w = asQWidget();
215 bool Dialog::isVisibleView() const
217 return asQWidget()->isVisible();
221 void Dialog::checkStatus()
223 // buffer independant dialogs are always active.
224 // This check allows us leave canApply unimplemented for some dialogs.
225 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);
238 // refreshReadOnly() is too generous in _enabling_ widgets
239 // update dialog to disable disabled widgets again
241 if (!readonly || canApplyToReadOnly())
249 QString Dialog::sessionKey() const
251 return "view-" + QString::number(lyxview_->id())
252 + "/" + toqstr(name());
256 void Dialog::saveSession() const
259 settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry());
263 void Dialog::restoreSession()
266 asQWidget()->restoreGeometry(
267 settings.value(sessionKey() + "/geometry").toByteArray());
270 } // namespace frontend