I mentioned yesterday that we can now open all the dialogs from the 
command line, but that subsequently pressing 'Apply' has no effect 
for InsetCollabsable-derived insets.

Ie, 'dialog-show-new-inset minipage' works but 'Apply' doesn't result 
in a minipage inset being inserted.

'Apply' leads to this LFUN in LyXText::dispatch being invoked:

        case LFUN_INSET_INSERT: {
                InsetOld * inset = createInset(cmd);
                lyxerr << "LFUN_INSET_INSERT " << cmd.argument << "\ninset "
                       << (inset ? "created" : "not created") << std::endl;

                if (inset && !bv->insertInset(inset))
                        delete inset;
                break;
        }

With the resulting message:

LFUN_INSET_INSERT minipage Minipage
position 1
inner_position 0
height "0pt"
width "100col%"

inset not created

Which isn't surprising because factory.C's creatInset doesn't know how 
to handle a LFUN_INSET_INSERT that wants to create a minipage. 
Nonetheless, that would be trivial to do.

Moving on...

LFUN_INSET_INSERT isn't the usual way to create a minipage inset. 
Indeed, it was created simply to handle button-like insets. Putting 
that another way, LFUN_INSET_INSERT is simply a more powerful version 
of this:

        case LFUN_INDEX_PRINT:
        case LFUN_TOC_INSERT:
        case LFUN_HFILL:
        case LFUN_INSERT_LINE:
        case LFUN_INSERT_PAGEBREAK:
                doInsertInset(*this, cmd, false, false);

More powerful because 'cmd' can contain user-specified data; we don't 
have to use the default values when creating the inset.) In fact, we 
can do away entirely with the above block, replacing it with calls:

        "inset-insert index-print"
        "inset-insert toc"
        "inset-insert hfill"
        "inset-insert line"
        "inset-insert pagebreak"

simply by modifying factory.C's createInset to handle these various 
args.

But hang on. If we can do this for these LFUNs, can we not do the same 
for LFUN_INSET_MINIPAGE et al.? Of course. Tell factory.C's 
createInset how to handle "LFUN_INSET_INSERT minipage <data>" where 
<data> may be an empty string (effectively as now) but could also 
contain the data from the dialog and we're half way there. 
Thereafter, we would need to tell the LFUN to handle the cursor 
placement et al.

Ie, it becomes

        case LFUN_INSET_INSERT: {
                InsetOld * inset = createInset(cmd);

                if (!inset || !bv->insertInset(inset)) {
                        delete inset;
                        break;
                }

                string const name = cmd.getArg(0);
                if (name == "bibitem" ||
                    name == "box" ||
                    name == "branch" ||
                    name == "charstyle" ||
                    name == "environment" ||
                    name == "ert" ||
                    name == "float" ||
                    name == "footnote" ||
                    name == "marginal" ||
                    name == "minipage" ||
                    name == "note" ||
                    name == "optarg" ||
                    name == "tabular" ||
                    name == "widefloat" ||
                    name == "wrap")
                        doInsertInset(*this, cmd.view(), true, true);
                else if (name == "index")
                        doInsertInset(*this, cmd.view(), true, false);

where doInsertInset is a modified version of the existing function 
that no longer calls createInset itself but is otherwise unchanged.

This would allow us to get rid of all these LFUNs (below).

Sounds like a plan or should I look elsewhere for things to meddle 
with?

Angus

        case LFUN_INSERT_NOTE:
        case LFUN_INSERT_CHARSTYLE:
        case LFUN_INSERT_BOX:
        case LFUN_INSERT_BRANCH:
        case LFUN_INSERT_BIBITEM:
        case LFUN_INSET_ERT:
        case LFUN_INSET_FLOAT:
        case LFUN_INSET_FOOTNOTE:
        case LFUN_INSET_MARGINAL:
        case LFUN_INSET_MINIPAGE:
        case LFUN_INSET_OPTARG:
        case LFUN_INSET_WIDE_FLOAT:
        case LFUN_INSET_WRAP:
        case LFUN_TABULAR_INSERT:
        case LFUN_ENVIRONMENT_INSERT:
                // Open the inset, and move the current selection
                // inside it.
                doInsertInset(*this, cmd, true, true);
                break;

        case LFUN_INDEX_INSERT:
                // Just open the inset
                doInsertInset(*this, cmd, true, false);
                break;

        case LFUN_INDEX_PRINT:
        case LFUN_TOC_INSERT:
        case LFUN_HFILL:
        case LFUN_INSERT_LINE:
        case LFUN_INSERT_PAGEBREAK:
                // do nothing fancy
                doInsertInset(*this, cmd, false, false);
                break;


Reply via email to