]> git.lyx.org Git - features.git/commitdiff
Introduce a RefPrefix tag for Style, InsetLayout, and Float, that
authorRichard Heck <rgheck@comcast.net>
Wed, 17 Mar 2010 12:23:24 +0000 (12:23 +0000)
committerRichard Heck <rgheck@comcast.net>
Wed, 17 Mar 2010 12:23:24 +0000 (12:23 +0000)
indicates what prefix to use when constructing formatted references.
Documentation to follow.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33784 a592a061-630c-0410-9148-cb99ea01b6c8

12 files changed:
lib/layouts/stdfloats.inc
lib/layouts/stdinsets.inc
lib/layouts/stdsections.inc
lib/scripts/layout2layout.py
src/Floating.cpp
src/Floating.h
src/Layout.cpp
src/Layout.h
src/Text.cpp
src/TextClass.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h

index 37c28fa095ce4f04c29f99eb4c7345b31cbb8456..30055c962f6a9d68a2054fa4c2f0cfebdae56d91 100644 (file)
@@ -16,6 +16,7 @@ Float
        ListName              "List of Tables"
        NeedsFloatPkg         false
        ListCommand           listoftables
+       RefPrefix             tab
 End
 
 
@@ -29,6 +30,7 @@ Float
        ListName              "List of Figures"
        NeedsFloatPkg         false
        ListCommand           listoffigures
+       RefPrefix             fig
 End
 
 
@@ -41,4 +43,5 @@ Float
        Style                 ruled
        ListName              "List of Algorithms"
        NeedsFloatPkg         true
+       RefPrefix             alg
 End
index 85b437975f6c00029e26590df63b566df41c7674..f5bc8909460c9e42ba2aeabdcd12caaffc3552ae 100644 (file)
@@ -97,6 +97,7 @@ InsetLayout Foot
          Size                Small
        EndFont
        MultiPar              true
+       RefPrefix             fn
        HTMLLabel             \arabic{footnote}
        HTMLInnerTag          div
        HTMLStyle
@@ -223,6 +224,7 @@ InsetLayout Listings
        KeepEmpty             true
        FreeSpacing           true
        ForceLTR              true
+       RefPrefix             lst
 End
 
 InsetLayout Branch
@@ -292,6 +294,7 @@ InsetLayout Wrap
          Size                Small
        EndFont
        MultiPar              true
