]> git.lyx.org Git - lyx.git/blobdiff - src/TextClass.cpp
* src/LaTeXFeatures.cpp: simplify greektext definition. Patch by G. Milde (bug #6458)
[lyx.git] / src / TextClass.cpp
index 464cc284a56ff253bc12db87ca2f42c31f18ea07..6d13d7de0a26b0d92aae8e9d2ce9476f365521f2 100644 (file)
@@ -66,7 +66,7 @@ private:
 };
 
 // Keep the changes documented in the Customization manual. 
-int const FORMAT = 24;
+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:
@@ -197,7 +197,8 @@ enum TextClassTags {
        TC_DEFAULTMODULE,
        TC_PROVIDESMODULE,
        TC_EXCLUDESMODULE,
-       TC_HTMLTOCSECTION
+       TC_HTMLTOCSECTION,
+       TC_CITEFORMAT
 };
 
 
@@ -206,6 +207,7 @@ namespace {
        LexerKeyword textClassTags[] = {
                { "addtohtmlpreamble", TC_ADDTOHTMLPREAMBLE },
                { "addtopreamble",     TC_ADDTOPREAMBLE },
+               { "citeformat",        TC_CITEFORMAT },
                { "classoptions",      TC_CLASSOPTIONS },
                { "columns",           TC_COLUMNS },
                { "counter",           TC_COUNTER },
@@ -634,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;
@@ -831,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();
@@ -846,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 {
@@ -860,6 +891,8 @@ void TextClass::readFloat(Lexer & lexrc)
                FT_HTMLSTYLE,
                FT_HTMLATTR,
                FT_HTMLTAG,
+               FT_LISTCOMMAND,
+               FT_REFPREFIX,
                FT_END
        };
 
@@ -870,10 +903,12 @@ void TextClass::readFloat(Lexer & lexrc)
                { "htmlattr", FT_HTMLATTR },
                { "htmlstyle", FT_HTMLSTYLE },
                { "htmltag", FT_HTMLTAG },
+               { "listcommand", FT_LISTCOMMAND },
                { "listname", FT_LISTNAME },
                { "needsfloatpkg", FT_NEEDSFLOAT },
                { "numberwithin", FT_WITHIN },
                { "placement", FT_PLACEMENT },
+               { "refprefix", FT_REFPREFIX },
                { "style", FT_STYLE },
                { "type", FT_TYPE }
        };
@@ -884,9 +919,11 @@ 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;
@@ -912,8 +949,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();
+                               refprefix = fl.refPrefix();
                        } 
                        break;
                case FT_NAME:
@@ -938,9 +977,17 @@ 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_NEEDSFLOAT:
                        lexrc.next();
@@ -964,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, 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),
@@ -982,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;
@@ -1083,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_;
@@ -1298,6 +1360,27 @@ Layout const & DocumentClass::htmlTOCLayout() const
 }
 
 
+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