On Tue, 4 Jul 2000, Angus Leeming wrote:
> 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 andso 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 inLyXParagraph::InsertInset() once the inset is inserted into the
> insetlist.
>
> 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.
>
Perhaps holding a pointer to the owning paragraph whould server us better?
Insets can be either in the top-level document (owned by a paragraph) or
inside other insets. Thus insets have an Inset* 'owner' member, but no
pointer for the first case. This can be contrasted with the LyXText class,
which can be owner by either a Buffer_View or an InsetText.
This also allows easier deletion of an inset, given only a pointer to the
inset (you don't have to search for the paragraph) - maybe even implement
Inset::delete_yourself() (which removes the inset from the respective
owner, and then deletes 'this').
class Inset {
LyXParagraph * owner_par;
bool isInserted() { return (owner_par!=NULL) || (owner!=NULL)); }
};
Lior.