]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
This file is part of LyX, the document processor.
[lyx.git] / src / frontends / controllers / ControlPrint.C
1 /**
2  * \file ControlPrint.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "ControlPrint.h"
18
19 #include "ViewBase.h"
20 #include "ButtonControllerBase.h"
21
22 #include "buffer.h"
23 #include "gettext.h"
24 #include "helper_funcs.h"
25 #include "PrinterParams.h"
26
27 #include "frontends/Alert.h"
28 #include "frontends/Liason.h"
29
30 #include "support/LAssert.h"
31
32 using Liason::printBuffer;
33 using Liason::getPrinterParams;
34
35
36 ControlPrint::ControlPrint(LyXView & lv, Dialogs & d)
37         : ControlDialogBD(lv, d),
38           params_(0)
39 {}
40
41
42 void ControlPrint::apply()
43 {
44         if (!bufferIsAvailable())
45                 return;
46
47         view().apply();
48
49         if (!printBuffer(buffer(), params())) {
50                 Alert::alert(_("Error:"),
51                            _("Unable to print"),
52                            _("Check that your parameters are correct"));
53         }
54 }
55
56
57 PrinterParams & ControlPrint::params() const
58 {
59         lyx::Assert(params_);
60         return *params_;
61 }
62
63
64 void ControlPrint::setParams()
65 {
66         if (params_) delete params_;
67         params_ = new PrinterParams(getPrinterParams(buffer()));
68
69         bc().valid(); // so that the user can press Ok
70 }
71
72
73 void ControlPrint::clearParams()
74 {
75         if (params_) {
76                 delete params_;
77                 params_ = 0;
78         }
79 }
80
81
82 string const ControlPrint::Browse(string const & in_name)
83 {
84         string const title = _("Print to file");
85         string const pattern = "*.ps";
86
87         // Show the file browser dialog
88         return browseRelFile(&lv_, in_name, buffer()->filePath(),
89                              title, pattern);
90 }