Author: vfr
Date: Thu Oct 27 22:00:08 2011
New Revision: 40044
URL: http://www.lyx.org/trac/changeset/40044

Log:
Let Buffer::preview return an error value

TODO:
 - Also let the public function return an error value,
 - Move all user interaction (Alerts etc.) out of Buffer.

Modified:
   lyx-devel/trunk/src/Buffer.cpp
   lyx-devel/trunk/src/Buffer.h

Modified: lyx-devel/trunk/src/Buffer.cpp
==============================================================================
--- lyx-devel/trunk/src/Buffer.cpp      Thu Oct 27 22:00:06 2011        (r40043)
+++ lyx-devel/trunk/src/Buffer.cpp      Thu Oct 27 22:00:08 2011        (r40044)
@@ -3744,20 +3744,27 @@
        bool const update_unincluded =
                        params().maintain_unincluded_children
                        && !params().getIncludedChildren().empty();
-       return preview(format, update_unincluded);
+       ExportStatus const status = preview(format, update_unincluded);
+       return (status == PreviewSuccess);
 }
 
-bool Buffer::preview(string const & format, bool includeall) const
+Buffer::ExportStatus Buffer::preview(string const & format, bool includeall) 
const
 {
        MarkAsExporting exporting(this);
        string result_file;
        // (1) export with all included children (omit \includeonly)
-       if (includeall && (doExport(format, true, true) != ExportSuccess))
-               return false;
+       if (includeall) { 
+               ExportStatus const status = doExport(format, true, true);
+               if (status != ExportSuccess)
+                       return status;
+       }
        // (2) export with included children only
-       if (doExport(format, true, false, result_file) != ExportSuccess)
-               return false;
-       return formats.view(*this, FileName(result_file), format);
+       ExportStatus const status = doExport(format, true, false, result_file);
+       if (status != ExportSuccess)
+               return status;
+       if (!formats.view(*this, FileName(result_file), format))
+               return PreviewError;
+       return PreviewSuccess;
 }
 
 

Modified: lyx-devel/trunk/src/Buffer.h
==============================================================================
--- lyx-devel/trunk/src/Buffer.h        Thu Oct 27 22:00:06 2011        (r40043)
+++ lyx-devel/trunk/src/Buffer.h        Thu Oct 27 22:00:08 2011        (r40044)
@@ -123,11 +123,15 @@
        };
 
        enum ExportStatus {
+               // export
                ExportSuccess,
                ExportError,
                ExportNoPathToFormat,
                ExportTexPathHasSpaces,
-               ExportConverterError
+               ExportConverterError,
+               // preview
+               PreviewSuccess,
+               PreviewError
        };
 
        /// Method to check if a file is externally modified, used by
@@ -623,7 +627,7 @@
        ExportStatus doExport(std::string const & target, bool put_in_tempdir,
                bool includeall) const;
        ///
-       bool preview(std::string const & format, bool includeall = false) const;
+       ExportStatus preview(std::string const & format, bool includeall = 
false) const;
 
 public:
        /// mark the buffer as busy exporting something, or not

Reply via email to