]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
Get rid of all-insets-toggle and explain how to replace it with inset-forall.
[lyx.git] / src / TextClass.cpp
index c73857f6e3214ecbf82f34d95bc168197ee9494d..6d13d7de0a26b0d92aae8e9d2ce9476f365521f2 100644 (file)
@@ -66,7 +66,7 @@ private:
 };
 
 // Keep the changes documented in the Customization manual. 
-int const FORMAT = 20;
+int const FORMAT = 26;
 
 
 bool layout2layout(FileName const & filename, FileName const & tempfile)
@@ -95,7 +95,7 @@ bool layout2layout(FileName const & filename, FileName const & tempfile)
 }
 
 
-std::string translateRT(TextClass::ReadType rt) 
+string translateRT(TextClass::ReadType rt) 
 {
        switch (rt) {
        case TextClass::BASECLASS:
@@ -196,7 +196,9 @@ enum TextClassTags {
        TC_ADDTOHTMLPREAMBLE,
        TC_DEFAULTMODULE,
        TC_PROVIDESMODULE,
-       TC_EXCLUDESMODULE
+       TC_EXCLUDESMODULE,
+       TC_HTMLTOCSECTION,
+       TC_CITEFORMAT
 };
 
 
@@ -205,6 +207,7 @@ namespace {
        LexerKeyword textClassTags[] = {
                { "addtohtmlpreamble", TC_ADDTOHTMLPREAMBLE },
                { "addtopreamble",     TC_ADDTOPREAMBLE },
+               { "citeformat",        TC_CITEFORMAT },
                { "classoptions",      TC_CLASSOPTIONS },
                { "columns",           TC_COLUMNS },
                { "counter",           TC_COUNTER },
@@ -215,6 +218,7 @@ namespace {
                { "float",             TC_FLOAT },
                { "format",            TC_FORMAT },
                { "htmlpreamble",      TC_HTMLPREAMBLE },
+               { "htmltocsection",    TC_HTMLTOCSECTION },
                { "ifcounter",         TC_IFCOUNTER },
                { "ifstyle",           TC_IFSTYLE },
                { "input",             TC_INPUT },
@@ -529,6 +533,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                case TC_HTMLPREAMBLE:
                        htmlpreamble_ = from_utf8(lexrc.getLongString("EndPreamble"));
                        break;
+               
+               case TC_HTMLTOCSECTION:
+                       html_toc_section_ = from_utf8(trim(lexrc.getString()));
+                       break;
 
                case TC_ADDTOPREAMBLE:
                        preamble_ += from_utf8(lexrc.getLongString("EndPreamble"));
@@ -628,6 +636,10 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                case TC_FLOAT:
                        readFloat(lexrc);
                        break;
+               
+               case TC_CITEFORMAT:
+                       readCiteFormat(lexrc);
+                       break;
 
                case TC_IFCOUNTER:
                        ifcounter = true;
@@ -825,7 +837,10 @@ void TextClass::readClassOptions(Lexer & lexrc)
                        break;
                case CO_OTHER:
                        lexrc.next();
-                       options_ = lexrc.getString();
+                       if (options_.empty())
+                               options_ = lexrc.getString();
+                       else
+                               options_ += ',' + lexrc.getString();
                        break;
                case CO_HEADER:
                        lexrc.next();
@@ -840,6 +855,28 @@ void TextClass::readClassOptions(Lexer & lexrc)
 }
 
 
+void TextClass::readCiteFormat(Lexer & lexrc)
+{
+       string etype;
+       string definition;
+       while (lexrc.isOK()) {
+               lexrc.next();
+               etype = lexrc.getString();
+               if (!lexrc.isOK() || compare_ascii_no_case(etype, "end") == 0)
+                       break;
+               lexrc.eatLine();
+               definition = lexrc.getString();
+               char initchar = etype[0];
+               if (initchar == '#')
+                       continue;
+               if (initchar == '!' || initchar == '_')
+                       cite_macros_[etype] = definition;
+               else
+                       cite_formats_[etype] = definition;
+       }
+}
+
+
 void TextClass::readFloat(Lexer & lexrc)
 {
        enum {
@@ -850,10 +887,12 @@ void TextClass::readFloat(Lexer & lexrc)
                FT_WITHIN,
                FT_STYLE,
                FT_LISTNAME,
-               FT_BUILTIN,
+               FT_NEEDSFLOAT,
                FT_HTMLSTYLE,
                FT_HTMLATTR,
                FT_HTMLTAG,
+               FT_LISTCOMMAND,
+               FT_REFPREFIX,
                FT_END
        };
 
@@ -864,10 +903,12 @@ void TextClass::readFloat(Lexer & lexrc)
                { "htmlattr", FT_HTMLATTR },
                { "htmlstyle", FT_HTMLSTYLE },
                { "htmltag", FT_HTMLTAG },
-               { "latexbuiltin", FT_BUILTIN },
+               { "listcommand", FT_LISTCOMMAND },
                { "listname", FT_LISTNAME },
+               { "needsfloatpkg", FT_NEEDSFLOAT },
                { "numberwithin", FT_WITHIN },
                { "placement", FT_PLACEMENT },
+               { "refprefix", FT_REFPREFIX },
                { "style", FT_STYLE },
                { "type", FT_TYPE }
        };
@@ -878,13 +919,15 @@ void TextClass::readFloat(Lexer & lexrc)
        string htmlattr;
        string htmlstyle;
        string htmltag;
-       string listName;
+       string listname;
+       string listcommand;
        string name;
        string placement;
+       string refprefix;
        string style;
        string type;
        string within;
-       bool builtin = false;
+       bool needsfloat = true;
 
        bool getout = false;
        while (!getout && lexrc.isOK()) {
@@ -906,8 +949,10 @@ void TextClass::readFloat(Lexer & lexrc)
                                within = fl.within();
                                style = fl.style();
                                name = fl.name();
-                               listName = fl.listName();
-                               builtin = fl.builtin();
+                               listname = fl.listName();
+                               needsfloat = fl.needsFloatPkg();
+                               listcommand = fl.listCommand();
+                               refprefix = fl.refPrefix();
                        } 
                        break;
                case FT_NAME:
@@ -932,13 +977,21 @@ void TextClass::readFloat(Lexer & lexrc)
                        lexrc.next();
                        style = lexrc.getString();
                        break;
+               case FT_LISTCOMMAND:
+                       lexrc.next();
+                       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_BUILTIN:
+               case FT_NEEDSFLOAT:
                        lexrc.next();
-                       builtin = lexrc.getBool();
+                       needsfloat = lexrc.getBool();
                        break;
                case FT_HTMLATTR:
                        lexrc.next();
@@ -958,10 +1011,15 @@ void TextClass::readFloat(Lexer & lexrc)
                }
        }
 
-       // Here if have a full float if getout == true
+       // Here we have a full float if getout == true
        if (getout) {
+               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, htmltag, htmlattr, htmlstyle, builtin);
+                               listname, listcommand, refprefix, 
+                               htmltag, htmlattr, htmlstyle, needsfloat);
                floatlist_.newFloat(fl);
                // each float has its own counter
                counters_.newCounter(from_ascii(type), from_ascii(within),
@@ -976,6 +1034,15 @@ void TextClass::readFloat(Lexer & lexrc)
 }
 
 
+string const & TextClass::prerequisites() const
+{ 
+       if (contains(prerequisites_, ',')) {
+               vector<string> const pres = getVectorFromString(prerequisites_);
+               prerequisites_ = getStringFromVector(pres, "\n\t");
+       }
+       return prerequisites_; 
+}
+
 bool TextClass::hasLayout(docstring const & n) const
 {
        docstring const name = n.empty() ? defaultLayoutName() : n;
@@ -1077,7 +1144,8 @@ bool TextClass::load(string const & path) const
                       << to_utf8(makeDisplayPath(layout_file.absFilename()))
                       << "'\n(Check `" << name_
                       << "')\nCheck your installation and "
-                       "try Options/Reconfigure..." << endl;
+                         "try Options/Reconfigure..." 
+                      << endl;
        }
 
        return loaded_;
@@ -1166,6 +1234,7 @@ Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
        return *defaultLayout;
 }
 
