*
* \author Angus Leeming
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-
#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),
PrinterParams & ControlPrint::params() const
{
- lyx::Assert(params_);
+ BOOST_ASSERT(params_);
return *params_;
}
}
-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);
}
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:
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());
}