On Tue, Aug 20, 2002 at 12:15:19PM +0200, Jean-Marc Lasgouttes wrote: > >>>>> "Martin" == Martin Vermeer <[EMAIL PROTECTED]> writes: > > Martin> Hmmm... perhaps. But do you think it is wise to use a name > Martin> that requires an understanding of the LaTeX commands? Anyway, > Martin> as you see the inset label is 'opt' so in fact we are already > Martin> in this situation... feel free to change the name. > > Internally, the code is handled as an optional argument, not as a > shorttitle. That's why I think it is better to name the inset like > that. This has nothing to do with what the user sees... We may keep > the 'short title' wording in menus right now, but I think everything > else should be renamed. > > >> Would you be so kind to rename InsetShortTitle to > >> InsetOptionalArgument (or something else of your choice)? The right > >> time for doing it is definitely now... > > Martin> Find/replace... no big deal. Should I also change > Martin> insetshorttitle.[Ch]? > > Yes, please.
Made all the changes... this patch replaces the first earlier patch (short1.diff). The other one short2.diff is unchanged. I also append the new files insets/insetoptarg.[Ch]. To ADD to CVS. 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->hasoption) + 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 13:43:16 @@ -59,6 +59,7 @@ enum LayoutTags { LT_ENDLABELTYPE, LT_LATEXNAME, LT_LATEXPARAM, + LT_HASOPTION, LT_LATEXTYPE, LT_LEFTMARGIN, LT_NEED_PROTECT, @@ -83,6 +84,7 @@ LyXLayout::LyXLayout () margintype = MARGIN_STATIC; latextype = LATEX_PARAGRAPH; intitle = false; + hasoption = false; needprotect = false; keepempty = false; font = LyXFont(LyXFont::ALL_INHERIT); @@ -127,6 +129,7 @@ bool LyXLayout::Read (LyXLex & lexrc, Ly { "fill_top", LT_FILL_TOP }, { "font", LT_FONT }, { "freespacing", LT_FREE_SPACING }, + { "hasoption", LT_HASOPTION }, { "intitle", LT_INTITLE }, { "itemsep", LT_ITEMSEP }, { "keepempty", LT_KEEPEMPTY }, @@ -243,6 +246,10 @@ bool LyXLayout::Read (LyXLex & lexrc, Ly case LT_INTITLE: intitle = lexrc.next() && lexrc.getInteger(); + break; + + case LT_HASOPTION: + hasoption = 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? + bool hasoption; + 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->hasoption) { + 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 \
/* 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
msg43189/pgp00000.pgp
Description: PGP signature