]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
PDF-form.lyx: add a note
[lyx.git] / src / Buffer.cpp
index 54da9b24ea394bc0f7dbfa3f5b685bc4d00565a6..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_;
 
@@ -367,7 +371,7 @@ private:
 static FileName createBufferTmpDir()
 {
        // FIXME This would be the ideal application for a TempDir class (like
-       //       TempFile but for directories) 
+       //       TempFile but for directories)
        string counter;
        {
                static int count;
@@ -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;
@@ -3335,7 +3350,7 @@ void Buffer::Impl::updateMacros(DocIterator & it, DocIterator & scope)
                                continue;
 
                        // register macro
-                       // FIXME (Abdel), I don't understandt why we pass 'it' here
+                       // FIXME (Abdel), I don't understand why we pass 'it' here
                        // instead of 'macroTemplate' defined above... is this correct?
                        macros[macroTemplate.name()][it] =
                                Impl::ScopeMacro(scope, MacroData(const_cast<Buffer *>(owner_), it));
@@ -4119,12 +4134,10 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                d->cloned_buffer_->d->errorLists[error_type] = d->errorLists[error_type];
        }
 
-       if (!success)
-               return ExportConverterError;
 
        if (put_in_tempdir) {
                result_file = tmp_result_file.absFileName();
-               return ExportSuccess;
+               return success ? ExportSuccess : ExportConverterError;
        }
 
        if (dest_filename.empty())
@@ -4189,7 +4202,7 @@ Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir
                        formats.prettyName(format)));
        }
 
-       return ExportSuccess;
+       return success ? ExportSuccess : ExportConverterError;
 }
 
 
@@ -4214,11 +4227,27 @@ 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);
+
+       LATTEST (isClone());
+       d->cloned_buffer_->d->preview_file_ = previewFile;
+       d->cloned_buffer_->d->preview_format_ = format;
+
        if (status != ExportSuccess)
                return status;
-       if (!formats.view(*this, FileName(result_file), format))
-               return PreviewError;
-       return PreviewSuccess;
+       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;
+       }
 }
 
 
@@ -4453,9 +4482,9 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
                if (master != this) {
                        bufToUpdate.insert(this);
                        master->updateBuffer(UpdateMaster, utype);
-                       // If the master buffer has no gui associated with it, then the TocModel is 
-                       // not updated during the updateBuffer call and TocModel::toc_ is invalid 
-                       // (bug 5699). The same happens if the master buffer is open in a different 
+                       // If the master buffer has no gui associated with it, then the TocModel is
+                       // not updated during the updateBuffer call and TocModel::toc_ is invalid
+                       // (bug 5699). The same happens if the master buffer is open in a different
                        // window. This test catches both possibilities.
                        // See: http://marc.info/?l=lyx-devel&m=138590578911716&w=2
                        // There remains a problem here: If there is another child open in yet a third