commit 9446aa3640932bcd836abad0d4f9b7c54202cecc
Author: Richard Kimberly Heck <[email protected]>
Date:   Sat Jan 9 20:33:23 2021 -0500

    Fix bug #11030.
    
    Factor out the code that connects to a newly created dialog and then
    use that also in GuiGraphics.
    
    There must be many other dialogs that need this same treatment....
---
 src/frontends/qt/Dialog.cpp      |   25 +++++++++++++++++++++++++
 src/frontends/qt/Dialog.h        |    2 ++
 src/frontends/qt/GuiCitation.cpp |   20 +-------------------
 src/frontends/qt/GuiGraphics.cpp |    1 +
 4 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/frontends/qt/Dialog.cpp b/src/frontends/qt/Dialog.cpp
index f929c0e..c9d11f7 100644
--- a/src/frontends/qt/Dialog.cpp
+++ b/src/frontends/qt/Dialog.cpp
@@ -275,5 +275,30 @@ void Dialog::restoreSession()
                settings.value(sessionKey() + "/geometry").toByteArray());
 }
 
+
+// If we have just created an inset, then we want to attach the
+// dialog to it. This (i) allows further modification of that inset and
+// (ii) prevents an additional click on Apply or OK from unexpectedly
+// creating another inset. (See #3964 and #11030.)
+void Dialog::connectToNewInset()
+{
+       GuiView & view = const_cast<GuiView &>(lyxview());
+       BufferView * bv = view.currentBufferView();
+       // should have one, but just to be safe...
+       if (!bv)
+               return;
+
+       // are we attached to an inset already?
+       Inset * ins = bv->editedInset(fromqstr(name_));
+       if (ins)
+               return;
+
+       // no, so we just inserted one, and now we are behind it.
+       Cursor const & cur = bv->cursor();
+       ins = cur.prevInset();
+       if (ins)
+               bv->editInset(fromqstr(name_), ins);
+}
+
 } // namespace frontend
 } // namespace lyx
diff --git a/src/frontends/qt/Dialog.h b/src/frontends/qt/Dialog.h
index b4e6045..be9b323 100644
--- a/src/frontends/qt/Dialog.h
+++ b/src/frontends/qt/Dialog.h
@@ -266,6 +266,8 @@ protected:
        virtual void apply();
        /// To be called when the buffer view has changed
        virtual void onBufferViewChanged() = 0;
+       ///
+       void connectToNewInset();
 
 private:
        /** The Dialog's name is the means by which a dialog identifies
diff --git a/src/frontends/qt/GuiCitation.cpp b/src/frontends/qt/GuiCitation.cpp
index e6df310..eed9574 100644
--- a/src/frontends/qt/GuiCitation.cpp
+++ b/src/frontends/qt/GuiCitation.cpp
@@ -198,25 +198,7 @@ void GuiCitation::applyView()
        QString const after = textAfterED->text();
 
        applyParams(choice, full, force, before, after);
-
-       // If we have just created a citation inset, then we want to attach the
-       // dialog to it. This (i) allows further modification of that inset and
-       // (ii) prevents an additional click on Apply or OK from unexpectedly
-       // creating another inset. (See #3964.)
-       GuiView & view = const_cast<GuiView &>(lyxview());
-       BufferView * bv = view.currentBufferView();
-       // should have one, but just to be safe...
-       if (bv) {
-               // are we attached to an inset already?
-               Inset * ins = bv->editedInset("citation");
-               if (!ins) {
-                       // no, so we just inserted one, and now we are behind 
it.
-                       Cursor const & cur = bv->cursor();
-                       ins = cur.prevInset();
-                       if (ins)
-                               bv->editInset("citation", ins);
-               }
-       }
+       connectToNewInset();
 }
 
 
diff --git a/src/frontends/qt/GuiGraphics.cpp b/src/frontends/qt/GuiGraphics.cpp
index b8a5af9..51036e1 100644
--- a/src/frontends/qt/GuiGraphics.cpp
+++ b/src/frontends/qt/GuiGraphics.cpp
@@ -770,6 +770,7 @@ void GuiGraphics::dispatchParams()
        InsetGraphicsParams tmp_params(params_);
        string const lfun = InsetGraphics::params2string(tmp_params, buffer());
        dispatch(FuncRequest(getLfun(), lfun));
+       connectToNewInset();
 }
 
 
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to