From 39ec3d0eb81f6e3ade7bc183f7590f3a0bcd6cf7 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Sun, 28 Mar 2004 14:12:33 +0000 Subject: [PATCH] Introduce LFUN_PRINT. Convert the printer dialog to the Dialog-based scheme. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8552 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 9 +- src/LyXAction.C | 1 + src/frontends/ChangeLog | 6 + src/frontends/Dialogs.h | 2 - src/frontends/controllers/ChangeLog | 4 + src/frontends/controllers/ControlPrint.C | 150 +++++------------------ src/frontends/controllers/ControlPrint.h | 26 ++-- src/frontends/gtk/ChangeLog | 4 + src/frontends/gtk/Dialogs.C | 10 +- src/frontends/guiapi.C | 6 - src/frontends/guiapi.h | 1 - src/frontends/qt2/ChangeLog | 9 +- src/frontends/qt2/Dialogs.C | 10 +- src/frontends/qt2/Dialogs2.C | 14 --- src/frontends/qt2/QPrint.C | 6 +- src/frontends/qt2/QPrint.h | 7 +- src/frontends/xforms/ChangeLog | 8 ++ src/frontends/xforms/Dialogs.C | 10 +- src/frontends/xforms/Dialogs2.C | 15 --- src/frontends/xforms/FormPrint.C | 6 +- src/frontends/xforms/FormPrint.h | 9 +- src/frontends/xforms/forms/form_print.fd | 34 ++--- src/lfuns.h | 1 + src/lyxfunc.C | 104 +++++++++++++++- 24 files changed, 239 insertions(+), 213 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index d97b711834..cda0515861 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,7 +1,14 @@ +2004-03-28 Angus Leeming + + * lfuns.h: + * LyXAction.C (init): new LFUN_PRINT. + + * lyxfunc.C (getStatus, dispatch): handle LFUN_PRINT. + 2004-03-27 Angus Leeming * lfuns.h: - * LyXAction.C (init): new LFUN_EXPORT_CUSTOM + * LyXAction.C (init): new LFUN_EXPORT_CUSTOM. * lyxfunc.C (getStatus, dispatch): handle LFUN_EXPORT_CUSTOM. diff --git a/src/LyXAction.C b/src/LyXAction.C index ed5f0ced58..94dbbc7e19 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -115,6 +115,7 @@ void LyXAction::init() { LFUN_ENDBUFSEL, "buffer-end-select", ReadOnly }, { LFUN_EXPORT, "buffer-export", ReadOnly }, { LFUN_EXPORT_CUSTOM, "buffer-export-custom", ReadOnly }, + { LFUN_PRINT, "buffer-print", ReadOnly }, { LFUN_IMPORT, "buffer-import", NoBuffer }, { LFUN_MENUNEW, "buffer-new", NoBuffer }, { LFUN_MENUNEWTMPLT,"buffer-new-template", NoBuffer }, diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 298b589597..8f72b642c6 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,9 @@ +2004-03-28 Angus Leeming + + * Dialogs.h (showPrint): removed. + + * guiapi.[Ch] (gui_ShowPrint): removed. + 2004-03-27 Angus Leeming * Dialogs.h (showSendto): removed. diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index e066fb76d6..d3ec0d02b0 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -71,8 +71,6 @@ public: void showPreamble(); /// void showPreferences(); - /// - void showPrint(); /// bring up the spellchecker void showSpellchecker(); //@} diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 447f87fec5..35552fe3c1 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2004-03-28 Angus Leeming + + * ControlPrint.[Ch]: converted to the dialog-based scheme. + 2004-03-27 Angus Leeming * ControlSendto.[Ch]: converted to the dialog-based scheme. diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index da85afa9c0..9daba95957 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -12,106 +12,68 @@ #include "ControlPrint.h" -#include "ViewBase.h" #include "ButtonController.h" +#include "helper_funcs.h" #include "buffer.h" #include "bufferparams.h" +#include "funcrequest.h" #include "gettext.h" -#include "helper_funcs.h" #include "PrinterParams.h" -#include "exporter.h" - -#include "frontends/Alert.h" #include "support/tostr.h" #include "support/filetools.h" #include "support/globbing.h" -#include "support/path.h" -#include "support/systemcall.h" -#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; +using std::string; -ControlPrint::ControlPrint(LyXView & lv, Dialogs & d) - : ControlDialogBD(lv, d), +ControlPrint::ControlPrint(Dialog & parent) + : Dialog::Controller(parent), params_(0) {} -PrinterParams & ControlPrint::params() const -{ - BOOST_ASSERT(params_); - return *params_; -} - - -void ControlPrint::setParams() +bool ControlPrint::initialiseParams(std::string const &) { - if (params_) delete params_; - /// get global printer parameters - string const name = ChangeExtension(buffer()->fileName(), + string const name = ChangeExtension(kernel().buffer().fileName(), lyxrc.print_file_extension); - params_ = new PrinterParams (PrinterParams::PRINTER, - lyxrc.printer, name); + params_.reset(new PrinterParams (PrinterParams::PRINTER, + lyxrc.printer, name)); - bc().valid(); // so that the user can press Ok + dialog().bc().valid(); // so that the user can press Ok + return true; } void ControlPrint::clearParams() { - if (params_) { - delete params_; - params_ = 0; - } + params_.reset(); } -string const ControlPrint::browse(string const & in_name) const +PrinterParams & ControlPrint::params() const { - return browseRelFile(in_name, buffer().filePath(), - _("Print to file"), - FileFilterList("PostScript files (*.ps)"), - true); + BOOST_ASSERT(params_.get()); + return *params_; } -namespace { - -void showPrintError(string const & name) +string const ControlPrint::browse(string const & in_name) const { - 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); -} - + return browseRelFile(in_name, kernel().buffer().filePath(), + _("Print to file"), + FileFilterList("PostScript files (*.ps)"), + true); } /// print the current buffer -void ControlPrint::apply() +void ControlPrint::dispatchParams() { - if (!bufferIsAvailable()) - return; - - view().apply(); - PrinterParams const pp = params(); string command(lyxrc.print_command + ' '); @@ -162,67 +124,15 @@ void ControlPrint::apply() command += lyxrc.print_extra_options + ' '; } - command += buffer()->params().dvips_options() + ' '; - - if (!Exporter::Export(buffer(), "dvi", true)) { - showPrintError(buffer()->fileName()); - return; - } - - // Push directory path. - string const path = buffer()->temppath(); - Path p(path); - - // there are three cases here: - // 1. we print to a file - // 2. we print directly to a printer - // 3. we print using a spool command (print to file first) - Systemcall one; - int res = 0; - string const dviname = ChangeExtension(buffer()->getLatexName(true), "dvi"); - switch (pp.target) { - case PrinterParams::PRINTER: - if (!lyxrc.print_spool_command.empty()) { - // case 3: print using a spool - string const psname = ChangeExtension(dviname, ".ps"); - command += lyxrc.print_to_file - + QuoteName(psname) - + ' ' - + QuoteName(dviname); - - string command2 = lyxrc.print_spool_command + ' '; - if (!pp.printer_name.empty()) { - command2 += lyxrc.print_spool_printerprefix - + pp.printer_name - + ' '; - } - command2 += QuoteName(psname); - // First run dvips. - // If successful, then spool command - res = one.startscript(Systemcall::Wait, command); - if (res == 0) - res = one.startscript(Systemcall::DontWait, - command2); - } else { - // case 2: print directly to a printer - res = one.startscript(Systemcall::DontWait, - command + QuoteName(dviname)); - } - break; - - case PrinterParams::FILE: - // case 1: print to a file - command += lyxrc.print_to_file - + QuoteName(MakeAbsPath(pp.file_name, path)) - + ' ' - + QuoteName(dviname); - res = one.startscript(Systemcall::DontWait, command); - break; - } + command += kernel().buffer().params().dvips_options() + ' '; - lyxerr[Debug::LATEX] << "ControlPrint::apply(): print command = \"" - << command << '"' << endl; + string const target = (pp.target == PrinterParams::PRINTER) ? + "printer" : "file"; + + string const target_name = (pp.target == PrinterParams::PRINTER) ? + (pp.printer_name.empty() ? "default" : pp.printer_name) : + pp.file_name; - if (res != 0) - showPrintError(buffer()->fileName()); + string const data = target + " " + target_name + " " + command; + kernel().dispatch(FuncRequest(LFUN_PRINT, data)); } diff --git a/src/frontends/controllers/ControlPrint.h b/src/frontends/controllers/ControlPrint.h index 99d60256ba..d847bb9edf 100644 --- a/src/frontends/controllers/ControlPrint.h +++ b/src/frontends/controllers/ControlPrint.h @@ -13,33 +13,33 @@ #ifndef CONTROLPRINT_H #define CONTROLPRINT_H - -#include "ControlDialog_impl.h" - +#include "Dialog.h" +#include class PrinterParams; /** A controller for Print dialogs. */ -class ControlPrint : public ControlDialogBD { +class ControlPrint : public Dialog::Controller { public: /// - ControlPrint(LyXView &, Dialogs &); + ControlPrint(Dialog &); + /// + virtual bool initialiseParams(std::string const & data); + /// + virtual void clearParams(); + /// + virtual void dispatchParams(); + /// + virtual bool isBufferDependent() const { return true; } /// Browse for a file std::string const browse(std::string const &) const; /// PrinterParams & params() const; private: - /// Get changed parameters and Dispatch them to the kernel. - virtual void apply(); - /// set the params before show or update. - virtual void setParams(); - /// clean-up on hide. - virtual void clearParams(); - /// - PrinterParams * params_; + boost::scoped_ptr params_; }; #endif // CONTROLPRINT_H diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 51a3e11341..cfe3a7667a 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,7 @@ +2004-03-28 Angus Leeming + + * Dialogs.C (build): added print dialog. + 2004-03-27 Angus Leeming * Dialogs.C (build): added box, fidreplace, log, sendto, vspace diff --git a/src/frontends/gtk/Dialogs.C b/src/frontends/gtk/Dialogs.C index 86457e37b8..24fcfef6d5 100644 --- a/src/frontends/gtk/Dialogs.C +++ b/src/frontends/gtk/Dialogs.C @@ -33,6 +33,7 @@ #include "ControlMath.h" #include "ControlNote.h" #include "ControlParagraph.h" +#include "ControlPrint.h" #include "ControlRef.h" #include "ControlSearch.h" #include "ControlSendto.h" @@ -68,6 +69,7 @@ #include "FormMathsStyle.h" #include "FormNote.h" #include "FormParagraph.h" +#include "FormPrint.h" #include "FormRef.h" #include "FormSearch.h" #include "FormSendto.h" @@ -126,13 +128,13 @@ char const * const dialognames[] = { "mathgreek", "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc", "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators", "mathdelimiter", "mathmatrix", "mathspace", "mathstyle", -"box", "note", "paragraph", "ref", "sendto", "tabular", "tabularcreate", "texinfo", +"box", "note", "paragraph", "print", "ref", "sendto", "tabular", "tabularcreate", #ifdef HAVE_LIBAIKSAURUS "thesaurus", #endif -"toc", "url", "vspace", "wrap" }; +"texinfo", "toc", "url", "vspace", "wrap" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -437,6 +439,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlParagraph(*dialog)); dialog->setView(new FormParagraph(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + } else if (name == "print") { + dialog->setController(new ControlPrint(*dialog)); + dialog->setView(new FormPrint(*dialog)); + dialog->bc().bp(new OkApplyCancelPolicy); } else if (name == "ref") { dialog->setController(new ControlRef(*dialog)); dialog->setView(new FormRef(*dialog)); diff --git a/src/frontends/guiapi.C b/src/frontends/guiapi.C index d5b455ccaf..398604b8c8 100644 --- a/src/frontends/guiapi.C +++ b/src/frontends/guiapi.C @@ -40,12 +40,6 @@ void gui_ShowPreferences(Dialogs & d) } -void gui_ShowPrint(Dialogs & d) -{ - d.showPrint(); -} - - void gui_ShowSpellchecker(Dialogs & d) { d.showSpellchecker(); diff --git a/src/frontends/guiapi.h b/src/frontends/guiapi.h index 7072cc0e42..ec72c87641 100644 --- a/src/frontends/guiapi.h +++ b/src/frontends/guiapi.h @@ -23,7 +23,6 @@ void gui_show_dialog(Dialogs *, char const * name, char const * data); void gui_ShowDocument(Dialogs &); void gui_ShowPreamble(Dialogs &); void gui_ShowPreferences(Dialogs &); -void gui_ShowPrint(Dialogs &); void gui_ShowSpellchecker(Dialogs &); } // extern "C" diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 714aaa00cb..a1eb4b0082 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,6 +1,13 @@ +2004-03-28 Angus Leeming + + * Dialogs.C (build): added print dialog. + * Dialogs2.C (showPrint): removed. + + * QPrint.[Ch]: converted to the Dialog-based scheme. + 2004-03-27 Angus Leeming - * Dialogs.C (build): added sendto, dialog. + * Dialogs.C (build): added sendto dialog. * Dialogs2.C (showSendto): removed. * QSendto.[Ch]: converted to the Dialog-based scheme. diff --git a/src/frontends/qt2/Dialogs.C b/src/frontends/qt2/Dialogs.C index c9b973a64c..244125cb78 100644 --- a/src/frontends/qt2/Dialogs.C +++ b/src/frontends/qt2/Dialogs.C @@ -29,6 +29,7 @@ #include "ControlMath.h" #include "ControlNote.h" #include "ControlParagraph.h" +#include "ControlPrint.h" #include "ControlRef.h" #include "ControlSearch.h" #include "ControlSendto.h" @@ -64,6 +65,7 @@ #include "QMath.h" #include "QNote.h" #include "QParagraph.h" +#include "QPrint.h" #include "QRef.h" #include "QSearch.h" #include "QSendto.h" @@ -92,8 +94,8 @@ char const * const dialognames[] = { "aboutlyx", "bibitem", "bibtex", "box", "branch", "changes", "character", "citation", "error", "errorlist", "ert", "external", "file", "findreplace", "float", "graphics", "include", "index", "label", "log", "mathpanel", -"mathdelimiter", "mathmatrix", -"note", "paragraph", "ref", "sendto", "tabular", "tabularcreate", "texinfo", +"mathdelimiter", "mathmatrix", "note", "paragraph", "print", "ref", "sendto", +"tabular", "tabularcreate", "texinfo", #ifdef HAVE_LIBAIKSAURUS "thesaurus", @@ -232,6 +234,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlParagraph(*dialog)); dialog->setView(new QParagraph(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + } else if (name == "print") { + dialog->setController(new ControlPrint(*dialog)); + dialog->setView(new QPrint(*dialog)); + dialog->bc().bp(new OkApplyCancelPolicy); } else if (name == "ref") { dialog->setController(new ControlRef(*dialog)); dialog->setView(new QRef(*dialog)); diff --git a/src/frontends/qt2/Dialogs2.C b/src/frontends/qt2/Dialogs2.C index 0dbd726562..ddbccb88d3 100644 --- a/src/frontends/qt2/Dialogs2.C +++ b/src/frontends/qt2/Dialogs2.C @@ -18,7 +18,6 @@ #include "ButtonController.h" #include "ControlDocument.h" -#include "ControlPrint.h" #include "ControlSpellchecker.h" #include "QDocument.h" @@ -29,8 +28,6 @@ #undef signals #include "QPrefs.h" #include "QPrefsDialog.h" -#include "QPrint.h" -#include "QLPrintDialog.h" #include "QSpellchecker.h" #include "QSpellcheckerDialog.h" @@ -43,9 +40,6 @@ DocumentDialog; typedef GUI PrefsDialog; -typedef GUI -PrintDialog; - typedef GUI SpellcheckerDialog; @@ -54,7 +48,6 @@ struct Dialogs::Impl { DocumentDialog document; PrefsDialog prefs; - PrintDialog print; SpellcheckerDialog spellchecker; }; @@ -62,7 +55,6 @@ struct Dialogs::Impl { Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) : document(lv, d), prefs(lv, d), - print(lv, d), spellchecker(lv, d) {} @@ -99,12 +91,6 @@ void Dialogs::showPreferences() } -void Dialogs::showPrint() -{ - pimpl_->print.controller().show(); -} - - void Dialogs::showSpellchecker() { pimpl_->spellchecker.controller().show(); diff --git a/src/frontends/qt2/QPrint.C b/src/frontends/qt2/QPrint.C index b5a39b1396..730bd8d7c3 100644 --- a/src/frontends/qt2/QPrint.C +++ b/src/frontends/qt2/QPrint.C @@ -27,11 +27,11 @@ #include -typedef Qt2CB > base_class; +typedef QController > base_class; -QPrint::QPrint() - : base_class(_("LyX: Print Document")) +QPrint::QPrint(Dialog & parent) + : base_class(parent, _("LyX: Print Document")) { } diff --git a/src/frontends/qt2/QPrint.h b/src/frontends/qt2/QPrint.h index 941e08fac3..f3b390ee7b 100644 --- a/src/frontends/qt2/QPrint.h +++ b/src/frontends/qt2/QPrint.h @@ -13,21 +13,20 @@ #ifndef QPRINT_H #define QPRINT_H - -#include "Qt2Base.h" +#include "QDialogView.h" class ControlPrint; class QLPrintDialog; /// class QPrint - : public Qt2CB > + : public QController > { public: /// friend class QLPrintDialog; /// - QPrint(); + QPrint(Dialog &); private: /// Apply changes virtual void apply(); diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index dd23ea4d62..ba8588be34 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,11 @@ +2004-03-28 Angus Leeming + + * Dialogs.C (build): added print dialog. + * Dialogs2.C (showPrint): removed. + + * FormPrint.[Ch]: + * forms/form_print.fd: converted to the Dialog-based scheme. + 2004-03-27 Angus Leeming * Dialogs.C (build): added sendto, dialog. diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 2e07275727..7f535e5931 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -30,6 +30,7 @@ #include "ControlMath.h" #include "ControlNote.h" #include "ControlParagraph.h" +#include "ControlPrint.h" #include "ControlRef.h" #include "ControlSearch.h" #include "ControlSendto.h" @@ -63,6 +64,7 @@ #include "FormMathsStyle.h" #include "FormNote.h" #include "FormParagraph.h" +#include "FormPrint.h" #include "FormRef.h" #include "FormTabular.h" #include "FormTexinfo.h" @@ -121,13 +123,13 @@ char const * const dialognames[] = { "mathgreek", "mathmisc", "mathdots", "mathbigoperators", "mathamsmisc", "mathamsarrows", "mathamsrelations", "mathamsnegatedrelations", "mathamsoperators", "mathdelimiter", "mathmatrix", "mathspace", "mathstyle", -"note", "paragraph", "ref", "sendto", "tabular", "tabularcreate", "texinfo", +"note", "paragraph", "print", "ref", "sendto", "tabular", "tabularcreate", #ifdef HAVE_LIBAIKSAURUS "thesaurus", #endif -"toc", "url", "vspace", "wrap" }; +"texinfo", "toc", "url", "vspace", "wrap" }; char const * const * const end_dialognames = dialognames + (sizeof(dialognames) / sizeof(char *)); @@ -427,6 +429,10 @@ Dialog * Dialogs::build(string const & name) dialog->setController(new ControlParagraph(*dialog)); dialog->setView(new FormParagraph(*dialog)); dialog->bc().bp(new OkApplyCancelReadOnlyPolicy); + } else if (name == "print") { + dialog->setController(new ControlPrint(*dialog)); + dialog->setView(new FormPrint(*dialog)); + dialog->bc().bp(new OkApplyCancelPolicy); } else if (name == "ref") { dialog->setController(new ControlRef(*dialog)); dialog->setView(new FormRef(*dialog)); diff --git a/src/frontends/xforms/Dialogs2.C b/src/frontends/xforms/Dialogs2.C index bdaa5ec709..156c4ffe2d 100644 --- a/src/frontends/xforms/Dialogs2.C +++ b/src/frontends/xforms/Dialogs2.C @@ -31,10 +31,6 @@ #include "FormColorpicker.h" #include "forms/form_preferences.h" -#include "ControlPrint.h" -#include "FormPrint.h" -#include "forms/form_print.h" - #include "ControlSpellchecker.h" #include "FormSpellchecker.h" #include "forms/form_spellchecker.h" @@ -48,9 +44,6 @@ PreambleDialog; typedef GUI PreferencesDialog; -typedef GUI -PrintDialog; - typedef GUI SpellcheckerDialog; @@ -61,7 +54,6 @@ struct Dialogs::Impl { DocumentDialog document; PreambleDialog preamble; PreferencesDialog preferences; - PrintDialog print; SpellcheckerDialog spellchecker; }; @@ -70,7 +62,6 @@ Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) : document(lv, d), preamble(lv, d), preferences(lv, d), - print(lv, d), spellchecker(lv, d) {} @@ -105,12 +96,6 @@ void Dialogs::showPreferences() } -void Dialogs::showPrint() -{ - pimpl_->print.controller().show(); -} - - void Dialogs::showSpellchecker() { pimpl_->spellchecker.controller().show(); diff --git a/src/frontends/xforms/FormPrint.C b/src/frontends/xforms/FormPrint.C index ca497e0f38..a3ea1756ea 100644 --- a/src/frontends/xforms/FormPrint.C +++ b/src/frontends/xforms/FormPrint.C @@ -32,10 +32,10 @@ using lyx::support::strToInt; using std::string; -typedef FormCB > base_class; +typedef FormController > base_class; -FormPrint::FormPrint() - : base_class(_("Print Document")) +FormPrint::FormPrint(Dialog & parent) + : base_class(parent, _("Print Document")) {} diff --git a/src/frontends/xforms/FormPrint.h b/src/frontends/xforms/FormPrint.h index 0228ad3863..316c8951b5 100644 --- a/src/frontends/xforms/FormPrint.h +++ b/src/frontends/xforms/FormPrint.h @@ -13,9 +13,7 @@ #ifndef FORMPRINT_H #define FORMPRINT_H - - -#include "FormBase.h" +#include "FormDialogView.h" #include "RadioButtonGroup.h" class ControlPrint; @@ -24,10 +22,11 @@ struct FD_print; /** This class provides an XForms implementation of the FormPrint Dialog. The print dialog allows users to print their documents. */ -class FormPrint : public FormCB > { +class FormPrint + : public FormController > { public: /// - FormPrint(); + FormPrint(Dialog &); private: /// Apply from dialog virtual void apply(); diff --git a/src/frontends/xforms/forms/form_print.fd b/src/frontends/xforms/forms/form_print.fd index 32af45e742..dc61ab0912 100644 --- a/src/frontends/xforms/forms/form_print.fd +++ b/src/frontends/xforms/forms/form_print.fd @@ -100,7 +100,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_printer -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -118,7 +118,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_East name: input_file -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -136,7 +136,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_close -callback: C_FormBaseCancelCB +callback: C_FormDialogView_CancelCB argument: 0 -------------------- @@ -154,7 +154,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_NoGravity name: input_from_page -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -172,7 +172,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_NoGravity FL_NoGravity name: check_sorted_copies -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -190,7 +190,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_NoGravity FL_NoGravity name: input_to_page -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -208,7 +208,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: button_browse -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -226,7 +226,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: check_reverse_order -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -244,7 +244,7 @@ shortcut: resize: FL_RESIZE_X gravity: FL_West FL_NoGravity name: counter_copies -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 bounds: 1 1000000 precision: 0 @@ -267,7 +267,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_ok -callback: C_FormBaseOKCB +callback: C_FormDialogView_OKCB argument: 0 -------------------- @@ -285,7 +285,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_SouthEast FL_SouthEast name: button_apply -callback: C_FormBaseApplyCB +callback: C_FormDialogView_ApplyCB argument: 0 -------------------- @@ -303,7 +303,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: check_odd_pages -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -321,7 +321,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: check_even_pages -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -357,7 +357,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: radio_printer -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -375,7 +375,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: radio_file -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -429,7 +429,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: radio_all_pages -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- @@ -447,7 +447,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_West FL_West name: radio_from_to -callback: C_FormBaseInputCB +callback: C_FormDialogView_InputCB argument: 0 -------------------- diff --git a/src/lfuns.h b/src/lfuns.h index 1718935518..dc455b67b1 100644 --- a/src/lfuns.h +++ b/src/lfuns.h @@ -336,6 +336,7 @@ enum kb_action { LFUN_WORD_REPLACE, // 255 LFUN_EXPORT_CUSTOM, + LFUN_PRINT, LFUN_LASTACTION // end of the table }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index d52e650baf..eab75513a7 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -76,6 +76,7 @@ #include "support/filetools.h" #include "support/forkedcontr.h" #include "support/globbing.h" +#include "support/lstrings.h" #include "support/path.h" #include "support/path_defines.h" #include "support/systemcall.h" @@ -101,6 +102,7 @@ using lyx::support::isStrInt; using lyx::support::MakeAbsPath; using lyx::support::MakeDisplayPath; using lyx::support::Path; +using lyx::support::QuoteName; using lyx::support::rtrim; using lyx::support::split; using lyx::support::strToInt; @@ -482,6 +484,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const case LFUN_KMAP_TOGGLE: case LFUN_REPEAT: case LFUN_EXPORT_CUSTOM: + case LFUN_PRINT: case LFUN_SEQUENCE: case LFUN_SAVEPREFERENCES: case LFUN_SCREEN_FONT_UPDATE: @@ -535,6 +538,14 @@ bool ensureBufferClean(BufferView * bv) return buf.isClean(); } +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); +} + } //namespace anon @@ -730,6 +741,97 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) break; } + case LFUN_PRINT: { + string target; + string target_name; + string command = split(split(argument, target, ' '), + target_name, ' '); + + if (target.empty() + || target_name.empty() + || command.empty()) { + lyxerr << "Unable to parse \"" + << argument << '"' << std::endl; + break; + } + if (target != "printer" && target != "file") { + lyxerr << "Unrecognized target \"" + << target << '"' << std::endl; + break; + } + + Buffer * buffer = owner->buffer(); + + if (!Exporter::Export(buffer, "dvi", true)) { + showPrintError(buffer->fileName()); + break; + } + + // Push directory path. + string const path = buffer->temppath(); + Path p(path); + + // there are three cases here: + // 1. we print to a file + // 2. we print directly to a printer + // 3. we print using a spool command (print to file first) + Systemcall one; + int res = 0; + string const dviname = + ChangeExtension(buffer->getLatexName(true), + "dvi"); + + if (target == "printer") { + if (!lyxrc.print_spool_command.empty()) { + // case 3: print using a spool + string const psname = + ChangeExtension(dviname,".ps"); + command += lyxrc.print_to_file + + QuoteName(psname) + + ' ' + + QuoteName(dviname); + + string command2 = + lyxrc.print_spool_command +' '; + if (target_name != "default") { + command2 += lyxrc.print_spool_printerprefix + + target_name + + ' '; + } + command2 += QuoteName(psname); + // First run dvips. + // If successful, then spool command + res = one.startscript( + Systemcall::Wait, + command); + + if (res == 0) + res = one.startscript( + Systemcall::DontWait, + command2); + } else { + // case 2: print directly to a printer + res = one.startscript( + Systemcall::DontWait, + command + QuoteName(dviname)); + } + + } else { + // case 1: print to a file + command += lyxrc.print_to_file + + QuoteName(MakeAbsPath(target_name, + path)) + + ' ' + + QuoteName(dviname); + res = one.startscript(Systemcall::DontWait, + command); + } + + if (res != 0) + showPrintError(buffer->fileName()); + break; + } + case LFUN_IMPORT: doImport(argument); break; @@ -915,8 +1017,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose) owner->getDialogs().showPreamble(); else if (name == "preferences") owner->getDialogs().showPreferences(); - else if (name == "print") - owner->getDialogs().showPrint(); else if (name == "spellchecker") owner->getDialogs().showSpellchecker(); -- 2.39.2