]> git.lyx.org Git - lyx.git/blobdiff - src/bufferparams.C
Fix bug 2485 and crash on middle mouse paste on math
[lyx.git] / src / bufferparams.C
index a5bd2f88e68ef2625310c8787db96c78f38173d1..924b7e2698aed4cf8774ea87d7c411873df6cc30 100644 (file)
@@ -105,25 +105,6 @@ QuotesLangTranslator const & quoteslangtranslator()
 }
 
 
-// Quote times
-typedef Translator<int, InsetQuotes::quote_times> QuotesTimesTranslator;
-
-
-QuotesTimesTranslator const init_quotestimestranslator()
-{
-       QuotesTimesTranslator translator(1, InsetQuotes::SingleQ);
-       translator.addPair(2, InsetQuotes::DoubleQ);
-       return translator;
-}
-
-
-QuotesTimesTranslator const & quotestimestranslator()
-{
-       static QuotesTimesTranslator translator = init_quotestimestranslator();
-       return translator;
-}
-
-
 // Paper size
 typedef Translator<std::string, PAPER_SIZE> PaperSizeTranslator;
 
@@ -152,27 +133,6 @@ PaperSizeTranslator const & papersizetranslator()
 }
 
 
-// Paper packages
-typedef Translator<string, PAPER_PACKAGES> PaperPackagesTranslator;
-
-
-PaperPackagesTranslator const init_paperpackagestranslator()
-{
-       PaperPackagesTranslator translator(string_paperpackages[0], PACKAGE_NONE);
-       translator.addPair(string_paperpackages[1], PACKAGE_A4);
-       translator.addPair(string_paperpackages[2], PACKAGE_A4WIDE);
-       translator.addPair(string_paperpackages[3], PACKAGE_WIDEMARGINSA4);
-       return translator;
-}
-
-
-PaperPackagesTranslator const & paperpackagestranslator()
-{
-       static PaperPackagesTranslator translator = init_paperpackagestranslator();
-       return translator;
-}
-
-
 // Paper orientation
 typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
 
@@ -323,17 +283,15 @@ BufferParams::BufferParams()
          // true in the returned pair, then `second' is the textclass
          // number; if it is false, second is 0. In both cases, second
          // is what we want.
