]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Differentiate backups from autosave files (#12659)
[lyx.git] / src / Buffer.cpp
index 5295a4bfc577191af725361c350d23521f2f963e..4d7adc3534bc4e1b41f6268605458f49e17d7ddc 100644 (file)
@@ -1110,6 +1110,24 @@ bool Buffer::readDocument(Lexer & lex)
 }
 
 
+bool Buffer::isSyncTeXenabled() const
+{
+       bool enabled = params().output_sync;
+
+       if (!enabled)
+               for (auto const & c : theConverters()) {
+                       const string dest = c.to().substr(0,3);
+                       if (dest == "dvi" || dest == "pdf") {
+                               const string cmd = c.command();
+                               enabled |= cmd.find("-synctex=") != string::npos
+                                       && cmd.find("-synctex=0") == string::npos;
+                               if (enabled)
+                                       break;
+                       }
+               }
+       return enabled;
+}
+
 bool Buffer::importString(string const & format, docstring const & contents, ErrorList & errorList)
 {
        Format const * fmt = theFormats().getFormat(format);
@@ -1145,7 +1163,7 @@ bool Buffer::importFile(string const & format, FileName const & name, ErrorList
 
        FileName const lyx = tempFileName("Buffer_importFileXXXXXX.lyx");
        Converters::RetVal const retval =
-               theConverters().convert(nullptr, name, lyx, name, format, "lyx", errorList);
+               theConverters().convert(this, name, lyx, name, format, "lyx", errorList);
        if (retval == Converters::SUCCESS) {
                bool const success = readFile(lyx) == ReadSuccess;
                removeTempFile(lyx);
@@ -1812,7 +1830,7 @@ Buffer::ExportStatus Buffer::makeLaTeXFile(FileName const & fname,
                lyx_exit(1);
        }
 
-       d->texrow = move(os.texrow());
+       d->texrow = std::move(os.texrow());
 
        ofs.close();
        if (ofs.fail()) {
@@ -1948,7 +1966,7 @@ Buffer::ExportStatus Buffer::writeLaTeXSource(otexstream & os,
                                        docdir = subst(docdir, "~", "\\string~");
                                bool const nonascii = !isAscii(from_utf8(docdir));
                                // LaTeX 2019/10/01 handles non-ascii path without detokenize
-                               bool const utfpathlatex = features.isAvailable("LaTeX-2019/10/01");
+                               bool const utfpathlatex = features.isAvailableAtLeastFrom("LaTeX", 2019, 10);
                                bool const detokenize = !utfpathlatex && nonascii;
                                bool const quote = contains(docdir, ' ');
                                if (utfpathlatex && nonascii)
@@ -2154,16 +2172,22 @@ Buffer::ExportStatus Buffer::writeDocBookSource(odocstream & os,
                        mathmlNamespace = + " xmlns:" + mathmlPrefix + "=\"http://www.w3.org/1998/Math/MathML\"";
                }
 
+               // XML-compatible language code: in lib/languages, language codes are
+               // given as dictionary file names; HTML5 expects to follow BCP47. This
+               // function implements a simple heuristic that does the conversion.
+               std::string htmlCode = params().language->code();
+               std::replace(htmlCode.begin(), htmlCode.end(), '_', '-');
+
                // Directly output the root tag, based on the current type of document.
-               string languageCode = params().language->code();
-               string params = "xml:lang=\"" + languageCode + '"'
-                                               + " xmlns=\"http://docbook.org/ns/docbook\""
-                                               + " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
-                                               + mathmlNamespace
-                                               + " xmlns:xi=\"http://www.w3.org/2001/XInclude\""
-                                               + " version=\"5.2\"";
+               string attributes = "xml:lang=\"" + htmlCode + '"'
+                                                   + " xmlns=\"http://docbook.org/ns/docbook\""
+                                                   + " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
+                                                   + mathmlNamespace
+                                                   + " xmlns:xi=\"http://www.w3.org/2001/XInclude\""
+                                                   + " version=\"5.2\"";
+               // Version 5.2 is required for formalgroup.
 
-               os << "<" << from_ascii(tclass.docbookroot()) << " " << from_ascii(params) << ">\n";
+               os << "<" << from_ascii(tclass.docbookroot()) << " " << from_ascii(attributes) << ">\n";
        }
 
        if (output_body) {
@@ -2221,14 +2245,16 @@ Buffer::ExportStatus Buffer::writeLyXHTMLSource(odocstream & os,
          output == FullSource || output == OnlyBody || output == IncludedFile;
 
        if (output_preamble) {
-               os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-                  << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\" \"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd\">\n"
-                  // FIXME Language should be set properly.
-                  << "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+               // HTML5-compatible language code: in lib/languages, language codes are
+               // given as dictionary file names; HTML5 expects to follow BCP47. This
+               // function implements a simple heuristic that does the conversion.
+               std::string htmlCode = params().language->code();
+               std::replace(htmlCode.begin(), htmlCode.end(), '_', '-');
+
+               os << "<!DOCTYPE html>\n"
+                  << "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"" << from_ascii(htmlCode) << "\">\n"
                   << "<head>\n"
-                  << "<meta name=\"GENERATOR\" content=\"" << PACKAGE_STRING << "\" />\n"
-                  // FIXME Presumably need to set this right
-                  << "<meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\" />\n";
+                  << "<meta name=\"generator\" content=\"" << PACKAGE_STRING << "\" />\n";
 
                docstring const & doctitle = features.htmlTitle();
                os << "<title>"
@@ -2288,7 +2314,7 @@ Buffer::ExportStatus Buffer::writeLyXHTMLSource(odocstream & os,
                        // we are here if the CSS is supposed to be written to the header
                        // or if we failed to write it to an external file.
                        if (!written) {
-                               os << "<style type='text/css'>\n"
+                               os << "<style>\n"
                                         << dstyles
                                         << "\n</style>\n";
                        }
@@ -2686,7 +2712,7 @@ void Buffer::markDepClean(string const & name)
 }
 
 
-bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
+bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag) const
 {
        if (isInternal()) {
                // FIXME? if there is an Buffer LFUN that can be dispatched even
@@ -4235,6 +4261,13 @@ void Buffer::updateTitles() const
 }
 
 
+void Buffer::scheduleRedrawWorkAreas() const
+{
+       if (d->wa_)
+               d->wa_->scheduleRedraw();
+}
+
+
 void Buffer::resetAutosaveTimers() const
 {
        if (d->gui_)
@@ -4935,6 +4968,10 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
 {
        LBUFERR(!text().paragraphs().empty());
 
+       // This can be called when loading a file, so that there be no
+       // open undo group.
+       UndoGroupHelper ugh(const_cast<Buffer *>(this));
+
        // Use the master text class also for child documents
        Buffer const * const master = masterBuffer();
        DocumentClass const & textclass = master->params().documentClass();