]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
PDF-form.lyx: add a note
[lyx.git] / src / Buffer.cpp
index e045e01aa5e87397f88b3b3700fddfad3113da92..7022139daf1b960f1e0ff924ed6fe52efdf3a283 100644 (file)
@@ -285,6 +285,10 @@ public:
        /// we ran updateBuffer(), i.e., whether citation labels may need
        /// to be updated.
        mutable bool cite_labels_valid_;
+       /// these hold the file name and format, written to by Buffer::preview
+       /// and read from by LFUN_BUFFER_VIEW_CACHE.
+       FileName preview_file_;
+       string preview_format_;
 
        mutable RefCache ref_cache_;
 
@@ -420,6 +424,8 @@ Buffer::Impl::Impl(Buffer * owner, FileName const & file, bool readonly_,
        cite_labels_valid_ = cloned_buffer_->d->cite_labels_valid_;
        unnamed = cloned_buffer_->d->unnamed;
        internal_buffer = cloned_buffer_->d->internal_buffer;
+       preview_file_ = cloned_buffer_->d->preview_file_;
+       preview_format_ = cloned_buffer_->d->preview_format_;
 }
 
 
@@ -438,7 +444,6 @@ Buffer::Buffer(string const & file, bool readonly, Buffer const * cloned_buffer)
                        it.paragraph().setId(cloned_it.paragraph().id());
        } else
                d->inset = new InsetText(this);
-       d->inset->setAutoBreakRows(true);
        d->inset->getText(0)->setMacrocontextPosition(par_iterator_begin());
 }
 
@@ -2421,6 +2426,10 @@ bool Buffer::getStatus(FuncRequest const & cmd, FuncStatus & flag)
                enable = !isReadonly();
                break;
 
+       case LFUN_BUFFER_VIEW_CACHE:
+               enable = (d->preview_file_).exists();
+               break;
+
        default:
                return false;
        }
@@ -2760,6 +2769,12 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                break;
        }
 
+       case LFUN_BUFFER_VIEW_CACHE:
+               if (!formats.view(*this, d->preview_file_,
+                                 d->preview_format_))
+                       dr.setMessage(_("Error viewing the output file."));
+               break;
+
        default:
                dispatched = false;
                break;
@@ -4213,9 +4228,26 @@ Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) con
        // (2) export with included children only
        ExportStatus const status = doExport(format, true, false, result_file);
        FileName const previewFile(result_file);
-       if (previewFile.exists() && !formats.view(*this, previewFile, format))
-               return PreviewError;
-       return (status == ExportSuccess) ? PreviewSuccess : status;
+
+       LATTEST (isClone());
+       d->cloned_buffer_->d->preview_file_ = previewFile;
+       d->cloned_buffer_->d->preview_format_ = format;
+
+       if (status != ExportSuccess)
+               return status;
+       if (previewFile.exists()) {
+               if (!formats.view(*this, previewFile, format))
+                       return PreviewError;
+               else
+                       return PreviewSuccess;
+       }
+       else {
+               // Successful export but no output file?
+               // Probably a bug in error detection.
+               LATTEST (status != ExportSuccess);
+
+               return status;
+       }
 }