]> git.lyx.org Git - lyx.git/commitdiff
Introduce LFUN_PRINT.
authorAngus Leeming <leeming@lyx.org>
Sun, 28 Mar 2004 14:12:33 +0000 (14:12 +0000)
committerAngus Leeming <leeming@lyx.org>
Sun, 28 Mar 2004 14:12:33 +0000 (14:12 +0000)
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

24 files changed:
src/ChangeLog
src/LyXAction.C
src/frontends/ChangeLog
src/frontends/Dialogs.h
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlPrint.C
src/frontends/controllers/ControlPrint.h
src/frontends/gtk/ChangeLog
src/frontends/gtk/Dialogs.C
src/frontends/guiapi.C
src/frontends/guiapi.h
src/frontends/qt2/ChangeLog
src/frontends/qt2/Dialogs.C
src/frontends/qt2/Dialogs2.C
src/frontends/qt2/QPrint.C
src/frontends/qt2/QPrint.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/Dialogs.C
src/frontends/xforms/Dialogs2.C
src/frontends/xforms/FormPrint.C
src/frontends/xforms/FormPrint.h
src/frontends/xforms/forms/form_print.fd
src/lfuns.h
src/lyxfunc.C

index d97b7118349866283cbdec7edb7c23278a6ce5e6..cda0515861b9aae65d42b181e5ec0a4df723d994 100644 (file)
@@ -1,7 +1,14 @@
+2004-03-28  Angus Leeming  <leeming@lyx.org>
+
+       * lfuns.h:
+       * LyXAction.C (init): new LFUN_PRINT.
+
+       * lyxfunc.C (getStatus, dispatch): handle LFUN_PRINT.
+
 2004-03-27  Angus Leeming  <leeming@lyx.org>
 
        * lfuns.h:
-       * LyXAction.C (init): new LFUN_EXPORT_CUSTOM
+       * LyXAction.C (init): new LFUN_EXPORT_CUSTOM.
 
        * lyxfunc.C (getStatus, dispatch): handle LFUN_EXPORT_CUSTOM.
 
index ed5f0ced580908dd5800e5ef8d3299cb95b0266f..94dbbc7e19b16613df840d2dbdb6047fe3e259e8 100644 (file)
@@ -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 },
index 298b589597170aa0f65f27a06858e5b362c5b8fa..8f72b642c6db25ccc2583e1f48f82ff80438cf7d 100644 (file)
@@ -1,3 +1,9 @@
+2004-03-28  Angus Leeming  <leeming@lyx.org>
+
+       * Dialogs.h (showPrint): removed.
+
+       * guiapi.[Ch] (gui_ShowPrint): removed.
+
 2004-03-27  Angus Leeming  <leeming@lyx.org>
 
        * Dialogs.h (showSendto): removed.
index e066fb76d6118c37b057d0a2a5501d6aea42074d..d3ec0d02b05875c029f94c6ecd91b4b2ed73d6cd 100644 (file)
@@ -71,8 +71,6 @@ public:
        void showPreamble();
        ///
        void showPreferences();
-       ///
-       void showPrint();
        /// bring up the spellchecker
        void showSpellchecker();
        //@}
index 447f87fec540389a06120a4992d1f4154433f4ee..35552fe3c1a2914eda9be87712574eb5dd81c24c 100644 (file)
@@ -1,3 +1,7 @@
+2004-03-28  Angus Leeming  <leeming@lyx.org>
+
+       * ControlPrint.[Ch]: converted to the dialog-based scheme.
+
 2004-03-27  Angus Leeming  <leeming@lyx.org>
 
        * ControlSendto.[Ch]: converted to the dialog-based scheme.
index da85afa9c0aac3ded18768b604834284bd12484b..9daba9595728629043c61bc29ac180b4e749f91b 100644 (file)
 
 #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));
 }
index 99d60256ba225046a15d14c1a8f7e3a2b3464f9d..d847bb9edf995d8c1ee8a185a9aa61792dc210ab 100644 (file)
 #ifndef CONTROLPRINT_H
 #define CONTROLPRINT_H
 
-
-#include "ControlDialog_impl.h"
-
+#include "Dialog.h"
+#include <boost/scoped_ptr.hpp>
 
 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<PrinterParams> params_;
 };
 
 #endif // CONTROLPRINT_H
index 51a3e11341b6bd5ae77d1f630d970f429c9c225b..cfe3a7667a8b93db1169fe87a45c35b92d187b6b 100644 (file)
@@ -1,3 +1,7 @@
+2004-03-28  Angus Leeming  <leeming@lyx.org>
+
+       * Dialogs.C (build): added print dialog.
+
 2004-03-27  Angus Leeming  <leeming@lyx.org>
 
        * Dialogs.C (build): added box, fidreplace, log, sendto, vspace
index 86457e37b810e0b6e33125afec937bd67c5a9ead..24fcfef6d5d3ad73ff27ca93b3d9c62ccdeb808f 100644 (file)
@@ -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));
index d5b455ccafd5956c49c1ba83fd6265f534fd6757..398604b8c8917eff4af54652640c106b8657cddf 100644 (file)
@@ -40,12 +40,6 @@ void gui_ShowPreferences(Dialogs & d)
 }
 
 
