]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Properly mark a buffer as internal
[lyx.git] / src / Buffer.cpp
index 76ec7d81ab217aad1d23365916a69b608a0e3990..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;
 }
 
 
@@ -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);