]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
The logic of the endParagraph() routine is wrong. We should first
[lyx.git] / src / BufferParams.cpp
index e2959ed0926ed83d253a2bcbec1c9e9cdf2aa1b6..5f848a6256ff9f76132d5c7bc4fb666ed4d7727e 100644 (file)
@@ -259,22 +259,20 @@ PackageTranslator const & packagetranslator()
 
 
 // Cite engine
-typedef Translator<string, CiteEngine> CiteEngineTranslator;
+typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
 
 
-CiteEngineTranslator const init_citeenginetranslator()
+CiteEngineTypeTranslator const init_citeenginetypetranslator()
 {
-       CiteEngineTranslator translator("basic", ENGINE_BASIC);
-       translator.addPair("natbib_numerical", ENGINE_NATBIB_NUMERICAL);
-       translator.addPair("natbib_authoryear", ENGINE_NATBIB_AUTHORYEAR);
-       translator.addPair("jurabib", ENGINE_JURABIB);
+       CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
+       translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
        return translator;
 }
 
 
-CiteEngineTranslator const & citeenginetranslator()
+CiteEngineTypeTranslator const & citeenginetypetranslator()
 {
-       static CiteEngineTranslator translator = init_citeenginetranslator();
+       static CiteEngineTypeTranslator translator = init_citeenginetypetranslator();
        return translator;
 }
 
@@ -361,7 +359,8 @@ BufferParams::BufferParams()
        papersize = PAPER_DEFAULT;
        orientation = ORIENTATION_PORTRAIT;
        use_geometry = false;
-       cite_engine_ = ENGINE_BASIC;
+       cite_engine_.push_back("basic");
+       cite_engine_type_ = ENGINE_TYPE_NUMERICAL;
        biblio_style = "plain";
        use_bibtopic = false;
        use_indices = false;
