commit ae528715d336562a3d1e65fdd144797caeae25e9
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Tue Jun 28 23:17:05 2022 +0200

    Fix ToC action when cursor is in adv. F&R pane
    
    This important part is the last point, the rest is what is needed to
    make it happen.
    
    * implement (FindAndReplace|FindAndReplaceWidget)::hasWorkArea, that
      tell whether a work area is own by the advanced find & replace
      widget.
    
    * factor out method find() from GuiView::findOrBuild.
    
    * implement GuiView::hasVisibleWorkArea, that tells whether a workarea
      is visible in the view (current tab in a split or adv. f&r
      workarea).
    
    * Finally, in TocWidget::sendDispatch, change the current workarea
      temporarily to the document workarea before dispatching the
      function. The code tries to be as careful as possible to handle all
      cases. The future will tell whether it is good enough.
---
 src/frontends/qt/FindAndReplace.cpp |    5 +++++
 src/frontends/qt/FindAndReplace.h   |    4 ++++
 src/frontends/qt/GuiView.cpp        |   25 +++++++++++++++++++++++--
 src/frontends/qt/GuiView.h          |    4 ++++
 src/frontends/qt/TocWidget.cpp      |   15 +++++++++++++++
 5 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/src/frontends/qt/FindAndReplace.cpp 
b/src/frontends/qt/FindAndReplace.cpp
index d72fa92..a06cd1f 100644
--- a/src/frontends/qt/FindAndReplace.cpp
+++ b/src/frontends/qt/FindAndReplace.cpp
@@ -721,6 +721,11 @@ void FindAndReplaceWidget::updateButtons()
 }
 
 
+bool FindAndReplaceWidget::hasWorkArea(GuiWorkArea * wa) const
+{
+       return wa == find_work_area_ || wa == replace_work_area_;
+}
+
 } // namespace frontend
 } // namespace lyx
 
diff --git a/src/frontends/qt/FindAndReplace.h 
b/src/frontends/qt/FindAndReplace.h
index 41c211d..3bb4007 100644
--- a/src/frontends/qt/FindAndReplace.h
+++ b/src/frontends/qt/FindAndReplace.h
@@ -36,6 +36,9 @@ public:
        void updateGUI();
        void updateButtons();
 
+       // return true if \c wa is one if the adv. F&R workareas
+       bool hasWorkArea(GuiWorkArea * wa) const;
+
 public Q_SLOTS:
        ///
        void dockLocationChanged(Qt::DockWidgetArea area);
@@ -97,6 +100,7 @@ public:
        void dispatchParams() override {}
        bool isBufferDependent() const override { return false; }
        bool canApplyToReadOnly() const override { return true; }
+       bool hasWorkArea(GuiWorkArea * wa) const { return 
widget_->hasWorkArea(wa); }
        void selectAll();
 
        /// update
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index 8afa3b2..24969c2 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -18,6 +18,7 @@
 #include "DialogFactory.h"
 #include "DispatchResult.h"
 #include "FileDialog.h"
+#include "FindAndReplace.h"
 #include "FontLoader.h"
 #include "GuiApplication.h"
 #include "GuiClickableLabel.h"
@@ -1867,6 +1868,17 @@ void GuiView::removeWorkArea(GuiWorkArea * wa)
 }
 
 
+bool GuiView::hasVisibleWorkArea(GuiWorkArea * wa) const
+{
+       for (int i = 0; i < d.splitter_->count(); ++i)
+               if (d.tabWorkArea(i)->currentWorkArea() == wa)
+                       return true;
+
+       FindAndReplace * fr = 
static_cast<FindAndReplace*>(find("findreplaceadv", false));
+       return fr->isVisible() && fr->hasWorkArea(wa);
+}
+
+
 LayoutBox * GuiView::getLayoutDialog() const
 {
        return d.layout_;
@@ -5034,7 +5046,7 @@ void GuiView::flatGroupBoxes(const QObject * widget, bool 
flag)
 }
 
 
-Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
+Dialog * GuiView::find(string const & name, bool hide_it) const
 {
        if (!isValidName(name))
                return nullptr;
@@ -5046,8 +5058,17 @@ Dialog * GuiView::findOrBuild(string const & name, bool 
hide_it)
                        it->second->hideView();
                return it->second.get();
        }
+       return nullptr;
+}
+
+
+Dialog * GuiView::findOrBuild(string const & name, bool hide_it)
+{
+       Dialog * dialog = find(name, hide_it);
+       if (dialog != nullptr)
+               return dialog;
 
-       Dialog * dialog = build(name);
+       dialog = build(name);
        d.dialogs_[name].reset(dialog);
 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
        // Force a uniform style for group boxes
diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h
index 7237017..241701c 100644
--- a/src/frontends/qt/GuiView.h
+++ b/src/frontends/qt/GuiView.h
@@ -206,6 +206,8 @@ public:
        void setCurrentWorkArea(GuiWorkArea * work_area);
        ///
        void removeWorkArea(GuiWorkArea * work_area);
+       /// return true if \c wa is one of the visibles workareas of this view
+       bool hasVisibleWorkArea(GuiWorkArea * wa) const;
        /// return the current WorkArea (the one that has the focus).
        GuiWorkArea const * currentWorkArea() const;
        /// return the current WorkArea (the one that has the focus).
@@ -472,6 +474,8 @@ private:
        /// Is the dialog currently visible?
        bool isDialogVisible(std::string const & name) const;
        ///
+       Dialog * find(std::string const & name, bool hide_it) const;
+       ///
        Dialog * findOrBuild(std::string const & name, bool hide_it);
        ///
        Dialog * build(std::string const & name);
diff --git a/src/frontends/qt/TocWidget.cpp b/src/frontends/qt/TocWidget.cpp
index e0f1faf..c236327 100644
--- a/src/frontends/qt/TocWidget.cpp
+++ b/src/frontends/qt/TocWidget.cpp
@@ -380,7 +380,22 @@ void TocWidget::sendDispatch(FuncRequest fr)
 {
 
        fr.setViewOrigin(&gui_view_);
+       GuiWorkArea * old_wa = gui_view_.currentWorkArea();
+       GuiWorkArea * doc_wa = gui_view_.currentMainWorkArea();
+       /* The ToC command should be dispatched to the document work area,
+        * not the Adv. Find&Replace (which is the only other know
+        * possibility.
+        */
+       if (doc_wa != nullptr && doc_wa != old_wa)
+               gui_view_.setCurrentWorkArea(doc_wa);
        DispatchResult const & dr = dispatch(fr);
+       /* If the current workarea has not explicitely changed, and the
+        * original one is still visible, let's reset it.
+        */
+       if (gui_view_.currentWorkArea() == doc_wa
+            && gui_view_.hasVisibleWorkArea(old_wa)
+            && doc_wa != old_wa)
+               gui_view_.setCurrentWorkArea(old_wa);
        if (dr.error())
                gui_view_.message(dr.message());
 }
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to