I thought I'd see if I could make some progress with my planned clean-up of 
the controllers. The getting rid of inset* that I mentioned yesterday. 
Unfortunately, I'm stuck and would value some advice.

Pressing (say) a citation inset triggers a call to InsetCitation::edit, 
which in turn calls
        bv->owner()->getDialogs().showCitation(this);

The inset* is passed to the frontends and stored there. Once the user has 
finished modifying the data in the dialog and pressed Ok, the inset is 
modified in the frontend with:

void ControlCommand::applyParamsToInset()
{
        inset()->setParams(params());
        bufferview()->updateInset(inset(), true);
}

What I'd like to do is call lyxfunc().dispatch to modify the inset and 
update the bufferview if it sees fit. However, I don't want to store an 
inset * in the frontend, so am having difficulty working out how to apply 
the modified params to the right inset.

One idea makes use of the fact that we allow only one dialog of a particular 
kind to be open in each LyXView. We could have

class LyXView {
public:
        void showDialog(string const & name, inset * inset) {
                ostringstream data;
                inset.write(data);
                if (getDialogs().show(name, data))
                        openedDialog(name) = inset;
        }
        void hideDialog(string const & name) {
                if (getDialogs().hide(name))
                        openedDialog(name) = 0;
        }
        inset * getOpenDialog(string const & name) {
                return openedDialog(name);
        }
private:
        map(string, inset *) openedInsets;
};

void InsetCitation::edit(BufferView * bv, int, int, mouse_button::state)
{
        bv->owner()->showDialog("citation", this);
}

This would also allow the dispatch method to retrieve the open inset when it 
is passed data and apply it as it chooses. The frontends would need know 
nothing about the insets themselves. Ie, if 
LyXView::getOpenDialog("citation") returns an inset, apply the data to it. 
If it returns a null pointer, create a new inset at the current cursor 
position.

Does this sound like a viable plan?

-- 
Angus

Reply via email to