X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fcontrollers%2FControlPrint.C;h=da85afa9c0aac3ded18768b604834284bd12484b;hb=d891a896f47df2d7f048ad7e4498f2fd4f3c5d3b;hp=bcc51336dd79a4ae97312442d5290453650f2c97;hpb=ba9cdda813625e0dd224859027608cc0df705197;p=lyx.git diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index bcc51336dd..da85afa9c0 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -5,34 +5,46 @@ * * \author Angus Leeming * - * Full author contact details are available in file CREDITS + * Full author contact details are available in file CREDITS. */ #include - #include "ControlPrint.h" #include "ViewBase.h" #include "ButtonController.h" #include "buffer.h" +#include "bufferparams.h" #include "gettext.h" #include "helper_funcs.h" #include "PrinterParams.h" #include "exporter.h" -#include "converter.h" #include "frontends/Alert.h" -#include "support/LAssert.h" +#include "support/tostr.h" #include "support/filetools.h" +#include "support/globbing.h" #include "support/path.h" #include "support/systemcall.h" -#include "debug.h" // for lyxerr +#include "debug.h" + +using lyx::support::bformat; +using lyx::support::ChangeExtension; +using lyx::support::FileFilterList; +using lyx::support::IsDirWriteable; +using lyx::support::MakeAbsPath; +using lyx::support::MakeDisplayPath; +using lyx::support::Path; +using lyx::support::QuoteName; +using lyx::support::Systemcall; using std::endl; +using std::string; + ControlPrint::ControlPrint(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), @@ -42,7 +54,7 @@ ControlPrint::ControlPrint(LyXView & lv, Dialogs & d) PrinterParams & ControlPrint::params() const { - lyx::Assert(params_); + BOOST_ASSERT(params_); return *params_; } @@ -70,14 +82,25 @@ void ControlPrint::clearParams() } -string const ControlPrint::Browse(string const & in_name) +string const ControlPrint::browse(string const & in_name) const { - string const title = _("Print to file"); - string const pattern = "*.ps"; + return browseRelFile(in_name, buffer().filePath(), + _("Print to file"), + FileFilterList("PostScript files (*.ps)"), + true); +} + + +namespace { + +void showPrintError(string const & name) +{ + string str = bformat(_("Could not print the document %1$s.\n" + "Check that your printer is set up correctly."), + MakeDisplayPath(name, 50)); + Alert::error(_("Print document failed"), str); +} - // Show the file browser dialog - return browseRelFile(in_name, buffer()->filePath(), - title, pattern, true); } @@ -139,20 +162,15 @@ void ControlPrint::apply() command += lyxrc.print_extra_options + ' '; } - command += converters.dvips_options(buffer()) + ' '; + command += buffer()->params().dvips_options() + ' '; if (!Exporter::Export(buffer(), "dvi", true)) { - Alert::alert(_("Error:"), - _("Unable to print"), - _("Check that your parameters are correct")); + showPrintError(buffer()->fileName()); return; } // Push directory path. - string path = buffer()->filePath(); - if (lyxrc.use_tempdir || !IsDirWriteable(path)) { - path = buffer()->tmppath; - } + string const path = buffer()->temppath(); Path p(path); // there are three cases here: @@ -205,9 +223,6 @@ void ControlPrint::apply() lyxerr[Debug::LATEX] << "ControlPrint::apply(): print command = \"" << command << '"' << endl; - if (res != 0) { - Alert::alert(_("Error:"), - _("Unable to print"), - _("Check that your parameters are correct")); - } + if (res != 0) + showPrintError(buffer()->fileName()); }