]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/Dialog.cpp
Account for old versions of Pygments
[lyx.git] / src / frontends / qt4 / Dialog.cpp
index c0814277ecb0a6e846e78369b0d601452935a833..e1fddaaa7e0f2660b4e3380d61c3e73fb3205e03 100644 (file)
@@ -45,7 +45,7 @@ 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)
 {}
 
 
@@ -75,21 +75,21 @@ void Dialog::updateDialog() const
 
 void Dialog::disconnect() const
 {
-       lyxview_->disconnectDialog(fromqstr(name_));
+       lyxview_.disconnectDialog(fromqstr(name_));
 }
 
 
 bool Dialog::isBufferAvailable() const
 {
-       return lyxview_->currentBufferView() != 0;
+       return lyxview_.currentBufferView() != 0;
 }
 
 
 bool Dialog::isBufferReadonly() const
 {
-       if (!lyxview_->documentBufferView())
+       if (!lyxview_.documentBufferView())
                return true;
-       return lyxview_->documentBufferView()->buffer().isReadonly();
+       return lyxview_.documentBufferView()->buffer().isReadonly();
 }
 
 
@@ -112,21 +112,21 @@ KernelDocType Dialog::docType() const
 
 BufferView const * Dialog::bufferview() const
 {
-       return lyxview_->currentBufferView();
+       return lyxview_.currentBufferView();
 }
 
 
 Buffer const & Dialog::buffer() const
 {
-       LAPPERR(lyxview_->currentBufferView());
-       return lyxview_->currentBufferView()->buffer();
+       LAPPERR(lyxview_.currentBufferView());
+       return lyxview_.currentBufferView()->buffer();
 }
 
 
 Buffer const & Dialog::documentBuffer() const
 {
-       LAPPERR(lyxview_->currentBufferView());
-       return lyxview_->documentBufferView()->buffer();
+       LAPPERR(lyxview_.documentBufferView());
+       return lyxview_.documentBufferView()->buffer();
 }
 
 
@@ -193,9 +193,9 @@ void Dialog::showView()
        if (wantInitialFocus())
                w->setFocus();
        else {
-               lyxview_->raise();
-               lyxview_->activateWindow();
-               lyxview_->setFocus();
+               lyxview_.raise();
+               lyxview_.activateWindow();
+               lyxview_.setFocus();
        }
 }
 
@@ -219,11 +219,23 @@ 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;
 }
 
@@ -258,7 +270,7 @@ void Dialog::checkStatus()
 
 QString Dialog::sessionKey() const
 {
-       return "views/" + QString::number(lyxview_->id())
+       return "views/" + QString::number(lyxview_.id())
                + "/" + name();
 }