X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FDialog.cpp;h=65d4a5598141dbb3471e02af0c1471a2e638051c;hb=425d092204118ea6c24c28e85fdf03fcf2bb51a4;hp=5c37b23241978a5fd4eb37818b45c5f9fd733ee2;hpb=990df4924a00309f49f89466179fc46ad1b382c1;p=lyx.git diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index 5c37b23241..65d4a55981 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -16,17 +16,20 @@ #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 - #include using namespace std; @@ -55,7 +58,6 @@ bool Dialog::canApply() const void Dialog::dispatch(FuncRequest const & fr) const { - theLyXFunc().setLyXView(lyxview_); lyx::dispatch(fr); } @@ -74,15 +76,15 @@ void Dialog::disconnect() const 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(); } @@ -103,29 +105,16 @@ KernelDocType Dialog::docType() const } -BufferView * Dialog::bufferview() -{ - return lyxview_->view(); -} - - BufferView const * Dialog::bufferview() const { - return lyxview_->view(); -} - - -Buffer & Dialog::buffer() -{ - BOOST_ASSERT(lyxview_->buffer()); - return *lyxview_->buffer(); + return lyxview_->currentBufferView(); } Buffer const & Dialog::buffer() const { - BOOST_ASSERT(lyxview_->buffer()); - return *lyxview_->buffer(); + LASSERT(lyxview_->currentBufferView(), /**/); + return lyxview_->currentBufferView()->buffer(); } @@ -135,7 +124,7 @@ void Dialog::showData(string const & data) return; if (!initialiseParams(data)) { - LYXERR0("Dialog \"" << fromqstr(name()) + LYXERR0("Dialog \"" << name() << "\" failed to translate the data string passed to show()"); return; } @@ -163,30 +152,11 @@ void Dialog::apply() } -void Dialog::updateData(string const & data) -{ - if (isBufferDependent() && !isBufferAvailable()) - return; - - if (!initialiseParams(data)) { - LYXERR0("Dialog \"" << fromqstr(name()) - << "\" could not be initialized"); - return; - } - - updateView(); -} - - -void Dialog::showView() +void Dialog::prepareView() { - // Make sure the dialog is up-to-date. - updateView(); // Make sure the dialog controls are correctly enabled/disabled with // readonly status. checkStatus(); - if (exitEarly()) - return; QWidget * w = asQWidget(); w->setWindowTitle(title_); @@ -194,14 +164,27 @@ void Dialog::showView() 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(); - w->setFocus(); + if (wantInitialFocus()) + w->setFocus(); + else { + lyxview_->raise(); + lyxview_->activateWindow(); + lyxview_->setFocus(); + } } @@ -222,12 +205,25 @@ bool Dialog::isVisibleView() const } +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 independant dialogs are always active. + // buffer independent dialogs are always active. // This check allows us leave canApply unimplemented for some dialogs. - if (!isBufferDependent()) + if (!isBufferDependent()) { + updateView(); return; + } // deactivate the dialog if we have no buffer if (!isBufferAvailable()) { @@ -238,13 +234,11 @@ void Dialog::checkStatus() // check whether this dialog may be active if (canApply()) { bool const readonly = isBufferReadonly(); - enableView(!readonly); + enableView(!readonly || canApplyToReadOnly()); // refreshReadOnly() is too generous in _enabling_ widgets // update dialog to disable disabled widgets again - if (!readonly || canApplyToReadOnly()) - updateView(); - + updateView(); } else enableView(false); } @@ -252,7 +246,7 @@ void Dialog::checkStatus() QString Dialog::sessionKey() const { - return "view-" + QString::number(lyxview_->id()) + return "views/" + QString::number(lyxview_->id()) + "/" + name(); }