X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FDialog.cpp;h=65d4a5598141dbb3471e02af0c1471a2e638051c;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=40b4f376321a75595b0810446833f9fa9132c305;hpb=1060f922f06f1906e49d68498e1e8dc8d919a3f0;p=lyx.git diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index 40b4f37632..65d4a55981 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -13,20 +13,34 @@ #include "Dialog.h" #include "GuiView.h" +#include "qt_helpers.h" #include "Buffer.h" +#include "BufferView.h" +#include "Cursor.h" #include "FuncRequest.h" #include "FuncStatus.h" #include "LyXFunc.h" +#include "insets/Inset.h" + +#include "support/debug.h" +#include "support/lassert.h" + +#include +#include + #include +using namespace std; +using namespace lyx::support; + namespace lyx { namespace frontend { -Dialog::Dialog(GuiView & lv, std::string const & name) - : lyxview_(&lv), name_(name.c_str()) +Dialog::Dialog(GuiView & lv, QString const & name, QString const & title) + : name_(name), title_(title), lyxview_(&lv) {} @@ -34,14 +48,9 @@ Dialog::~Dialog() {} -std::string Dialog::name() const -{ - return name_; -} - bool Dialog::canApply() const { - FuncRequest const fr(getLfun(), name_); + FuncRequest const fr(getLfun(), fromqstr(name_)); FuncStatus const fs(getStatus(fr)); return fs.enabled(); } @@ -49,40 +58,39 @@ bool Dialog::canApply() const void Dialog::dispatch(FuncRequest const & fr) const { - theLyXFunc().setLyXView(lyxview_); lyx::dispatch(fr); } void Dialog::updateDialog() const { - dispatch(FuncRequest(LFUN_DIALOG_UPDATE, name_)); + dispatch(FuncRequest(LFUN_DIALOG_UPDATE, fromqstr(name_))); } void Dialog::disconnect() const { - lyxview_->disconnectDialog(name_); + lyxview_->disconnectDialog(fromqstr(name_)); } bool Dialog::isBufferAvailable() const { - return lyxview_->buffer() != 0; + return lyxview_->currentBufferView() != 0; } bool Dialog::isBufferReadonly() const { - if (!lyxview_->buffer()) + if (!lyxview_->documentBufferView()) return true; - return lyxview_->buffer()->isReadonly(); + return lyxview_->documentBufferView()->buffer().isReadonly(); } -std::string const Dialog::bufferFilepath() const +QString Dialog::bufferFilepath() const { - return buffer().filePath(); + return toqstr(buffer().filePath()); } @@ -97,29 +105,164 @@ KernelDocType Dialog::docType() const } -BufferView * Dialog::bufferview() +BufferView const * Dialog::bufferview() const { - return lyxview_->view(); + return lyxview_->currentBufferView(); } -BufferView const * Dialog::bufferview() const +Buffer const & Dialog::buffer() const { - return lyxview_->view(); + LASSERT(lyxview_->currentBufferView(), /**/); + return lyxview_->currentBufferView()->buffer(); } -Buffer & Dialog::buffer() +void Dialog::showData(string const & data) { - BOOST_ASSERT(lyxview_->buffer()); - return *lyxview_->buffer(); + if (isBufferDependent() && !isBufferAvailable()) + return; + + if (!initialiseParams(data)) { + LYXERR0("Dialog \"" << name() + << "\" failed to translate the data string passed to show()"); + return; + } + + showView(); } -Buffer const & Dialog::buffer() const +void Dialog::apply() +{ + if (isBufferDependent()) { + if (!isBufferAvailable() || + (isBufferReadonly() && !canApplyToReadOnly())) + return; + } + + applyView(); + dispatchParams(); + + if (disconnectOnApply() && !isClosing()) { + disconnect(); + initialiseParams(string()); + updateView(); + } +} + + +void Dialog::prepareView() +{ + // Make sure the dialog controls are correctly enabled/disabled with + // readonly status. + checkStatus(); + + QWidget * w = asQWidget(); + w->setWindowTitle(title_); + + QSize const hint = w->sizeHint(); + if (hint.height() >= 0 && hint.width() >= 0) + w->setMinimumSize(hint); +} + + +void Dialog::showView() +{ + prepareView(); + + QWidget * w = asQWidget(); + if (w->isVisible()) { + w->raise(); + w->activateWindow(); + } else + w->show(); + + if (wantInitialFocus()) + w->setFocus(); + else { + lyxview_->raise(); + lyxview_->activateWindow(); + lyxview_->setFocus(); + } +} + + +void Dialog::hideView() +{ + QWidget * w = asQWidget(); + if (!w->isVisible()) + return; + clearParams(); + disconnect(); + w->hide(); +} + + +bool Dialog::isVisibleView() const +{ + return asQWidget()->isVisible(); +} + + +Inset const * Dialog::inset(InsetCode code) const +{ + Inset * ins = bufferview()->cursor().innerInsetOfType(code); + if (!ins) + ins = bufferview()->cursor().nextInset(); + if (!ins || ins->lyxCode() != code) + return 0; + return ins; +} + + +void Dialog::checkStatus() +{ + // buffer independent dialogs are always active. + // This check allows us leave canApply unimplemented for some dialogs. + if (!isBufferDependent()) { + updateView(); + return; + } + + // deactivate the dialog if we have no buffer + if (!isBufferAvailable()) { + enableView(false); + return; + } + + // check whether this dialog may be active + if (canApply()) { + bool const readonly = isBufferReadonly(); + enableView(!readonly || canApplyToReadOnly()); + // refreshReadOnly() is too generous in _enabling_ widgets + // update dialog to disable disabled widgets again + + updateView(); + } else + enableView(false); +} + + +QString Dialog::sessionKey() const +{ + return "views/" + QString::number(lyxview_->id()) + + "/" + name(); +} + + +void Dialog::saveSession() const +{ + QSettings settings; + settings.setValue(sessionKey() + "/geometry", asQWidget()->saveGeometry()); +} + + +void Dialog::restoreSession() { - BOOST_ASSERT(lyxview_->buffer()); - return *lyxview_->buffer(); + QSettings settings; + asQWidget()->restoreGeometry( + settings.value(sessionKey() + "/geometry").toByteArray()); } } // namespace frontend