+
 /////////////////////////////////////////////////////////////////////////
 //
 // DocumentClassBundle
@@ -1265,6 +1334,53 @@ bool DocumentClass::hasTocLevels() const
 }
 
 
+Layout const & DocumentClass::htmlTOCLayout() const
+{
+       if (html_toc_section_.empty()) {
+               // we're going to look for the layout with the minimum toclevel
+               TextClass::LayoutList::const_iterator lit = begin();
+               TextClass::LayoutList::const_iterator const len = end();
+               int minlevel = 1000;
+               Layout const * lay = NULL;
+               for (; lit != len; ++lit) {
+                       int const level = lit->toclevel;
+                       // we don't want Part
+                       if (level == Layout::NOT_IN_TOC || level < 0 || level >= minlevel)
+                               continue;
+                       lay = &*lit;
+                       minlevel = level;
+               }
+               if (lay)
+                       html_toc_section_ = lay->name();
+               else
+                       // hmm. that is very odd, so we'll do our best
+                       html_toc_section_ = defaultLayoutName();
+       }
+       return operator[](html_toc_section_);
+}
+
+
+string const & DocumentClass::getCiteFormat(string const & entry_type) const
+{
+       static string default_format = N_("{%author%[[%author%, ]][[{%editor%[[%editor%, ed., ]]}]]}\"%title%\"{%journal%[[, {!<i>!}%journal%{!</i>!}]][[{%publisher%[[, %publisher%]][[{%institution%[[, %institution%]]}]]}]]}{%year%[[ (%year%)]]}{%pages%[[, %pages%]]}.");
+       
+       map<string, string>::const_iterator it = cite_formats_.find(entry_type);
+       if (it != cite_formats_.end())
+               return it->second;
+       return default_format;
+}
+
+
+string const & DocumentClass::getCiteMacro(string const & macro) const
+{
+       static string empty;
+       map<string, string>::const_iterator it = cite_macros_.find(macro);
+       if (it != cite_macros_.end())
+               return it->second;
+       return empty;
+}
+
+
 /////////////////////////////////////////////////////////////////////////
 //
 // PageSides