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....
This commit is contained in:
Richard Kimberly Heck 2021-01-09 20:33:23 -05:00
parent e438c0f90b
commit 9446aa3640
4 changed files with 29 additions and 19 deletions

View File

@ -275,5 +275,30 @@ void Dialog::restoreSession()
settings.value(sessionKey() + "/geometry").toByteArray()); 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 frontend
} // namespace lyx } // namespace lyx

View File

@ -266,6 +266,8 @@ protected:
virtual void apply(); virtual void apply();
/// To be called when the buffer view has changed /// To be called when the buffer view has changed
virtual void onBufferViewChanged() = 0; virtual void onBufferViewChanged() = 0;
///
void connectToNewInset();
private: private:
/** The Dialog's name is the means by which a dialog identifies /** The Dialog's name is the means by which a dialog identifies

View File

@ -198,25 +198,7 @@ void GuiCitation::applyView()
QString const after = textAfterED->text(); QString const after = textAfterED->text();
applyParams(choice, full, force, before, after); applyParams(choice, full, force, before, after);
connectToNewInset();
// 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);
}
}
} }

View File

@ -770,6 +770,7 @@ void GuiGraphics::dispatchParams()
InsetGraphicsParams tmp_params(params_); InsetGraphicsParams tmp_params(params_);
string const lfun = InsetGraphics::params2string(tmp_params, buffer()); string const lfun = InsetGraphics::params2string(tmp_params, buffer());
dispatch(FuncRequest(getLfun(), lfun)); dispatch(FuncRequest(getLfun(), lfun));
connectToNewInset();
} }