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.
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
22 #include "support/Debug.h"
32 Dialog::Dialog(GuiView & lv, std::string const & name)
33 : name_(name), lyxview_(&lv)
41 std::string const & Dialog::name() const
46 bool Dialog::canApply() const
48 FuncRequest const fr(getLfun(), from_ascii(name_));
49 FuncStatus const fs(getStatus(fr));
54 void Dialog::dispatch(FuncRequest const & fr) const
56 theLyXFunc().setLyXView(lyxview_);
61 void Dialog::updateDialog() const
63 dispatch(FuncRequest(LFUN_DIALOG_UPDATE, from_ascii(name_)));
67 void Dialog::disconnect() const
69 lyxview_->disconnectDialog(name_);
73 bool Dialog::isBufferAvailable() const
75 return lyxview_->buffer() != 0;
79 bool Dialog::isBufferReadonly() const
81 if (!lyxview_->buffer())
83 return lyxview_->buffer()->isReadonly();
87 std::string const Dialog::bufferFilepath() const
89 return buffer().filePath();
93 KernelDocType Dialog::docType() const
95 if (buffer().isLatex())
97 if (buffer().isLiterate())
104 BufferView * Dialog::bufferview()
106 return lyxview_->view();
110 BufferView const * Dialog::bufferview() const
112 return lyxview_->view();
116 Buffer & Dialog::buffer()
118 BOOST_ASSERT(lyxview_->buffer());
119 return *lyxview_->buffer();
123 Buffer const & Dialog::buffer() const
125 BOOST_ASSERT(lyxview_->buffer());
126 return *lyxview_->buffer();
130 void Dialog::showData(string const & data)
132 if (isBufferDependent() && !isBufferAvailable())
135 if (!initialiseParams(data)) {
136 LYXERR0("Dialog \"" << name()
137 << "\" failed to translate the data string passed to show()");
147 if (isBufferDependent()) {
148 if (!isBufferAvailable() ||
149 (isBufferReadonly() && !canApplyToReadOnly()))
156 if (disconnectOnApply() && !isClosing()) {
158 initialiseParams(string());
164 void Dialog::updateData(string const & data)
166 if (isBufferDependent() && !isBufferAvailable())
169 if (!initialiseParams(data)) {
170 LYXERR0("Dialog \"" << name()
171 << "\" could not be initialized");
179 void Dialog::showView()
181 updateView(); // make sure its up-to-date
185 QWidget * w = asQWidget();
186 QSize const hint = w->sizeHint();
187 if (hint.height() >= 0 && hint.width() >= 0)
188 w->setMinimumSize(hint);
190 if (w->isVisible()) {
200 void Dialog::hideView()
202 QWidget * w = asQWidget();
211 bool Dialog::isVisibleView() const
213 return asQWidget()->isVisible();
217 void Dialog::checkStatus()
219 // buffer independant dialogs are always active.
220 // This check allows us leave canApply unimplemented for some dialogs.
221 if (!isBufferDependent())
224 // deactivate the dialog if we have no buffer
225 if (!isBufferAvailable()) {
230 // check whether this dialog may be active
232 bool const readonly = isBufferReadonly();
233 enableView(!readonly);
234 // refreshReadOnly() is too generous in _enabling_ widgets
235 // update dialog to disable disabled widgets again
237 if (!readonly || canApplyToReadOnly())
244 } // namespace frontend