-       textclass(textclasslist.NumberOfClass("article").second),
+       textclass(textclasslist.numberOfClass("article").second),
        pimpl_(new Impl)
 {
        paragraph_separation = PARSEP_INDENT;
        quotes_language = InsetQuotes::EnglishQ;
-       quotes_times = InsetQuotes::DoubleQ;
        fontsize = "default";
 
        /*  PaperLayout */
        papersize = PAPER_DEFAULT;
-       paperpackage = PACKAGE_NONE;
        orientation = ORIENTATION_PORTRAIT;
        use_geometry = false;
        use_amsmath = AMS_AUTO;
@@ -444,19 +402,28 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                lex.next();
                string const classname = lex.getString();
                pair<bool, lyx::textclass_type> pp =
-                       textclasslist.NumberOfClass(classname);
+                       textclasslist.numberOfClass(classname);
                if (pp.first) {
                        textclass = pp.second;
                } else {
-                       textclass = 0;
-                       return classname;
+                       // if text class does not exist, try to load it from filepath
+                       pp = textclasslist.addTextClass(classname, filepath);
+                       if (pp.first) {
+                               textclass = pp.second;
+                       } else {        
+                               textclass = 0;
+                               return classname;
+                       }       
                }
+               // FIXME: isTeXClassAvailable will try to load the layout file, but will
+               // fail because of the lack of path info. Warnings will be given although
+               // the layout file will be correctly loaded later.
                if (!getLyXTextClass().isTeXClassAvailable()) {
                        string const msg =
                                bformat(_("The document uses a missing "
                                "TeX class \"%1$s\".\n"), classname);
                        Alert::warning(_("Document class not available"),
-                                      msg + _("LyX will not be able to produce output."));
+                                      msg + _("LyX will not be able to produce output."));
                }
        } else if (token == "\\begin_preamble") {
                readPreamble(lex);
@@ -482,18 +449,10 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                string quotes_lang;
                lex >> quotes_lang;
                quotes_language = quoteslangtranslator().find(quotes_lang);
-       } else if (token == "\\quotes_times") {
-               int qtimes;
-               lex >> qtimes;
-               quotes_times = quotestimestranslator().find(qtimes);
        } else if (token == "\\papersize") {
                string ppsize;
                lex >> ppsize;
                papersize = papersizetranslator().find(ppsize);
-       } else if (token == "\\paperpackage") {
-               string ppackage;
-               lex >> ppackage;
-               paperpackage = paperpackagestranslator().find(ppackage);
        } else if (token == "\\use_geometry") {
                lex >> use_geometry;
        } else if (token == "\\use_amsmath") {
@@ -639,7 +598,6 @@ void BufferParams::writeFile(ostream & os) const
        spacing().writeFile(os);
 
        os << "\\papersize " << string_papersize[papersize]
-          << "\n\\paperpackage " << string_paperpackages[paperpackage]
           << "\n\\use_geometry " << convert<string>(use_geometry)
           << "\n\\use_amsmath " << use_amsmath
           << "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
@@ -647,12 +605,12 @@ void BufferParams::writeFile(ostream & os) const
           << "\n\\paperorientation " << string_orientation[orientation]
           << '\n';
 
-       std::list<Branch>::const_iterator it = branchlist().begin();
-       std::list<Branch>::const_iterator end = branchlist().end();
+       BranchList::const_iterator it = branchlist().begin();
+       BranchList::const_iterator end = branchlist().end();
        for (; it != end; ++it) {
                os << "\\branch " << it->getBranch()
                   << "\n\\selected " << it->getSelected()
-                  << "\n\\color " << it->getColor()
+                  << "\n\\color " << lyx::X11hexname(it->getColor())
                   << "\n\\end_branch"
                   << "\n";
        }
@@ -690,9 +648,7 @@ void BufferParams::writeFile(ostream & os) const
           << string_paragraph_separation[paragraph_separation]
           << "\n\\defskip " << getDefSkip().asLyXCommand()
           << "\n\\quotes_language "
-          << string_quotes_language[quotes_language] << '\n'
-          << "\\quotes_times "
-          << quotestimestranslator().find(quotes_times)
+          << string_quotes_language[quotes_language]
           << "\n\\papercolumns " << columns
           << "\n\\papersides " << sides
           << "\n\\paperpagestyle " << pagestyle << '\n';
@@ -746,7 +702,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                                     (papersize == PAPER_A3) ||
                                     (papersize == PAPER_CUSTOM);
 
-       if (!use_geometry && (paperpackage == PACKAGE_NONE)) {
+       if (!use_geometry) {
                switch (papersize) {
                case PAPER_A4:
                        clsoptions << "a4paper,";
@@ -849,7 +805,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
 
        if (inputenc == "auto") {
                string const doc_encoding =
-                       language->encoding()->LatexName();
+                       language->encoding()->latexName();
 
                // Create a list with all the input encodings used
                // in the document
@@ -867,26 +823,6 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                texrow.newline();
        }
 
-       // At the very beginning the text parameters.
-       if (paperpackage != PACKAGE_NONE) {
-               switch (paperpackage) {
-               case PACKAGE_NONE:
-                       break;
-               case PACKAGE_A4:
-                       os << "\\usepackage{a4}\n";
-                       texrow.newline();
-                       break;
-               case PACKAGE_A4WIDE:
-                       os << "\\usepackage{a4wide}\n";
-                       texrow.newline();
-                       break;
-               case PACKAGE_WIDEMARGINSA4:
-                       os << "\\usepackage[widemargins]{a4}\n";
-                       texrow.newline();
-                       break;
-               }
-       }
-
        if (use_geometry || nonstandard_papersize) {
                os << "\\usepackage{geometry}\n";
                texrow.newline();
@@ -988,17 +924,20 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                texrow.newline();
        }
 
-       if (secnumdepth != tclass.secnumdepth()) {
-               os << "\\setcounter{secnumdepth}{"
-                  << secnumdepth
-                  << "}\n";
-               texrow.newline();
-       }
-       if (tocdepth != tclass.tocdepth()) {
-               os << "\\setcounter{tocdepth}{"
-                  << tocdepth
-                  << "}\n";
-               texrow.newline();
+       // Only if class has a ToC hierarchy
+       if (tclass.hasTocLevels()) {
+               if (secnumdepth != tclass.secnumdepth()) {
+                       os << "\\setcounter{secnumdepth}{"
+                          << secnumdepth
+                          << "}\n";
+                       texrow.newline();
+               }
+               if (tocdepth != tclass.tocdepth()) {
+                       os << "\\setcounter{tocdepth}{"
+                          << tocdepth
+                          << "}\n";
+                       texrow.newline();
+               }
        }
 
        if (paragraph_separation) {
@@ -1078,7 +1017,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
                        if (bullets_def.empty())
                                bullets_def="\\AtBeginDocument{\n";
-                       bullets_def += "  \\renewcommand{\\labelitemi";
+                       bullets_def += "  \\def\\labelitemi";
                        switch (i) {
                                // `i' is one less than the item to modify
                        case 0:
@@ -1093,7 +1032,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                                bullets_def += 'v';
                                break;
                        }
-                       bullets_def += "}{" +
+                       bullets_def += '{' +
                                user_defined_bullet(i).getText()
                                + "}\n";
                }
@@ -1141,8 +1080,11 @@ void BufferParams::useClassDefaults()
        columns = tclass.columns();
        pagestyle = tclass.pagestyle();
        options = tclass.options();
-       secnumdepth = tclass.secnumdepth();
-       tocdepth = tclass.tocdepth();
+       // Only if class has a ToC hierarchy
+       if (tclass.hasTocLevels()) {
+               secnumdepth = tclass.secnumdepth();
+               tocdepth = tclass.tocdepth();
+       }
 }
 
 
@@ -1165,6 +1107,14 @@ LyXTextClass const & BufferParams::getLyXTextClass() const
 }
 
 
+LyXFont const BufferParams::getFont() const
+{
+       LyXFont f = getLyXTextClass().defaultfont();
+       f.setLanguage(language);
+       return f;
+}
+
+
 void BufferParams::readPreamble(LyXLex & lex)
 {
        if (lex.getString() != "\\begin_preamble")