The following patch cleans up the insetcaption code wrt allowing inset insertion:
- allow graphics inset, since it has been working for some time (but I forgot to tell) - use insetAllowed to disallow some insets (as should be) The is still the input inset that has been forbidden, and I am not sure why. I there a _really_ _good_ reason for that? I can think of valid uses (hint: a file can contain a single word, or a time stamp). This has been my first occasion to test the insetcaption, and I have to say that I still do not know why it is useful... I do not like much the addition of empty lines above and below "just in case" since I do not know many people that would need both... Instead of disabling break_paragraph, it may have been better to change it to handle the break-before/after caption correctly. JMarc
Index: src/insets/insetbase.h =================================================================== --- src/insets/insetbase.h (revision 17024) +++ src/insets/insetbase.h (working copy) @@ -336,7 +336,9 @@ public: /// NOMENCL_CODE, // 45 /// - NOMENCL_PRINT_CODE + NOMENCL_PRINT_CODE, + /// + PAGEBREAK_CODE }; /** returns the Code corresponding to the \c name. Index: src/insets/insetpagebreak.h =================================================================== --- src/insets/insetpagebreak.h (revision 17024) +++ src/insets/insetpagebreak.h (working copy) @@ -23,7 +23,7 @@ class InsetPagebreak : public InsetOld { public: InsetPagebreak() {} - InsetBase::Code lyxCode() const { return InsetBase::LINE_CODE; } + InsetBase::Code lyxCode() const { return InsetBase::PAGEBREAK_CODE; } bool metrics(MetricsInfo &, Dimension &) const; Index: src/insets/insetcaption.C =================================================================== --- src/insets/insetcaption.C (revision 17024) +++ src/insets/insetcaption.C (working copy) @@ -27,6 +27,7 @@ #include "LColor.h" #include "metricsinfo.h" #include "output_latex.h" +#include "outputparams.h" #include "paragraph.h" #include "TocBackend.h" @@ -179,38 +180,36 @@ InsetBase * InsetCaption::editXY(LCursor } +bool InsetCaption::insetAllowed(InsetBase::Code code) const +{ + switch (code) { + case FLOAT_CODE: + case TABULAR_CODE: + case INCLUDE_CODE: + case WRAP_CODE: + case CAPTION_CODE: + case PAGEBREAK_CODE: + return false; + default: + return InsetText::insetAllowed(code); + } +} + + bool InsetCaption::getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus & status) const { switch (cmd.action) { - case LFUN_CAPTION_INSERT: - case LFUN_FLOAT_INSERT: - case LFUN_FLOAT_WIDE_INSERT: - case LFUN_WRAP_INSERT: case LFUN_PARAGRAPH_MOVE_UP: case LFUN_PARAGRAPH_MOVE_DOWN: case LFUN_BREAK_PARAGRAPH: case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT: case LFUN_BREAK_PARAGRAPH_SKIP: case LFUN_PARAGRAPH_SPACING: - case LFUN_PAGEBREAK_INSERT: - case LFUN_TABULAR_INSERT: status.enabled(false); return true; - case LFUN_DIALOG_SHOW_NEW_INSET: - case LFUN_INSET_INSERT: { - string const name = cmd.getArg(0); - if (name == "float" - || name == "graphics" - || name == "include" - || name == "wrap" - ) { - status.enabled(false); - return true; - } - } default: return InsetText::getStatus(cur, cmd, status); } @@ -218,13 +217,17 @@ bool InsetCaption::getStatus(LCursor & c int InsetCaption::latex(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const + OutputParams const & runparams_in) const { // This is a bit too simplistic to take advantage of // caption options we must add more later. (Lgb) // This code is currently only able to handle the simple // \caption{...}, later we will make it take advantage // of the one of the caption packages. (Lgb) + OutputParams runparams = runparams_in; + // FIXME: actually, it is moving only when there is no + // optional argument. + runparams.moving_arg = true; os << "\\caption"; int l = latexOptArgInsets(buf, paragraphs()[0], os, runparams, 1); os << '{'; Index: src/insets/insetcaption.h =================================================================== --- src/insets/insetcaption.h (revision 17024) +++ src/insets/insetcaption.h (working copy) @@ -52,6 +52,8 @@ public: /// virtual InsetBase * editXY(LCursor & cur, int x, int y); /// + bool insetAllowed(InsetBase::Code code) const; + /// virtual bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const; /// virtual bool wide() const { return false; }