]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Properly mark a buffer as internal
[lyx.git] / src / Buffer.cpp
index 010843e9ec1ae55112c95a30d907f6a6f7450d61..1dc5d592e506f46f66ae3b360ffd4d37c48ad3cc 100644 (file)
@@ -195,6 +195,9 @@ public:
        /// is this an unnamed file (New...)?
        bool unnamed;
 
+       /// is this an internal bufffer?
+       bool internal_buffer;
+
        /// buffer is r/o
        bool read_only;
 
@@ -355,11 +358,12 @@ static FileName createBufferTmpDir()
 Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
        Buffer const * cloned_buffer)
        : owner_(owner), lyx_clean(true), bak_clean(true), unnamed(false),
-         read_only(readonly_), filename(file), file_fully_loaded(false),
-         toc_backend(owner), macro_lock(false), timestamp_(0), checksum_(0),
-         wa_(0), gui_(0), undo_(*owner), bibinfo_cache_valid_(false),
-         bibfile_cache_valid_(false), cite_labels_valid_(false),
-         preview_loader_(0), cloned_buffer_(cloned_buffer), clone_list_(0),
+         internal_buffer(false), read_only(readonly_), filename(file),
+         file_fully_loaded(false), toc_backend(owner), macro_lock(false),
+         timestamp_(0), checksum_(0), wa_(0), gui_(0), undo_(*owner),
+         bibinfo_cache_valid_(false), bibfile_cache_valid_(false),
+         cite_labels_valid_(false), preview_loader_(0),
+         cloned_buffer_(cloned_buffer), clone_list_(0),
          doing_export(false), parent_buffer(0)
 {
        if (!cloned_buffer_) {
@@ -379,6 +383,7 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
        bibfile_status_ = cloned_buffer_->d->bibfile_status_;
        cite_labels_valid_ = cloned_buffer_->d->cite_labels_valid_;
        unnamed = cloned_buffer_->d->unnamed;
+       internal_buffer = cloned_buffer_->d->internal_buffer;
 }
 
 
@@ -789,6 +794,7 @@ int Buffer::readHeader(Lexer & lex)
        params().html_latex_end.clear();
        params().html_math_img_scale = 1.0;
        params().output_sync_macro.erase();
+       params().local_layout.clear();
 
        for (int i = 0; i < 4; ++i) {
                params().user_defined_bullet(i) = ITEMIZE_DEFAULTS[i];
@@ -1508,9 +1514,8 @@ void Buffer::writeLaTeXSource(otexstream & os,
                        Encoding const * const enc = runparams.encoding;
                        if (enc) {
                                for (size_t n = 0; n < inputpath.size(); ++n) {
-                                       docstring const glyph =
-                                               docstring(1, inputpath[n]);
-                                       if (enc->latexChar(inputpath[n], true) != glyph) {
+                                       if (!enc->encodable(inputpath[n])) {
+                                               docstring const glyph(1, inputpath[n]);
                                                LYXERR0("Uncodable character '"
                                                        << glyph
                                                        << "' in input path!");
@@ -1769,7 +1774,7 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
        bool const output_preamble =
                output == FullSource || output == OnlyPreamble;
        bool const output_body =
-         output == FullSource || output == OnlyBody;
+         output == FullSource || output == OnlyBody || output == IncludedFile;
 
        if (output_preamble) {
                os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@@ -1852,11 +1857,14 @@ void Buffer::writeLyXHTMLSource(odocstream & os,
        }
 
        if (output_body) {
-               os << "<body>\n";
+               bool const output_body_tag = (output != IncludedFile);
+               if (output_body_tag)
+                       os << "<body>\n";
                XHTMLStream xs(os);
                params().documentClass().counters().reset();
                xhtmlParagraphs(text(), *this, xs, runparams);
-               os << "</body>\n";
+               if (output_body_tag)
+                       os << "</body>\n";
        }
 
        if (output_preamble)
@@ -2665,7 +2673,13 @@ bool Buffer::isUnnamed() const
 /// retrieving fileName() nor for checking if it is unnamed or not.
 bool Buffer::isInternal() const
 {
-       return fileName().extension() == "internal";
+       return d->internal_buffer;
+}
+
+
+void Buffer::setInternal(bool flag)
+{
+       d->internal_buffer = flag;
 }
 
 
@@ -3303,9 +3317,7 @@ void Buffer::getSourceCode(odocstream & os, string const format,
                texrow.newline();
                texrow.newline();
                // output paragraphs
-               if (params().isDocBook())
-                       docbookParagraphs(text(), *this, os, runparams);
-               else if (runparams.flavor == OutputParams::HTML) {
+               if (runparams.flavor == OutputParams::HTML) {
                        XHTMLStream xs(os);
                        setMathFlavor(runparams);
                        xhtmlParagraphs(text(), *this, xs, runparams);
@@ -3315,6 +3327,8 @@ void Buffer::getSourceCode(odocstream & os, string const format,
                        // Probably should have some routine with a signature like them.
                        writePlaintextParagraph(*this,
                                text().paragraphs()[par_begin], os, runparams, dummy);
+               } else if (params().isDocBook()) {
+                       docbookParagraphs(text(), *this, os, runparams);
                } else {
                        // latex or literate
                        otexstream ots(os, texrow);
@@ -3332,11 +3346,16 @@ void Buffer::getSourceCode(odocstream & os, string const format,
                d->texrow.reset();
                d->texrow.newline();
                d->texrow.newline();
-               if (params().isDocBook())
-                       writeDocBookSource(os, absFileName(), runparams, output);
-               else if (runparams.flavor == OutputParams::HTML)
+               if (runparams.flavor == OutputParams::HTML) {
                        writeLyXHTMLSource(os, runparams, output);
-               else {
+               } else if (runparams.flavor == OutputParams::TEXT) {
+                       if (output == OnlyPreamble) {
+                               os << _("% Plaintext does not have a preamble.");
+                       } else
+                               writePlaintextFile(*this, os, runparams);
+               } else if (params().isDocBook()) {
+                               writeDocBookSource(os, absFileName(), runparams, output);
+               } else {
                        // latex or literate
                        otexstream ots(os, d->texrow);
                        writeLaTeXSource(ots, string(), runparams, output);
@@ -3695,7 +3714,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                        }
                        return ExportNoPathToFormat;
                }
-               runparams.flavor = converters.getFlavor(path);
+               runparams.flavor = converters.getFlavor(path, this);
 
        } else {
                backend_format = format;
@@ -3749,7 +3768,8 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                return ExportTexPathHasSpaces;
        } else {
                runparams.nice = false;
-               bool const success = makeLaTeXFile(FileName(filename), string(), runparams);
+               bool const success = makeLaTeXFile(
+                       FileName(filename), filePath(), runparams);
                if (d->cloned_buffer_)
                        d->cloned_buffer_->d->errorLists["Export"] = d->errorLists["Export"];
                if (!success)