I'm thinking of adding a new variable to class Inset:
class Inset {
bool isInserted() const { return inserted_; }
bool inserted_;
}
The strategy I outline below is for an InsetCitation, but I think that it also
holds true for other insets and so the variable should go in the top level
class. Thoughts?
Angus
=============================================================
Here's the reasoning:
When a new Inset is created this variable (Inset::inserted_) is false. It is set
to true in LyXParagraph::InsertInset() once the inset is inserted into the
insetlist.
This allows us to call the citation dialog from LyXFunc::Dispatch (when
creating a new InsetCitation):
case LFUN_INSERT_CITATION:
owner->getDialogs()->showCitation( new InsetCitation(argument) );
break;
and from BufferView::Pimpl::workAreaButtonRelease (when launching the citation
dialog for an existing InsetCitation)
switch( inset_hit->LyxCode() ) {
case Inset::CITATION_CODE:
owner_->getDialogs()->showCitation( inset_hit );
break;
default:
inset_hit->Edit(bv_, x, y, button);
break;
}
The Dialogs::showCitation signal is connected to
void FormCitation::showInset( InsetCitation * inset )
interrogation of inset->isInserted() will allow the dialog to decide what to do
with the inset in the callback functions called when the Ok or Cancel buttons
are pressed.
Ie, if the inset contains some data, then a new inset must be inserted in the
insetlist
If, however, it is empty, then a new inset should be simply deleted,
whilst an old one should be removed from the insetlist.