John Levon wrote:

> On Thu, Apr 03, 2003 at 09:17:10AM +0000, Angus Leeming wrote:
> 
>> src/lfuns.h:    LFUN_INSET_DIALOG_UPDATE,
> 
> This one, insetcommand.C:localDispatch()

LFUN_INSET : operates on an inset
DIALOG_UPDATE : guess what ;-}

> Actually I was kind of hoping you'd be able to say one way or the other.
> What does the lfun do, and what are the consequences of it being called
> on more than one inset at a time ?

The lfun is used to tell an open dialog that the inset's contents have 
changed. In this particular case, the code is:

        case LFUN_INSET_DIALOG_UPDATE: {
                InsetCommandMailer mailer(cmd.argument, *this);
                mailer.updateDialog(cmd.view());
        }

void MailInset::updateDialog(BufferView * bv) const
{
        lyx::Assert(bv);
        bv->owner()->getDialogs().update(name(), inset2string());
}

void Dialogs::update(string const & name, string const & data)
{
        Dialog * dialog = find(name);
        if (!dialog)
                return;

        if (dialog->isVisible())
                dialog->update(data);
}

So, to answer your next question "what are the consequences of it being 
called on more than one inset at a time ?"

The dialog will be updated each time with the contents of the next inset. No 
check is made that the dialog is actually _connected_ to this inset.

So, you have probably discovered a flaw. The Dialogs::update method should 
probably have an (InsetBase *) parameter and only update the contents of 
the dialog if this matches open_insets_[name]. If only for peace of mind.

I don't think that it is actually a problem, since the inset::localDispatch 
method is meant to be called only from lyxfun.C's dispatch:

        case LFUN_DIALOG_UPDATE: {
                string const & name = argument;
                // Can only update a dialog connected to an existing inset
                InsetBase * inset = owner->getDialogs().getOpenInset(name);
                if (inset) {
                        FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
                                       ev.argument);
                        inset->localDispatch(fr);
                } else if (name == "paragraph") {
                        dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
                }
        }
        break;

Note that the lfun has changed from that dispatched from the outside, so we 
should be safe. There is no way to invoke the lfun from outside as it has 
no name defined in LyXAction.C's init:

               { LFUN_INSET_DIALOG_UPDATE, "", "internal only", Noop },

However, I think that there is probably room for the Dialogs class to be 
modified so that a) it knows which dialogs are used to modify an inset and 
b) refuses to update anything if it is not passed an (inset *) to compare 
with that stored in open_insets_[name].

Sorry to be so verbose, but I've been working this out!

Returning to the point of the entire discussion
>>         case LFUN_MOUSE_RELEASE:
>>                 edit(cmd.view(), cmd.x, cmd.y, cmd.button());
>> +               result = DISPATCHED;
>>                 break;
> 
> Angus, what about INSET_UPDATE ? Looks like it's needed there too ?

I would say yes. Please do so.

-- 
Angus

Reply via email to