On Tue, Aug 20, 2002 at 07:14:30PM +0200, Lars Gullik Bjønnes wrote: ...
> | Once this patch is in, anything is possible ;-) > > I'd rather wait with applying a patch, than apply something that > needs to be tweeked right away. > > -- > Lgb 2002-08-20 Martin Vermeer <[EMAIL PROTECTED]> (with lots of help!) * layouts/stdlayouts.inc: * layouts/stdsections.inc: * layouts/stdstarsections.inc: * BufferView_pimpl.C: * LyXAction.C: * buffer.C: * commandtags.h: * lyxfunc.C: * paragraph.[Ch]: * text2.C: * insets/insetoptarg.[Ch]: Added "optional argument" collapsible inset and code to make it work with the paragraph code. The inset can be anywhere in the paragraph, but will only do the expected thing in LaTeX if the layout file contains the parameter line (integer) OptionalArgs 1 (or more generally, a nonzero value) for that layout. Happy now? Martin
Index: BufferView_pimpl.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.283 diff -u -p -r1.283 BufferView_pimpl.C --- BufferView_pimpl.C 2002/08/18 17:15:23 1.283 +++ BufferView_pimpl.C 2002/08/20 13:43:10 @@ -68,6 +68,7 @@ #include "insets/insetcaption.h" #include "insets/insetfloatlist.h" #include "insets/insetspecialchar.h" +#include "insets/insetoptarg.h" #include "mathed/formulabase.h" @@ -1498,6 +1497,9 @@ bool BufferView::Pimpl::dispatch(FuncReq LyXTextClass const & tclass = buffer_->params.getLyXTextClass(); + LyXText * lt = bv_->getLyXText(); + LyXLayout_ptr const & style = lt->cursor.par()->layout(); + switch (ev.action) { // --- Misc ------------------------------------------- case LFUN_APPENDIX: @@ -2760,6 +2765,12 @@ bool BufferView::Pimpl::dispatch(FuncReq case LFUN_INSERT_NOTE: insertAndEditInset(new InsetNote(buffer_->params)); + break; + + case LFUN_INSET_OPTARG: + + if (style->optionalargs == 1) + insertAndEditInset(new InsetOptArg(buffer_->params)); break; case LFUN_INSET_FLOAT: Index: LyXAction.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/LyXAction.C,v retrieving revision 1.132 diff -u -p -r1.132 LyXAction.C --- LyXAction.C 2002/08/15 14:33:11 1.132 +++ LyXAction.C 2002/08/20 13:43:10 @@ -247,6 +247,8 @@ void LyXAction::init() ReadOnly }, { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"), Noop }, + { LFUN_INSET_OPTARG, "optional-insert", N_("Insert Optional Argument"), + Noop }, { LFUN_LANGUAGE, "language", N_("Change language"), Noop }, { LFUN_LATEX_LOG, "latex-view-log", N_("View LaTeX log"), ReadOnly }, Index: buffer.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/buffer.C,v retrieving revision 1.371 diff -u -p -r1.371 buffer.C --- buffer.C 2002/08/14 22:15:16 1.371 +++ buffer.C 2002/08/20 13:43:13 @@ -71,6 +71,7 @@ #include "insets/insetgraphics.h" #include "insets/insetfoot.h" #include "insets/insetmarginal.h" +#include "insets/insetoptarg.h" #include "insets/insetminipage.h" #include "insets/insetfloat.h" #include "insets/insettabular.h" @@ -1634,6 +1635,8 @@ void Buffer::readInset(LyXLex & lex, Par inset = new InsetFoot(params); } else if (tmptok == "Marginal") { inset = new InsetMarginal(params); + } else if (tmptok == "OptArg") { + inset = new InsetOptArg(params); } else if (tmptok == "Minipage") { inset = new InsetMinipage(params); } else if (tmptok == "Float") { Index: commandtags.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/commandtags.h,v retrieving revision 1.97 diff -u -p -r1.97 commandtags.h --- commandtags.h 2002/08/15 14:33:11 1.97 +++ commandtags.h 2002/08/20 13:43:14 @@ -288,6 +288,7 @@ enum kb_action { LFUN_FORKS_SHOW, // Angus 16 Feb 2002 LFUN_FORKS_KILL, // Angus 16 Feb 2002 LFUN_TOOLTIPS_TOGGLE, // Angus 8 Mar 2002 + LFUN_INSET_OPTARG, // Martin 12 Aug 2002 LFUN_MOUSE_PRESS, // André 9 Aug 2002 LFUN_MOUSE_MOTION, // André 9 Aug 2002 LFUN_MOUSE_RELEASE, // André 9 Aug 2002 Index: lyxfunc.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxfunc.C,v retrieving revision 1.369 diff -u -p -r1.369 lyxfunc.C --- lyxfunc.C 2002/08/15 14:33:11 1.369 +++ lyxfunc.C 2002/08/20 13:43:15 @@ -535,6 +535,9 @@ FuncStatus LyXFunc::getStatus(FuncReques case LFUN_INSERT_LABEL: code = Inset::LABEL_CODE; break; + case LFUN_INSET_OPTARG: + code = Inset::OPTARG_CODE; + break; case LFUN_REF_INSERT: code = Inset::REF_CODE; break; Index: lyxlayout.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxlayout.C,v retrieving revision 1.7 diff -u -p -r1.7 lyxlayout.C --- lyxlayout.C 2002/07/20 20:47:53 1.7 +++ lyxlayout.C 2002/08/20 17:24:08 @@ -59,6 +59,7 @@ enum LayoutTags { LT_ENDLABELTYPE, LT_LATEXNAME, LT_LATEXPARAM, + LT_OPTARGS, LT_LATEXTYPE, LT_LEFTMARGIN, LT_NEED_PROTECT, @@ -83,6 +84,7 @@ LyXLayout::LyXLayout () margintype = MARGIN_STATIC; latextype = LATEX_PARAGRAPH; intitle = false; + optionalargs = 0; needprotect = false; keepempty = false; font = LyXFont(LyXFont::ALL_INHERIT); @@ -146,6 +148,7 @@ bool LyXLayout::Read (LyXLex & lexrc, Ly { "newline", LT_NEWLINE }, { "nextnoindent", LT_NEXTNOINDENT }, { "obsoletedby", LT_OBSOLETEDBY }, + { "optionalargs", LT_OPTARGS }, { "parindent", LT_PARINDENT }, { "parsep", LT_PARSEP }, { "parskip", LT_PARSKIP }, @@ -243,6 +246,10 @@ bool LyXLayout::Read (LyXLex & lexrc, Ly case LT_INTITLE: intitle = lexrc.next() && lexrc.getInteger(); + break; + + case LT_OPTARGS: + optionalargs = lexrc.next() && lexrc.getInteger(); break; case LT_NEED_PROTECT: Index: lyxlayout.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/lyxlayout.h,v retrieving revision 1.4 diff -u -p -r1.4 lyxlayout.h --- lyxlayout.h 2002/07/20 20:47:53 1.4 +++ lyxlayout.h 2002/08/20 13:43:16 @@ -188,6 +188,9 @@ public: LYX_LATEX_TYPES latextype; /// Does this object belong in the title part of the document? bool intitle; + /// Does this layout allow for an optional parameter? + int optionalargs; + private: /// Name of the layout/paragraph environment string name_; Index: paragraph.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/paragraph.C,v retrieving revision 1.222 diff -u -p -r1.222 paragraph.C --- paragraph.C 2002/08/15 07:53:46 1.222 +++ paragraph.C 2002/08/20 13:43:18 @@ -32,6 +32,7 @@ #include "insets/insetinclude.h" #include "insets/insetbib.h" #include "insets/insettext.h" +#include "insets/insetoptarg.h" #include "support/filetools.h" #include "support/lstrings.h" @@ -1092,7 +1087,24 @@ int Paragraph::getPositionOfInset(Inset return -1; } +namespace { +InsetOptArg * optArgInset(Paragraph const & par) +{ + // Find the entry. + InsetList::iterator it = par.insetlist.begin(); + InsetList::iterator end = par.insetlist.end(); + for (; it != end; ++it) { + Inset * ins = it.getInset(); + if (ins->lyxCode() == Inset::OPTARG_CODE) { + return static_cast<InsetOptArg *>(ins); + } + } + return 0; +} + +} // end namespace + Paragraph * Paragraph::TeXOnePar(Buffer const * buf, BufferParams const & bparams, ostream & os, TexRow & texrow, @@ -1190,8 +1202,16 @@ Paragraph * Paragraph::TeXOnePar(Buffer switch (style->latextype) { case LATEX_COMMAND: os << '\\' - << style->latexname() - << style->latexparam(); + << style->latexname(); + + // Separate handling of optional argument inset. + if (style->optionalargs == 1) { + InsetOptArg * it = optArgInset(*this); + if (it != 0) + it->latexOptional(buf, os, false, false); + } + else + os << style->latexparam(); break; case LATEX_ITEM_ENVIRONMENT: if (bibkey) { Index: insets/inset.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/insets/inset.h,v retrieving revision 1.55 diff -u -p -r1.55 inset.h --- insets/inset.h 2002/08/13 17:43:38 1.55 +++ insets/inset.h 2002/08/20 13:43:26 @@ -115,7 +115,9 @@ public: /// FLOAT_LIST_CODE, /// - INDEX_PRINT_CODE + INDEX_PRINT_CODE, + /// + OPTARG_CODE }; /// Index: insets/Makefile.am =================================================================== RCS file: /cvs/lyx/lyx-devel/src/insets/Makefile.am,v retrieving revision 1.47 diff -u -p -r1.47 Makefile.am --- insets/Makefile.am 2002/07/04 13:54:28 1.47 +++ insets/Makefile.am 2002/08/20 14:01:21 @@ -63,6 +63,8 @@ libinsets_la_SOURCES = \ insetminipage.h \ insetnote.C \ insetnote.h \ + insetoptarg.C \ + insetoptarg.h \ insetparent.C \ insetparent.h \ insetquotes.C \
Index: stdlayouts.inc =================================================================== RCS file: /cvs/lyx/lyx-devel/lib/layouts/stdlayouts.inc,v retrieving revision 1.3 diff -u -p -r1.3 stdlayouts.inc --- stdlayouts.inc 2001/07/08 12:52:14 1.3 +++ stdlayouts.inc 2002/08/19 16:56:33 @@ -92,10 +92,13 @@ Style Caption Align Center AlignPossible Center LabelType Sensitive - LabelString Caption + LabelString Caption + OptionalArgs 1 # label font definition LabelFont Series Bold EndFont End + + Index: stdsections.inc =================================================================== RCS file: /cvs/lyx/lyx-devel/lib/layouts/stdsections.inc,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 stdsections.inc --- stdsections.inc 1999/09/27 18:44:34 1.1.1.1 +++ stdsections.inc 2002/08/19 16:56:33 @@ -49,6 +49,7 @@ Style Chapter LabelType Counter_Chapter LabelString "Chapter " LabelStringAppendix "Appendix " + OptionalArgs 1 # standard font definition Font @@ -73,6 +74,7 @@ Style Section Align Block AlignPossible Block, Left LabelType Counter_Section + OptionalArgs 1 # standard font definition Font @@ -97,6 +99,7 @@ Style Subsection Align Block AlignPossible Block, Left LabelType Counter_Subsection + OptionalArgs 1 # standard font definition Font @@ -121,6 +124,7 @@ Style Subsubsection Align Block AlignPossible Block, Left LabelType Counter_SubSubSection + OptionalArgs 1 # standard font definition Font @@ -145,6 +149,7 @@ Style Paragraph Align Block AlignPossible Block, Left LabelType Counter_Paragraph + OptionalArgs 1 # standard font definition Font @@ -170,6 +175,7 @@ Style Subparagraph Align Block AlignPossible Block, Left LabelType Counter_SubParagraph + OptionalArgs 1 # standard font definition Font Index: stdstarsections.inc =================================================================== RCS file: /cvs/lyx/lyx-devel/lib/layouts/stdstarsections.inc,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 stdstarsections.inc --- stdstarsections.inc 1999/09/27 18:44:34 1.1.1.1 +++ stdstarsections.inc 2002/08/19 16:56:33 @@ -22,6 +22,7 @@ Style Chapter* Margin Static LatexName chapter* LabelType No_Label + OptionalArgs 0 End # Section* style definition @@ -30,6 +31,7 @@ Style Section* Margin Static LatexName section* LabelType No_Label + OptionalArgs 0 End # Subsection* style definition @@ -38,6 +40,7 @@ Style Subsection* Margin Static LatexName subsection* LabelType No_Label + OptionalArgs 0 End # Subsubsection* style definition @@ -46,6 +49,7 @@ Style Subsubsection* Margin Static LatexName subsubsection* LabelType No_Label + OptionalArgs 0 End # Paragraph* style definition @@ -54,6 +58,7 @@ Style Paragraph* Margin Static LatexName paragraph* LabelType No_Label + OptionalArgs 0 End # Subparagraph* style definition @@ -62,5 +67,6 @@ Style Subparagraph* Margin Static LatexName subparagraph* LabelType No_Label + OptionalArgs 0 End
/* This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team. * * ====================================================== */ #include <config.h> #ifdef __GNUG__ #pragma implementation #endif #include "debug.h" #include "insetoptarg.h" #include "support/LOstream.h" #include "frontends/Alert.h" #include "support/lstrings.h" //frontStrip, strip #include "lyxtext.h" #include "buffer.h" #include "gettext.h" #include "BufferView.h" #include "support/lstrings.h" using std::ostream; using std::vector; using std::pair; /* OptArg. Used to insert a short version of sectioning header etc. * automatically, or other optional LaTeX arguments */ InsetOptArg::InsetOptArg(BufferParams const & ins) : InsetCollapsable(ins, true) { LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::collapsable); setLabelFont(font); setLabel(_("opt")); } InsetOptArg::InsetOptArg(InsetOptArg const & in, bool same_id) : InsetCollapsable(in, same_id) { LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::collapsable); setLabelFont(font); setLabel(_("opt")); } Inset * InsetOptArg::clone(Buffer const &, bool same_id) const { return new InsetOptArg(*this, same_id); } string const InsetOptArg::editMessage() const { return _("Opened Optional Argument Inset"); } void InsetOptArg::write(Buffer const * buf, ostream & os) const { os << "OptArg" << "\n"; InsetCollapsable::write(buf, os); } int InsetOptArg::latex(Buffer const *, ostream &, bool, bool) const { return 0; } int InsetOptArg::latexOptional(Buffer const * buf, ostream & os, bool, bool fp) const { os << '['; int const i = inset.latex(buf, os, false, fp); os << ']'; return i + 2; }
// -*- C++ -*- /* This file is part of* * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team * * ====================================================== */ #ifndef INSETOPTARG_H #define INSETOPTARG_H #ifdef __GNUG__ #pragma interface #endif #include "insettext.h" #include "insetcollapsable.h" class InsetOptArg : public InsetCollapsable { public: InsetOptArg(BufferParams const &); /// InsetOptArg(InsetOptArg const &, bool same_id = false); Inset * clone(Buffer const &, bool same_id = false) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// Inset::Code lyxCode() const { return Inset::OPTARG_CODE; } /// string const editMessage() const; /// Standard LaTeX output -- short-circuited int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// Outputting the optional parameter of a LaTeX command int latexOptional(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// void write(Buffer const * buf, ostream & os) const; }; #endif
msg43215/pgp00000.pgp
Description: PGP signature