From: Jean-Marc Lasgouttes Date: Fri, 23 Aug 2002 09:05:32 +0000 (+0000) Subject: the optional argument patch from martin X-Git-Tag: 1.6.10~18488 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=11953d373474f9a82737c66c275f4b85c0a3a028;p=features.git the optional argument patch from martin git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5079 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/CREDITS b/lib/CREDITS index ba15a74906..d45e5277fd 100644 --- a/lib/CREDITS +++ b/lib/CREDITS @@ -252,6 +252,7 @@ Gnome frontend @bMartin Vermeer @iE-mail: martin.vermeer@hut.fi + support for optional argument in sections/captions svjour/svjog, egs and llncs document classes Lot of bug hunting (and fixing!) @bJuergen Vigna diff --git a/lib/ChangeLog b/lib/ChangeLog index 5336b20b3c..a41fce5e36 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,4 +1,15 @@ +2002-08-23 Jean-Marc Lasgouttes + * ui/default.ui: add menu entry for optional-insert + + * CREDITS: update Martin's entry + +2002-08-20 Martin Vermeer + + * layouts/stdlayouts.inc: + * layouts/stdsections.inc: + * layouts/stdstarsections.inc: aded OptionalArgs tags to the + relevant layouts 2002-08-21 André Pönitz diff --git a/lib/layouts/stdlayouts.inc b/lib/layouts/stdlayouts.inc index 92136c4bcb..b96fc33c03 100644 --- a/lib/layouts/stdlayouts.inc +++ b/lib/layouts/stdlayouts.inc @@ -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 + + diff --git a/lib/layouts/stdsections.inc b/lib/layouts/stdsections.inc index a1ead72137..f11c7c68be 100644 --- a/lib/layouts/stdsections.inc +++ b/lib/layouts/stdsections.inc @@ -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 diff --git a/lib/layouts/stdstarsections.inc b/lib/layouts/stdstarsections.inc index 14561639e5..ae432454f9 100644 --- a/lib/layouts/stdstarsections.inc +++ b/lib/layouts/stdstarsections.inc @@ -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 diff --git a/lib/ui/default.ui b/lib/ui/default.ui index c3f54638ee..8140729291 100644 --- a/lib/ui/default.ui +++ b/lib/ui/default.ui @@ -174,6 +174,7 @@ Menuset Item "Label...|L" "label-insert" Item "Footnote|F" "footnote-insert" Item "Marginal Note|M" "marginalnote-insert" + Item "Short title" "optional-insert" Item "Index Entry|I" "index-insert" Item "URL...|U" "url-insert" Item "Note|N" "note-insert" diff --git a/po/POTFILES.in b/po/POTFILES.in index 96ab664a0f..ca6ca71010 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -8,6 +8,7 @@ src/converter.C src/CutAndPaste.C src/debug.C src/exporter.C +src/ext_l10n.h src/FloatList.C src/frontends/controllers/biblio.C src/frontends/controllers/ButtonController.h @@ -133,6 +134,7 @@ src/insets/insetlist.C src/insets/insetmarginal.C src/insets/insetminipage.C src/insets/insetnote.C +src/insets/insetoptarg.C src/insets/insetparent.C src/insets/insetref.C src/insets/insettabular.C diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index ba52669af9..40c4069c47 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -61,6 +61,7 @@ #include "insets/insetminipage.h" #include "insets/insetfloat.h" #include "insets/insettabular.h" +#include "insets/insetoptarg.h" #if 0 #include "insets/insettheorem.h" #include "insets/insetlist.h" @@ -1662,6 +1663,10 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev) insertAndEditInset(new InsetNote(buffer_->params)); break; + case LFUN_INSET_OPTARG: + insertAndEditInset(new InsetOptArg(buffer_->params)); + break; + case LFUN_INSET_FLOAT: // check if the float type exist if (floatList.typeExist(ev.argument)) { diff --git a/src/ChangeLog b/src/ChangeLog index f63d30869f..7732631739 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2002-08-22 Jean-Marc Lasgouttes + + * lyxfunc.C (getStatus): handle LFUN_INSET_OPTARG + +2002-08-20 Martin Vermeer + + * 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 + OptionalArgs 1 + (or more generally, a nonzero value) for that layout. + 2002-08-22 Lars Gullik Bjønnes * paragraph.h: remove the declaration of undefined counters class diff --git a/src/LyXAction.C b/src/LyXAction.C index f20f8b5227..1f4b832e6f 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -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 }, diff --git a/src/buffer.C b/src/buffer.C index 29fff0e612..44ac43836b 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -73,6 +73,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" @@ -1115,6 +1116,8 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& 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") { diff --git a/src/commandtags.h b/src/commandtags.h index 6469b95ee0..dcd1e1e019 100644 --- a/src/commandtags.h +++ b/src/commandtags.h @@ -282,6 +282,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 diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index 4063687fbd..e755ca7b05 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -63,6 +63,8 @@ libinsets_la_SOURCES = \ insetminipage.h \ insetnote.C \ insetnote.h \ + insetoptarg.C \ + insetoptarg.h \ insetparent.C \ insetparent.h \ insetquotes.C \ diff --git a/src/insets/inset.h b/src/insets/inset.h index e7fbd1a848..4f7467838b 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -115,7 +115,9 @@ public: /// FLOAT_LIST_CODE, /// - INDEX_PRINT_CODE + INDEX_PRINT_CODE, + /// + OPTARG_CODE }; /// diff --git a/src/insets/insetoptarg.C b/src/insets/insetoptarg.C new file mode 100644 index 0000000000..25502904f3 --- /dev/null +++ b/src/insets/insetoptarg.C @@ -0,0 +1,84 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995 Matthias Ettrich + * Copyright 1995-2001 The LyX Team. + * + * ====================================================== */ + +#include + +#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; +} + diff --git a/src/insets/insetoptarg.h b/src/insets/insetoptarg.h new file mode 100644 index 0000000000..7f30ce292d --- /dev/null +++ b/src/insets/insetoptarg.h @@ -0,0 +1,45 @@ +// -*- 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 diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 9f0327bc49..c8e7c64cb0 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -361,6 +361,10 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const break; } + case LFUN_INSET_OPTARG: + disable = (TEXT(false)->cursor.par()->layout()->optionalargs == 0); + break; + case LFUN_TABULAR_FEATURE: if (mathcursor) { #if 0 @@ -527,6 +531,9 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const 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; @@ -577,9 +584,8 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const default: break; } - if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) { + if (code != Inset::NO_CODE && tli && !tli->insetAllowed(code)) disable = true; - } if (disable) flag.disabled(true); diff --git a/src/lyxlayout.C b/src/lyxlayout.C index 969e0ba538..ca31bee99c 100644 --- a/src/lyxlayout.C +++ b/src/lyxlayout.C @@ -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, LyXTextClass const & tclass) { "newline", LT_NEWLINE }, { "nextnoindent", LT_NEXTNOINDENT }, { "obsoletedby", LT_OBSOLETEDBY }, + { "optionalargs", LT_OPTARGS }, { "parindent", LT_PARINDENT }, { "parsep", LT_PARSEP }, { "parskip", LT_PARSKIP }, @@ -245,6 +248,10 @@ bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass) intitle = lexrc.next() && lexrc.getInteger(); break; + case LT_OPTARGS: + optionalargs = lexrc.next() && lexrc.getInteger(); + break; + case LT_NEED_PROTECT: needprotect = lexrc.next() && lexrc.getInteger(); break; diff --git a/src/lyxlayout.h b/src/lyxlayout.h index 2566ece2ed..40b38ec7c1 100644 --- a/src/lyxlayout.h +++ b/src/lyxlayout.h @@ -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_; diff --git a/src/paragraph.C b/src/paragraph.C index 01f2f542fd..2f668a362d 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -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" @@ -955,6 +956,23 @@ int Paragraph::getPositionOfInset(Inset const * inset) const 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(ins); + } + } + return 0; +} + +} // end namespace Paragraph * Paragraph::TeXOnePar(Buffer const * buf, BufferParams const & bparams, @@ -1053,8 +1071,16 @@ Paragraph * Paragraph::TeXOnePar(Buffer const * buf, 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) {