+       RefPrefix             wrap
        HTMLStyle
                div.wrap { 
                        float: right;
index fa144c0e868a8d8b713caaa358a902156e4d6851..1a75379e7fc8d7730f173dd9a0bf79afa620bbfa 100644 (file)
@@ -26,6 +26,7 @@ Style Part
        BottomSep             4
        ParSep                0.8
        Align                 Center
+       RefPrefix             part
        Alignpossible         Center
        Font
          Series              Bold
@@ -53,6 +54,7 @@ Style Chapter
        ParSep                0.8
        Align                 Block
        OptionalArgs          1
+       RefPrefix             cha
        Font
          Series              Bold
          Size                Huge
@@ -78,6 +80,7 @@ Style Section
        ParSep                0.7
        Align                 Block
        OptionalArgs          1
+       RefPrefix             sec
        Font
          Series              Bold
          Size                Larger
@@ -98,6 +101,7 @@ Style Subsection
          Series              Bold
          Size                Large
        EndFont
+       RefPrefix             sub
        HTMLTag               h3
 End
 
@@ -113,6 +117,7 @@ Style Subsubsection
          Series              Bold
          Size                Normal
        EndFont
+       RefPrefix             sub
        HTMLTag               h4
 End
 
@@ -124,6 +129,7 @@ Style Paragraph
        LatexName             paragraph
        TopSep                0.4
        BottomSep             0
+       RefPrefix             par
 End
 
 
@@ -134,6 +140,7 @@ Style Subparagraph
        LatexName             subparagraph
        NextNoIndent          0
        LeftMargin            MM
+       RefPrefix             subp
 End
 
 Input numarticle.inc
index 71f0c9fc543ae4442e454fcb285afea3745c3513..e93966a81478736e790d85f68628576774680101 100644 (file)
@@ -88,6 +88,9 @@ import os, re, string, sys
 # Changed LaTeXBuiltin tag to NeedsFloatPkg and
 # added new tag ListCommand.
 
+# Incremented to format 25, 12 March 2010 by rgh
+# Added RefPrefix tag for layouts and floats.
+
 # Do not forget to document format change in Customization
 # Manual (section "Declaring a new text class").
 
@@ -95,7 +98,7 @@ import os, re, string, sys
 # development/tools/updatelayouts.sh script to update all
 # layout files to the new format.
 
-currentFormat = 24
+currentFormat = 25
 
 
 def usage(prog_name):
@@ -266,6 +269,11 @@ def convert(lines):
             while i < len(lines) and not re_EndBabelPreamble.match(lines[i]):
                 i += 1
             continue
+        
+        # Only new features
+        if format == 24:
+            i += 1
+            continue
 
         if format == 23:
           match = re_Float.match(lines[i])
index 8cfdf8d746e94c960a49cdfcddea116b981beadc..cf48630f69bac3ee80794f60bcbe0c58a4068231 100644 (file)
@@ -31,12 +31,13 @@ Floating::Floating(string const & type, string const & placement,
                   string const & ext, string const & within,
                   string const & style, string const & name,
                   string const & listName, std::string const & listCmd, 
+                        string const & refPrefix,
                         string const & htmlTag, string const & htmlAttrib, 
                         string const & htmlStyle, bool needsfloat)
        : floattype_(type), placement_(placement), ext_(ext), within_(within),
          style_(style), name_(name), listname_(listName), listcommand_(listCmd),
-         needsfloatpkg_(needsfloat), html_tag_(htmlTag), html_attrib_(htmlAttrib), 
-         html_style_(htmlStyle)
+         refprefix_(refPrefix), needsfloatpkg_(needsfloat), html_tag_(htmlTag), 
+               html_attrib_(htmlAttrib), html_style_(htmlStyle)
 {}
 
 
index 358bedf0bd76674db9c929f762853a9d7d063f4f..d50fa90870e8b86d5a3eb895f243e2f3e53df84e 100644 (file)
@@ -32,6 +32,7 @@ public:
                 std::string const & ext, std::string const & within,
                 std::string const & style, std::string const & name,
                 std::string const & listName, std::string const & listCmd,
+                std::string const & refPrefix,
                 std::string const & htmlType, std::string const & htmlClass, 
                 std::string const & htmlStyle, bool builtin = false);
        ///
@@ -52,6 +53,8 @@ public:
        /// if needsFloatPkg() is false. note that this should not contain
        /// the leading "\".
        std::string const & listCommand() const { return listcommand_; }
+       /// prefix to use for formatted references to such floats
+       std::string const & refPrefix() const { return refprefix_; }
        ///
        bool needsFloatPkg() const { return needsfloatpkg_; }
        /// style information, for preamble
@@ -80,6 +83,8 @@ private:
        ///
        std::string listcommand_;
        ///
+       std::string refprefix_;
+       ///
        bool needsfloatpkg_;
        /// 
        mutable std::string html_tag_;
index c9abc0e04eff8cae7d204c828adf5e1fa36ba1f2..7a26c8cf65a6a640dc66204fe187d4ee801f4a3a 100644 (file)
@@ -105,6 +105,7 @@ enum LayoutTags {
        LT_INPREAMBLE,
        LT_HTMLTITLE,
        LT_SPELLCHECK,
+       LT_REFPREFIX,
        LT_INTITLE // keep this last!
 };
 
@@ -212,6 +213,7 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                { "parskip",        LT_PARSKIP },
                { "passthru",       LT_PASS_THRU },
                { "preamble",       LT_PREAMBLE },
+               { "refprefix",      LT_REFPREFIX },
                { "requires",       LT_REQUIRES },
                { "rightmargin",    LT_RIGHTMARGIN },
                { "spacing",        LT_SPACING },