@@ -708,9 +707,13 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                lex >> use;
                use_package(package, packagetranslator().find(use));
        } else if (token == "\\cite_engine") {
-               string engine;
-               lex >> engine;
-               cite_engine_ = citeenginetranslator().find(engine);
+               lex.eatLine();
+               vector<string> engine = getVectorFromString(lex.getString());
+               setCiteEngine(engine);
+       } else if (token == "\\cite_engine_type") {
+               string engine_type;
+               lex >> engine_type;
+               cite_engine_type_ = citeenginetypetranslator().find(engine_type);
        } else if (token == "\\biblio_style") {
                lex.eatLine();
                biblio_style = lex.getString();
@@ -1015,7 +1018,22 @@ void BufferParams::writeFile(ostream & os) const
        for (size_t i = 0; i < packages.size(); ++i)
                os << "\n\\use_package " << packages[i] << ' '
                   << use_package(packages[i]);
-       os << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
+
+       os << "\n\\cite_engine ";
+
+       if (!cite_engine_.empty()) {
+               LayoutModuleList::const_iterator be = cite_engine_.begin();
+               LayoutModuleList::const_iterator en = cite_engine_.end();
+               for (LayoutModuleList::const_iterator it = be; it != en; ++it) {
+                       if (it != be)
+                               os << ',';
+                       os << *it;
+               }
+       } else {
+               os << "basic";
+       }
+
+       os << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
           << "\n\\biblio_style " << biblio_style
           << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
           << "\n\\use_indices " << convert<string>(use_indices)
@@ -2001,7 +2019,19 @@ void BufferParams::makeDocumentClass()
        if (!baseClass())
                return;
 
-       doc_class_ = &(DocumentClassBundle::get().makeDocumentClass(*baseClass(), layout_modules_));
+       LayoutModuleList mods;
+       LayoutModuleList::iterator it;
+       LayoutModuleList::iterator en;
+
+       it = layout_modules_.begin();
+       en = layout_modules_.end();
+       for (; it != en; it++)
+               mods.push_back(*it);
+       it = cite_engine_.begin();
+       en = cite_engine_.end();
+       for (; it != en; it++)
+               mods.push_back(*it);
+       doc_class_ = &(DocumentClassBundle::get().makeDocumentClass(*baseClass(), mods));
 
        if (!local_layout.empty()) {
                TextClass::ReturnValues success =
@@ -2016,7 +2046,8 @@ void BufferParams::makeDocumentClass()
 
 bool BufferParams::moduleCanBeAdded(string const & modName) const
 {
-       return layout_modules_.moduleCanBeAdded(modName, baseClass());
+       return cite_engine_.moduleCanBeAdded(modName, baseClass()) &&
+               layout_modules_.moduleCanBeAdded(modName, baseClass());
 }
 
 
@@ -2102,17 +2133,24 @@ bool BufferParams::isExportableFormat(string const & format) const
 vector<string> BufferParams::backends() const
 {
        vector<string> v;
-       v.push_back(bufferFormat());
+       string const buffmt = bufferFormat();
+
        // FIXME: Don't hardcode format names here, but use a flag
-       if (v.back() == "latex") {
-               v.push_back("pdflatex");
+       if (buffmt == "latex") {
+               if (!useNonTeXFonts) {
+                       v.push_back("pdflatex");
+                       v.push_back("latex");
+               }
                v.push_back("luatex");
                v.push_back("dviluatex");
                v.push_back("xetex");
-       } else if (v.back() == "xetex") {
+       } else if (buffmt == "xetex") {
+               v.push_back("xetex");
                v.push_back("luatex");
                v.push_back("dviluatex");
-       }
+       } else
+               v.push_back(buffmt);
+
        v.push_back("xhtml");
        v.push_back("text");
        v.push_back("lyx");
@@ -2134,6 +2172,8 @@ OutputParams::FLAVOR BufferParams::getOutputFlavor(string const format) const
 
        if (dformat == "xhtml")
                result = OutputParams::HTML;
+       else if (dformat == "text")
+               result = OutputParams::TEXT;
        else {
                // Try to determine flavor of default output format
                vector<string> backs = backends();
@@ -2526,6 +2566,14 @@ string const BufferParams::dvips_options() const
 {
        string result;
 
+       // If the class loads the geometry package, we do not know which
+       // paper size is used, since we do not set it (bug 7013).
+       // Therefore we must not specify any argument here.
+       // dvips gets the correct paper size via DVI specials in this case
+       // (if the class uses the geometry package correctly).
+       if (documentClass().provides("geometry"))
+               return result;
+
        if (use_geometry
            && papersize == PAPER_CUSTOM
            && !lyxrc.print_paper_dimension_flag.empty()
@@ -2910,20 +2958,75 @@ Encoding const & BufferParams::encoding() const
 }
 
 
-CiteEngine BufferParams::citeEngine() const
+bool BufferParams::addCiteEngine(string const & engine)
+{
+       LayoutModuleList::const_iterator it = cite_engine_.begin();
+       LayoutModuleList::const_iterator en = cite_engine_.end();
+       for (; it != en; ++it)
+               if (*it == engine)
+                       return false;
+       cite_engine_.push_back(engine);
+       return true;
+}
+
+
+bool BufferParams::addCiteEngine(vector<string> const & engine)
+{
+       vector<string>::const_iterator it = engine.begin();
+       vector<string>::const_iterator en = engine.end();
+       bool ret = true;
+       for (; it != en; ++it)
+               if (!addCiteEngine(*it))
+                       ret = false;
+       return ret;
+}
+
+
+string const & BufferParams::defaultBiblioStyle() const
+{
+       return documentClass().defaultBiblioStyle();
+}
+
+
+bool const & BufferParams::fullAuthorList() const
+{
+       return documentClass().fullAuthorList();
+}
+
+
+void BufferParams::setCiteEngine(string const & engine)
+{
+       clearCiteEngine();
+       addCiteEngine(engine);
+}
+
+
+void BufferParams::setCiteEngine(vector<string> const & engine)
+{
+       clearCiteEngine();
+       addCiteEngine(engine);
+}
+
+
+vector<string> BufferParams::citeCommands() const
 {
-       // FIXME the class should provide the numerical/
-       // authoryear choice
-       if (documentClass().provides("natbib")
-           && cite_engine_ != ENGINE_NATBIB_NUMERICAL)
-               return ENGINE_NATBIB_AUTHORYEAR;
-       return cite_engine_;
+       static CitationStyle const default_style;
+       vector<string> commands =
+               documentClass().citeCommands(citeEngineType());
+       if (commands.empty())
+               commands.push_back(default_style.cmd);
+       return commands;
 }
 
 
-void BufferParams::setCiteEngine(CiteEngine cite_engine)
+vector<CitationStyle> BufferParams::citeStyles() const
 {
-       cite_engine_ = cite_engine;
+       static CitationStyle const default_style;
+       vector<CitationStyle> styles =
+               documentClass().citeStyles(citeEngineType());
+       if (styles.empty())
+               styles.push_back(default_style);
+       return styles;
 }
 
 } // namespace lyx