-void gui_ShowPrint(Dialogs & d)
-{
-       d.showPrint();
-}
-
-
 void gui_ShowSpellchecker(Dialogs & d)
 {
        d.showSpellchecker();
index 7072cc0e429d8c5b31aa1868273035016df913a6..ec72c87641763eaac3c20ffab6ec6bb063ec5b29 100644 (file)
@@ -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"
index 714aaa00cb7148b85a2cfaff31c6ea30a5347706..a1eb4b0082765279c2a22ef201b95be3d56cfc6f 100644 (file)
@@ -1,6 +1,13 @@
+2004-03-28  Angus Leeming  <leeming@lyx.org>
+
+       * Dialogs.C (build): added print dialog.
+       * Dialogs2.C (showPrint): removed.
+
+       * QPrint.[Ch]: converted to the Dialog-based scheme.
+
 2004-03-27  Angus Leeming  <leeming@lyx.org>
 
-       * Dialogs.C (build): added sendto, dialog.
+       * Dialogs.C (build): added sendto dialog.
        * Dialogs2.C (showSendto): removed.
 
        * QSendto.[Ch]: converted to the Dialog-based scheme.
index c9b973a64c3203991b6c2edc1709828ead0b7dfc..244125cb78e9af4b32005f286f34170f606ea104 100644 (file)
@@ -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));
index 0dbd726562d4459bd164169cf71b6f4d46066b57..ddbccb88d3a476df459211c4c23ff8209bcf80e0 100644 (file)
@@ -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<ControlPrefs, QPrefs, OkApplyCancelPolicy, Qt2BC>
 PrefsDialog;
 
-typedef GUI<ControlPrint, QPrint, OkApplyCancelPolicy, Qt2BC>
-PrintDialog;
-
 typedef GUI<ControlSpellchecker, QSpellchecker, NoRepeatedApplyReadOnlyPolicy, Qt2BC>
 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();
index b5a39b139612aaef67bb41198d6ef449394ad547..730bd8d7c3e88950cba437c7f98ba81e16359ec0 100644 (file)
 #include <qpushbutton.h>
 
 
-typedef Qt2CB<ControlPrint, Qt2DB<QLPrintDialog> > base_class;
+typedef QController<ControlPrint, QView<QLPrintDialog> > base_class;
 
 
-QPrint::QPrint()
-       : base_class(_("LyX: Print Document"))
+QPrint::QPrint(Dialog & parent)
+       : base_class(parent, _("LyX: Print Document"))
 {
 }
 
index 941e08fac3bb3bc0aac74784a9be8db77aaca85e..f3b390ee7b8da3746a179fe5821efc86e251d5f8 100644 (file)
 #ifndef QPRINT_H
 #define QPRINT_H
 
-
-#include "Qt2Base.h"
+#include "QDialogView.h"
 
 class ControlPrint;
 class QLPrintDialog;
 
 ///
 class QPrint
-       : public Qt2CB<ControlPrint, Qt2DB<QLPrintDialog> >
+       : public QController<ControlPrint, QView<QLPrintDialog> >
 {
 public:
        ///
        friend class QLPrintDialog;
        ///
-       QPrint();
+       QPrint(Dialog &);
 private:
        /// Apply changes
        virtual void apply();
index dd23ea4d62b12270ba823e82f34cd398085ab04e..ba8588be3407405ac00b5395cd29285eab24a01d 100644 (file)
@@ -1,3 +1,11 @@
+2004-03-28  Angus Leeming  <leeming@lyx.org>
+
+       * 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  <leeming@lyx.org>
 
        * Dialogs.C (build): added sendto, dialog.
index 2e0727572709b84a71779f133220a24eb738c99c..7f535e59313011b8fa67ea98497af5719183dfd1 100644 (file)
@@ -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));
index bdaa5ec7097df250c5d4d35d59444f91d9d4a636..156c4ffe2db80a25176042b84daf2268f58c79fc 100644 (file)
 #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<ControlPrefs, FormPreferences, OkApplyCancelPolicy, xformsBC>
 PreferencesDialog;
 
-typedef GUI<ControlPrint, FormPrint, OkApplyCancelPolicy, xformsBC>
-PrintDialog;
-
 typedef GUI<ControlSpellchecker, FormSpellchecker, NoRepeatedApplyReadOnlyPolicy, xformsBC>
 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();
index ca497e0f386502c75829fb7bca95f682be75934b..a3ea1756ea58d693198c918c3b353e46a50331ab 100644 (file)
@@ -32,10 +32,10 @@ using lyx::support::strToInt;
 using std::string;
 
 
-typedef FormCB<ControlPrint, FormDB<FD_print> > base_class;
+typedef FormController<ControlPrint, FormView<FD_print> > base_class;
 
-FormPrint::FormPrint()
-       : base_class(_("Print Document"))
+FormPrint::FormPrint(Dialog & parent)
+       : base_class(parent, _("Print Document"))
 {}
 
 
index 0228ad38631571e64797802d7de36f1aa0937809..316c8951b5ffc9e033fdc2bf222e0471498adcb0 100644 (file)
@@ -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<ControlPrint, FormDB<FD_print> > {
+class FormPrint
+       : public FormController<ControlPrint, FormView<FD_print> > {
 public:
        ///
-       FormPrint();
+       FormPrint(Dialog &);
 private:
        /// Apply from dialog
        virtual void apply();
index 32af45e7420e37cae3567a8e37ac1fae97bf5e05..dc61ab0912b9fbfa49b579baca04a7d2009db84c 100644 (file)
@@ -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
 
 --------------------
index 17189355181e4d603ab96fd26b0b6ba6ad2fe68b..dc455b67b184fa9589a6d2b22ec9e1233565b8bf 100644 (file)
@@ -336,6 +336,7 @@ enum kb_action {
        LFUN_WORD_REPLACE,
        // 255
        LFUN_EXPORT_CUSTOM,
+       LFUN_PRINT,
 
        LFUN_LASTACTION                  // end of the table
 };
index d52e650bafaa314092a74eb0a63d823a74fe2429..eab75513a719417e182c5fe16145414743caa9db 100644 (file)
@@ -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();