]> git.lyx.org Git - lyx.git/blobdiff - src/Buffer.cpp
Return ExportStatus from Buffer to GuiView
[lyx.git] / src / Buffer.cpp
index 8204fe1aeaca2c1697c09fc5eca9af87c0b9e217..6e6fe18463cf938e9fa1999b0bf38746d0cef56c 100644 (file)
@@ -2095,9 +2095,9 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                break;
 
        case LFUN_BUFFER_EXPORT: {
-               bool success = doExport(argument, false, false);
-               dr.setError(!success);
-               if (!success)
+               ExportStatus const status = doExport(argument, false, false);
+               dr.setError(status != ExportSuccess);
+               if (status != ExportSuccess)
                        dr.setMessage(bformat(_("Error exporting to format: %1$s."), 
                                              func.argument()));
                break;
@@ -2283,10 +2283,7 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
                        break;
                }
 
-               bool const update_unincluded =
-                               params().maintain_unincluded_children
-                               && !params().getIncludedChildren().empty();
-               if (!doExport("dvi", true, update_unincluded)) {
+               if (!doExport("dvi", true)) {
                        showPrintError(absFileName());
                        dr.setMessage(_("Error exporting to DVI."));
                        break;
@@ -3486,10 +3483,19 @@ bool Buffer::isExporting() const
 }
 
 
-bool Buffer::doExport(string const & target, bool put_in_tempdir,
+Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir) const
+{
+       bool const update_unincluded =
+                       params().maintain_unincluded_children
+                       && !params().getIncludedChildren().empty();
+       return doExport(target, put_in_tempdir, update_unincluded);
+}
+
+
+Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir,
        bool includeall, string & result_file) const
 {
-       LYXERR(Debug::FILES, "target=" << target << ", result_file=" << result_file);
+       LYXERR(Debug::FILES, "target=" << target);
        OutputParams runparams(&params().encoding());
        string format = target;
        string dest_filename;
@@ -3528,7 +3534,7 @@ bool Buffer::doExport(string const & target, bool put_in_tempdir,
                                        _("No information for exporting the format %1$s."),
                                        formats.prettyName(format)));
                        }
-                       return false;
+                       return ExportNoPathToFormat;
                }
                runparams.flavor = converters.getFlavor(path);
 
@@ -3590,13 +3596,13 @@ bool Buffer::doExport(string const & target, bool put_in_tempdir,
                                d->cloned_buffer_->d->errorLists["Export"] =
                                        d->errorLists["Export"];
                        }
-                       return false;
+                       return ExportError;
                }
        } else if (!lyxrc.tex_allows_spaces
                   && contains(filePath(), ' ')) {
                Alert::error(_("File name error"),
                           _("The directory path to the document cannot contain spaces."));
-               return false;
+               return ExportTexPathHasSpaces;
        } else {
                runparams.nice = false;
                if (!makeLaTeXFile(FileName(filename), filePath(), runparams)) {
@@ -3604,7 +3610,7 @@ bool Buffer::doExport(string const & target, bool put_in_tempdir,
                                d->cloned_buffer_->d->errorLists["Export"] =
                                        d->errorLists["Export"];
                        }
-                       return false;
+                       return ExportError;
                }
        }
 
@@ -3653,11 +3659,11 @@ bool Buffer::doExport(string const & target, bool put_in_tempdir,
        }
 
        if (!success)
-               return false;
+               return ExportConverterError;
 
        if (put_in_tempdir) {
                result_file = tmp_result_file.absFileName();
-               return true;
+               return ExportSuccess;
        }
 
        if (dest_filename.empty())
@@ -3714,33 +3720,51 @@ bool Buffer::doExport(string const & target, bool put_in_tempdir,
                        formats.prettyName(format)));
        }
 
-       return true;
+       return ExportSuccess;
 }
 
 
-bool Buffer::doExport(string const & target, bool put_in_tempdir,
+Buffer::ExportStatus Buffer::doExport(string const & target, bool put_in_tempdir,
        bool includeall) const
 {
        string result_file;
        // (1) export with all included children (omit \includeonly)
-       if (includeall && !doExport(target, put_in_tempdir, true, result_file))
-               return false;
+       if (includeall) { 
+               ExportStatus const status = 
+                       doExport(target, put_in_tempdir, true, result_file);
+               if (status != ExportSuccess)
+                       return status;
+       }
        // (2) export with included children only
        return doExport(target, put_in_tempdir, false, result_file);
 }
 
 
-bool Buffer::preview(string const & format, bool includeall) const
+Buffer::ExportStatus Buffer::preview(string const & format) const
+{
+       bool const update_unincluded =
+                       params().maintain_unincluded_children
+                       && !params().getIncludedChildren().empty();
+       return preview(format, update_unincluded);
+}
+
+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))
-               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))
-               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;
 }