]> 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 be159dc2a31e652896f7ae1c7c017c8f5eb533ad..924b7e2698aed4cf8774ea87d7c411873df6cc30 100644 (file)
@@ -283,7 +283,7 @@ 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;
@@ -402,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);
@@ -601,7 +610,7 @@ void BufferParams::writeFile(ostream & os) const
        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";
        }
@@ -796,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
@@ -915,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) {
@@ -1005,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:
@@ -1020,7 +1032,7 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                                bullets_def += 'v';
                                break;
                        }
-                       bullets_def += "}{" +
+                       bullets_def += '{' +
                                user_defined_bullet(i).getText()
                                + "}\n";
                }
@@ -1068,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();
+       }
 }
 
 
@@ -1092,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")