diff --git a/src/frontends/qt/Dialog.cpp b/src/frontends/qt/Dialog.cpp index f929c0e1b9..c9d11f74a6 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(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 b4e6045366..be9b3232f7 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 e6df31084f..eed9574904 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(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 b8a5af95f6..51036e12f7 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(); }