@@ -497,6 +499,10 @@ bool Layout::read(Lexer & lex, TextClass const & tclass)
                        requires_.insert(req.begin(), req.end());
                        break;
                }
+                       
+               case LT_REFPREFIX:
+                       lex >> refprefix;
+                       break;
 
                case LT_HTMLTAG:
                        lex >> htmltag_;
index 8cea104193f8b1e6529b9da24cf023f6bd536f21..73edd052fcd1698e6dd8ef90fe0e8f0ae209d616 100644 (file)
@@ -245,6 +245,8 @@ public:
        int optionalargs;
        /// Which counter to step
        docstring counter;
+       /// Prefix to use when creating labels
+       docstring refprefix;
        /// Depth of XML command
        int commanddepth;
 
index 20accf5562f9efb81d2b5322c568347a48eea4c2..80357393904089d726e42b5d8e93f63143d5d1d2 100644 (file)
@@ -1864,40 +1864,32 @@ docstring Text::getPossibleLabel(Cursor const & cur) const
                }
        }
        if (layout->latextype != LATEX_PARAGRAPH)
-               name = from_ascii(layout->latexname());
+               name = layout->refprefix;
 
        // for captions, we just take the caption type
        Inset * caption_inset = cur.innerInsetOfType(CAPTION_CODE);
-       if (caption_inset)
-               name = from_ascii(static_cast<InsetCaption *>(caption_inset)->type());
-
-       // If none of the above worked, we'll see if we're inside various
-       // types of insets and take our abbreviation from them.
-       if (name.empty()) {
-               InsetCode const codes[] = {
-                       FLOAT_CODE,
-                       WRAP_CODE,
-                       FOOT_CODE
-               };
-               for (unsigned int i = 0; i < (sizeof codes / sizeof codes[0]); ++i) {
-                       Inset * float_inset = cur.innerInsetOfType(codes[i]);
-                       if (float_inset) {
-                               name = float_inset->name();
-                               break;
-                       }
+       if (caption_inset) {
+               string const & ftype = static_cast<InsetCaption *>(caption_inset)->type();
+               FloatList const & fl = cur.buffer()->params().documentClass().floats();
+               if (fl.typeExist(ftype)) {
+                       Floating const & flt = fl.getType(ftype);
+                       name = from_utf8(flt.refPrefix());
                }
+               if (name.empty())
+                       name = from_utf8(ftype.substr(0,3));
        }
 
-       // Create a correct prefix for prettyref
-       if (name == "theorem")
-               name = from_ascii("thm");
-       else if (name == "Foot")
-               name = from_ascii("fn");
-       else if (name == "listing")
-               name = from_ascii("lst");
+       // If none of the above worked, see if the inset knows.
+       if (name.empty()) {
+               InsetLayout const & il = cur.inset().getLayout();
+               name = il.refprefix();
+       }
 
        if (!name.empty())
-               text = name.substr(0, 3) + ':' + text;
+               // FIXME
+               // we should allow customization of the separator or else change it
+               // once we have refstyle
+               text = name + ':' + text;
 
        return text;
 }
index ce66cf856072b4045b68c54238a73b1294382686..7adad256be7b3ad9aa856b58ae4279b270972c18 100644 (file)
@@ -66,7 +66,7 @@ private:
 };
 
 // Keep the changes documented in the Customization manual. 
-int const FORMAT = 24;
+int const FORMAT = 25;
 
 
 bool layout2layout(FileName const & filename, FileName const & tempfile)
@@ -861,6 +861,7 @@ void TextClass::readFloat(Lexer & lexrc)
                FT_HTMLATTR,
                FT_HTMLTAG,
                FT_LISTCOMMAND,
+               FT_REFPREFIX,
                FT_END
        };
 
@@ -876,6 +877,7 @@ void TextClass::readFloat(Lexer & lexrc)
                { "needsfloatpkg", FT_NEEDSFLOAT },
                { "numberwithin", FT_WITHIN },
                { "placement", FT_PLACEMENT },
+               { "refprefix", FT_REFPREFIX },
                { "style", FT_STYLE },
                { "type", FT_TYPE }
        };
