On Mon, Aug 19, 2002 at 07:46:08PM +0300, Martin Vermeer wrote: > Anyway, when the ongoing compilation ends, this problem will be > obsolete. I have introduced a boolean HasOption, as per your suggestion.
Here is the code. 2002-08-19 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/insetshorttitle.[Ch]: Added "short title" 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 (boolean) HasOption 1 for that layout. -- Martin Vermeer [EMAIL PROTECTED] Helsinki University of Technology Department of Surveying P.O. Box 1200, FIN-02015 HUT, Finland :wq
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/19 16:58:11 @@ -68,6 +68,7 @@ #include "insets/insetcaption.h" #include "insets/insetfloatlist.h" #include "insets/insetspecialchar.h" +#include "insets/insetshorttitle.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_SHORTTITLE: + + if (style->hasoption) + insertAndEditInset(new InsetShortTitle(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/19 16:58:12 @@ -247,6 +247,8 @@ void LyXAction::init() ReadOnly }, { LFUN_INSERT_LABEL, "label-insert", N_("Insert Label"), Noop }, + { LFUN_INSET_SHORTTITLE, "shorttitle-insert", N_("Insert Short Title"), + 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/19 16:58:14 @@ -71,6 +71,7 @@ #include "insets/insetgraphics.h" #include "insets/insetfoot.h" #include "insets/insetmarginal.h" +#include "insets/insetshorttitle.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 == "ShortTitle") { + inset = new InsetShortTitle(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/19 16:58:15 @@ -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_SHORTTITLE, // 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/19 16:58:17 @@ -535,6 +535,9 @@ FuncStatus LyXFunc::getStatus(FuncReques case LFUN_INSERT_LABEL: code = Inset::LABEL_CODE; break; + case LFUN_INSET_SHORTTITLE: + code = Inset::SHORTTITLE_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/19 16:58:17 @@ -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/19 16:58:17 @@ -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/19 16:58:19 @@ -32,6 +32,7 @@ #include "insets/insetinclude.h" #include "insets/insetbib.h" #include "insets/insettext.h" +#include "insets/insetshorttitle.h" #include "support/filetools.h" #include "support/lstrings.h" @@ -1092,6 +1088,20 @@ int Paragraph::getPositionOfInset(Inset return -1; } +//InsetList::iterator Paragraph::shortTitleInset() const +InsetShortTitle * Paragraph::shortTitleInset() const +{ + // Find the entry. + InsetList::iterator it = insetlist.begin(); + InsetList::iterator end = insetlist.end(); + for (; it != end; ++it) { + Inset * ins = it.getInset(); + if (ins->lyxCode() == Inset::SHORTTITLE_CODE) { + return static_cast<InsetShortTitle *>(ins); + } + } + return 0; +} Paragraph * Paragraph::TeXOnePar(Buffer const * buf, BufferParams const & bparams, @@ -1187,11 +1197,20 @@ Paragraph * Paragraph::TeXOnePar(Buffer texrow.newline(); } + InsetShortTitle * it = shortTitleInset(); switch (style->latextype) { case LATEX_COMMAND: os << '\\' - << style->latexname() - << style->latexparam(); + << style->latexname(); + + // Separate handling of shorttitle inset. + // This means you can put it into ANY LaTeX cmd + if (style->hasoption) { + if (it != 0) + it->latexOptional(buf, os, false, false); + } + else + os << style->latexparam(); break; case LATEX_ITEM_ENVIRONMENT: if (bibkey) { Index: paragraph.h =================================================================== RCS file: /cvs/lyx/lyx-devel/src/paragraph.h,v retrieving revision 1.44 diff -u -p -r1.44 paragraph.h --- paragraph.h 2002/08/15 07:53:46 1.44 +++ paragraph.h 2002/08/19 16:58:20 @@ -27,6 +27,7 @@ class BufferParams; class BufferView; class Counters; class InsetBibKey; +class InsetShortTitle; class Language; class LaTeXFeatures; class ParagraphParameters; @@ -313,6 +314,9 @@ public: /// returns -1 if inset not found int getPositionOfInset(Inset const * inset) const; + /// MV + InsetShortTitle * shortTitleInset() const; + /// some good comment here John? Paragraph * getParFromID(int id) const; Index: paragraph_pimpl.C =================================================================== RCS file: /cvs/lyx/lyx-devel/src/paragraph_pimpl.C,v retrieving revision 1.42 diff -u -p -r1.42 paragraph_pimpl.C --- paragraph_pimpl.C 2002/08/11 15:03:51 1.42 +++ paragraph_pimpl.C 2002/08/19 16:58:20 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/19 16:58:27 @@ -115,7 +115,9 @@ public: /// FLOAT_LIST_CODE, /// - INDEX_PRINT_CODE + INDEX_PRINT_CODE, + /// + SHORTTITLE_CODE }; ///
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 + HasOption 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 " + HasOption 1 # standard font definition Font @@ -73,6 +74,7 @@ Style Section Align Block AlignPossible Block, Left LabelType Counter_Section + HasOption 1 # standard font definition Font @@ -97,6 +99,7 @@ Style Subsection Align Block AlignPossible Block, Left LabelType Counter_Subsection + HasOption 1 # standard font definition Font @@ -121,6 +124,7 @@ Style Subsubsection Align Block AlignPossible Block, Left LabelType Counter_SubSubSection + HasOption 1 # standard font definition Font @@ -145,6 +149,7 @@ Style Paragraph Align Block AlignPossible Block, Left LabelType Counter_Paragraph + HasOption 1 # standard font definition Font @@ -170,6 +175,7 @@ Style Subparagraph Align Block AlignPossible Block, Left LabelType Counter_SubParagraph + HasOption 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 + HasOption 0 End # Section* style definition @@ -30,6 +31,7 @@ Style Section* Margin Static LatexName section* LabelType No_Label + HasOption 0 End # Subsection* style definition @@ -38,6 +40,7 @@ Style Subsection* Margin Static LatexName subsection* LabelType No_Label + HasOption 0 End # Subsubsection* style definition @@ -46,6 +49,7 @@ Style Subsubsection* Margin Static LatexName subsubsection* LabelType No_Label + HasOption 0 End # Paragraph* style definition @@ -54,6 +58,7 @@ Style Paragraph* Margin Static LatexName paragraph* LabelType No_Label + HasOption 0 End # Subparagraph* style definition @@ -62,5 +67,6 @@ Style Subparagraph* Margin Static LatexName subparagraph* LabelType No_Label + HasOption 0 End
// -*- C++ -*- /* This file is part of* * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich * Copyright 1995-2001 The LyX Team * * ====================================================== */ #ifndef INSETSHORTTITLE_H #define INSETSHORTTITLE_H #ifdef __GNUG__ #pragma interface #endif #include "insettext.h" #include "insetcollapsable.h" class InsetShortTitle : public InsetCollapsable { public: InsetShortTitle(BufferParams const &); /// InsetShortTitle(InsetShortTitle const &, bool same_id = false); Inset * clone(Buffer const &, bool same_id = false) const; /// //void draw(BufferView *, LyXFont const &, int, float &, bool) ; /// EDITABLE editable() const { return IS_EDITABLE; } /// Inset::Code lyxCode() const { return Inset::SHORTTITLE_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
/* 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 "insetshorttitle.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; /* Shorttitle. Used to insert a short version of sectioning header etc. * automatically */ InsetShortTitle::InsetShortTitle(BufferParams const & ins) : InsetCollapsable(ins, true) { LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::collapsable); setLabelFont(font); setLabel(_("opt")); } InsetShortTitle::InsetShortTitle(InsetShortTitle const & in, bool same_id) : InsetCollapsable(in, same_id) { LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::collapsable); setLabelFont(font); setLabel(_("opt")); } Inset * InsetShortTitle::clone(Buffer const &, bool same_id) const { return new InsetShortTitle(*this, same_id); } #if 0 void InsetShortTitle::draw(BufferView * bv, LyXFont const & f, int baseline, float & x, bool cleared) { //InsetText::setDrawFrame(bv, ALWAYS); InsetCollapsable::draw(bv, f, baseline, x, cleared); x += width_collapsed(); } #endif string const InsetShortTitle::editMessage() const { return _("Opened Short Title Inset"); } void InsetShortTitle::write(Buffer const * buf, ostream & os) const { os << "ShortTitle" << "\n"; InsetCollapsable::write(buf, os); } int InsetShortTitle::latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const { return 0; } int InsetShortTitle::latexOptional(Buffer const * buf, ostream & os, bool fragile, bool fp) const { os << '['; int const i = inset.latex(buf, os, false, false); os << ']'; return i + 2; }
msg43129/pgp00000.pgp
Description: PGP signature