X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FDialog.cpp;h=e1fddaaa7e0f2660b4e3380d61c3e73fb3205e03;hb=28be7d552f62cc02fa86d7f79201d089bfb2d7b5;hp=d1ff82fc7f4d1f13ca9af65034e17772f08447ad;hpb=193074b3847b0364c8270c96614993e4500c938e;p=lyx.git diff --git a/src/frontends/qt4/Dialog.cpp b/src/frontends/qt4/Dialog.cpp index d1ff82fc7f..e1fddaaa7e 100644 --- a/src/frontends/qt4/Dialog.cpp +++ b/src/frontends/qt4/Dialog.cpp @@ -16,19 +16,25 @@ #include "qt_helpers.h" #include "Buffer.h" +#include "BufferParams.h" #include "BufferView.h" #include "Cursor.h" #include "FuncRequest.h" #include "FuncStatus.h" -#include "LyXFunc.h" +#include "LyX.h" #include "insets/Inset.h" #include "support/debug.h" +#include "support/gettext.h" #include "support/lassert.h" +#include +#include +#include #include #include +#include #include @@ -38,9 +44,8 @@ using namespace lyx::support; namespace lyx { namespace frontend { - Dialog::Dialog(GuiView & lv, QString const & name, QString const & title) - : name_(name), title_(title), lyxview_(&lv) + : name_(name), title_(title), lyxview_(lv) {} @@ -58,7 +63,6 @@ bool Dialog::canApply() const void Dialog::dispatch(FuncRequest const & fr) const { - theLyXFunc().setLyXView(lyxview_); lyx::dispatch(fr); } @@ -71,25 +75,25 @@ void Dialog::updateDialog() const void Dialog::disconnect() const { - lyxview_->disconnectDialog(fromqstr(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(); } -QString Dialog::bufferFilepath() const +QString Dialog::bufferFilePath() const { return toqstr(buffer().filePath()); } @@ -97,9 +101,9 @@ QString Dialog::bufferFilepath() const KernelDocType Dialog::docType() const { - if (buffer().isLatex()) + if (buffer().params().isLatex()) return LATEX; - if (buffer().isLiterate()) + if (buffer().params().isLiterate()) return LITERATE; return DOCBOOK; @@ -108,14 +112,21 @@ KernelDocType Dialog::docType() const BufferView const * Dialog::bufferview() const { - return lyxview_->view(); + return lyxview_.currentBufferView(); } Buffer const & Dialog::buffer() const { - LASSERT(lyxview_->buffer(), /**/); - return *lyxview_->buffer(); + LAPPERR(lyxview_.currentBufferView()); + return lyxview_.currentBufferView()->buffer(); +} + + +Buffer const & Dialog::documentBuffer() const +{ + LAPPERR(lyxview_.documentBufferView()); + return lyxview_.documentBufferView()->buffer(); } @@ -153,7 +164,7 @@ void Dialog::apply() } -void Dialog::showView() +void Dialog::prepareView() { // Make sure the dialog controls are correctly enabled/disabled with // readonly status. @@ -165,7 +176,14 @@ 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(); @@ -175,9 +193,9 @@ void Dialog::showView() if (wantInitialFocus()) w->setFocus(); else { - lyxview_->raise(); - lyxview_->activateWindow(); - lyxview_->setFocus(); + lyxview_.raise(); + lyxview_.activateWindow(); + lyxview_.setFocus(); } } @@ -201,18 +219,30 @@ bool Dialog::isVisibleView() const Inset const * Dialog::inset(InsetCode code) const { + // ins: the innermost inset of the type we look for + // that contains the cursor Inset * ins = bufferview()->cursor().innerInsetOfType(code); - if (!ins) - ins = bufferview()->cursor().nextInset(); - if (!ins || ins->lyxCode() != code) - return 0; + // next: a potential inset at cursor position + Inset * next = bufferview()->cursor().nextInset(); + // Check if next is of the type we look for + if (next) + if (next->lyxCode() != code) + next = 0; + if (ins) { + // prefer next if it is of the requested type (bug 8716) + if (next) + ins = next; + } else + // no containing inset of requested type + // use next (which might also be 0) + ins = next; 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()) { updateView(); @@ -228,13 +258,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); } @@ -242,7 +270,7 @@ void Dialog::checkStatus() QString Dialog::sessionKey() const { - return "views/" + QString::number(lyxview_->id()) + return "views/" + QString::number(lyxview_.id()) + "/" + name(); }