@@ -886,10 +888,11 @@ void TextClass::readFloat(Lexer & lexrc)
        string htmlattr;
        string htmlstyle;
        string htmltag;
-       string listName;
-       string listCommand;
+       string listname;
+       string listcommand;
        string name;
        string placement;
+       string refprefix;
        string style;
        string type;
        string within;
@@ -915,9 +918,10 @@ void TextClass::readFloat(Lexer & lexrc)
                                within = fl.within();
                                style = fl.style();
                                name = fl.name();
-                               listName = fl.listName();
+                               listname = fl.listName();
                                needsfloat = fl.needsFloatPkg();
-                               listCommand = fl.listCommand();
+                               listcommand = fl.listCommand();
+                               refprefix = fl.refPrefix();
                        } 
                        break;
                case FT_NAME:
@@ -944,11 +948,15 @@ void TextClass::readFloat(Lexer & lexrc)
                        break;
                case FT_LISTCOMMAND:
                        lexrc.next();
-                       listCommand = lexrc.getString();
+                       listcommand = lexrc.getString();
+                       break;
+               case FT_REFPREFIX:
+                       lexrc.next();
+                       refprefix = lexrc.getString();
                        break;
                case FT_LISTNAME:
                        lexrc.next();
-                       listName = lexrc.getString();
+                       listname = lexrc.getString();
                        break;
                case FT_NEEDSFLOAT:
                        lexrc.next();
@@ -974,13 +982,13 @@ void TextClass::readFloat(Lexer & lexrc)
 
        // Here we have a full float if getout == true
        if (getout) {
-               if (!needsfloat && listCommand.empty())
+               if (!needsfloat && listcommand.empty())
                        LYXERR0("The layout does not provide a list command " <<
                                "for the builtin float `" << type << "'. LyX will " <<
                                "not be able to produce a float list.");
                Floating fl(type, placement, ext, within, style, name, 
-                               listName, listCommand, htmltag, htmlattr, htmlstyle
-                               needsfloat);
+                               listname, listcommand, refprefix
+                               htmltag, htmlattr, htmlstyle, needsfloat);
                floatlist_.newFloat(fl);
                // each float has its own counter
                counters_.newCounter(from_ascii(type), from_ascii(within),
index ba1bbfb3e507220f647579d5cc9916f88287f49c..3aba74eef0a0d844af6d5e795b6e1fd0bdf7c57e 100644 (file)
@@ -106,6 +106,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                IL_PREAMBLE,
                IL_REQUIRES,
                IL_SPELLCHECK,
+               IL_REFPREFIX,
                IL_END
        };
 
@@ -143,6 +144,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                { "needprotect", IL_NEEDPROTECT },
                { "passthru", IL_PASSTHRU },
                { "preamble", IL_PREAMBLE },
+               { "refprefix", IL_REFPREFIX },
                { "requires", IL_REQUIRES },
                { "spellcheck", IL_SPELLCHECK }
        };
@@ -290,6 +292,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                case IL_PREAMBLE:
                        preamble_ = from_utf8(lex.getLongString("EndPreamble"));
                        break;
+               case IL_REFPREFIX:
+                       lex >> refprefix_;
+                       break;
                case IL_HTMLTAG:
                        lex >> htmltag_;
                        break;
index 0fcbad20d0ac645eac01deff28820dcb3ef0a430..3fdc17f8cecfb5f5036a77789b821d8cd061db86 100644 (file)
@@ -84,6 +84,8 @@ public:
        docstring preamble() const { return preamble_; }
        ///
        docstring counter() const { return counter_; }
+       ///
+       docstring refprefix() const { return refprefix_; }
        /// The tag enclosing all the material in this inset. Default is "span".
        std::string const & htmltag() const;
        /// Additional attributes for inclusion with the start tag. Default (if
@@ -176,6 +178,8 @@ private:
        ///
        docstring preamble_;
        ///
+       docstring refprefix_;
+       ///
        mutable std::string htmltag_;
        ///
        mutable std::string htmlattr_;