]> git.lyx.org Git - features.git/commitdiff
the optional argument patch from martin
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 23 Aug 2002 09:05:32 +0000 (09:05 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 23 Aug 2002 09:05:32 +0000 (09:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5079 a592a061-630c-0410-9148-cb99ea01b6c8

20 files changed:
lib/CREDITS
lib/ChangeLog
lib/layouts/stdlayouts.inc
lib/layouts/stdsections.inc
lib/layouts/stdstarsections.inc
lib/ui/default.ui
po/POTFILES.in
src/BufferView_pimpl.C
src/ChangeLog
src/LyXAction.C
src/buffer.C
src/commandtags.h
src/insets/Makefile.am
src/insets/inset.h
src/insets/insetoptarg.C [new file with mode: 0644]
src/insets/insetoptarg.h [new file with mode: 0644]
src/lyxfunc.C
src/lyxlayout.C
src/lyxlayout.h
src/paragraph.C

index ba15a74906cb2e7c63319b9e10db6caa378c1f42..d45e5277fd025d6f059c770f71d4adef6a4155c7 100644 (file)
    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
index 5336b20b3c8013323877b96e5874b76041ed85d7..a41fce5e363ccc3d27c62b251aff60bd017a2898 100644 (file)
@@ -1,4 +1,15 @@
+2002-08-23  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
 
+       * ui/default.ui: add menu entry for optional-insert
+
+       * CREDITS: update Martin's entry
+
+2002-08-20  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * layouts/stdlayouts.inc:
+       * layouts/stdsections.inc:
+       * layouts/stdstarsections.inc: aded OptionalArgs tags to the
+       relevant layouts
 
 2002-08-21  André Pönitz <poenitz@gmx.net>
 
index 92136c4bcbe19f864509de4611b7b846450af636..b96fc33c03220a1aba2aa331330c2349466367f6 100644 (file)
@@ -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 a1ead7213721a530fb0a591faf1efab891595a6a..f11c7c68bef4329abf4aae1e148ae6360f1b2ef9 100644 (file)
@@ -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 14561639e5fa39925e029367945e336803568909..ae432454f9e296fa9ce6a984902246e1e02c0163 100644 (file)
@@ -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
 
index c3f54638ee2ca152fbb052d6d6bba551ac7b7286..81407292916733ff126d65f189a03de7c223f7d8 100644 (file)
@@ -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"
index 96ab664a0f1c695e4eff782b570febe1535279ac..ca6ca71010c61182409b0fd7fcb5b657ebb642e5 100644 (file)
@@ -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
index ba52669af9fcbea921c50c8019b3df717b631a45..40c4069c47a8f13e10254ee72972bcb5a80d2b5a 100644 (file)
@@ -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)) {
index f63d30869f46e1648a6f30e2f16c41011e3e33d1..77326317395552255f2aa0fb3a71594d7f3e3b1d 100644 (file)
@@ -1,3 +1,23 @@
+2002-08-22  Jean-Marc Lasgouttes  <lasgouttes@freesurf.fr>
+
+       * lyxfunc.C (getStatus): handle LFUN_INSET_OPTARG
+
+2002-08-20  Martin Vermeer  <martin.vermeer@hut.fi>
+
+       * 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  <larsbj@gullik.net>
 
        * paragraph.h: remove the declaration of undefined counters class
index f20f8b5227493d507be6c6e99ce9195fbb88fe6a..1f4b832e6fb70775184df99134f4730306a5f598 100644 (file)
@@ -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 29fff0e6124a3a5e870e97373afd64750f1e613a..44ac43836b6184d991c482282b9c53662ed14112 100644 (file)
@@ -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") {
index 6469b95ee09082cfa47273e313c58d2a3a686fd4..dcd1e1e019da7d4493a1cfdfd855893d5e654546 100644 (file)
@@ -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
index 4063687fbd3998c025999ac0548c1151c0a66a42..e755ca7b058a3fc7f6e09e0f8a6dc909f4c96c57 100644 (file)
@@ -63,6 +63,8 @@ libinsets_la_SOURCES = \
        insetminipage.h \
        insetnote.C \
        insetnote.h \
+       insetoptarg.C \
+       insetoptarg.h \
        insetparent.C \
        insetparent.h \
        insetquotes.C \
index e7fbd1a84864e5875f516a7429a68ecb009b44f1..4f7467838bf5473267431e275c383269d02eaac0 100644 (file)
@@ -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 (file)
index 0000000..2550290
--- /dev/null
@@ -0,0 +1,84 @@
+/* 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;
+}
+
diff --git a/src/insets/insetoptarg.h b/src/insets/insetoptarg.h
new file mode 100644 (file)
index 0000000..7f30ce2
--- /dev/null
@@ -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
index 9f0327bc49025c28e6f47e396a84c0c8ab71661b..c8e7c64cb059f7534402be3fe1cfe4cc73d8f352 100644 (file)
@@ -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);
index 969e0ba53899c96bd36669ccbbb53cf559869886..ca31bee99ced9f6a1830ab3d3905b1cd56f67ccc 100644 (file)
@@ -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;
index 2566ece2ede3d49a0c1d05e7bdd27e288f96cf37..40b38ec7c1d5c58c3ab4d49df2cecb6b963e09c4 100644 (file)
@@ -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 01f2f542fd85e966e03d423d9f9e22577683fb4a..2f668a362db883d98499d7f4ad53b58b735f2b6a 100644 (file)
@@ -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<InsetOptArg *>(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) {