]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
implement getLabelList
[lyx.git] / src / frontends / controllers / ControlPrint.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 2001 The LyX Team.
7  *
8  *======================================================
9  *
10  * \file ControlPrint.C
11  * \author Angus Leeming, a.leeming@.ac.uk
12  */
13
14 #include <config.h>
15 #include <utility>
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "ControlPrint.h"
22 #include "buffer.h"
23 #include "Dialogs.h"
24 #include "LyXView.h"
25 #include "lyxrc.h"
26 #include "PrinterParams.h"
27 #include "Liason.h"
28 #include "helper_funcs.h" // browseFile
29 #include "lyx_gui_misc.h" // WriteAlert
30
31 using Liason::printBuffer;
32 using Liason::getPrinterParams;
33 using std::make_pair;
34
35 ControlPrint::ControlPrint(LyXView & lv, Dialogs & d)
36         : ControlDialog<ControlConnectBD>(lv, d)
37 {
38         d_.showPrint.connect(SigC::slot(this, &ControlPrint::show));
39 }
40
41
42 void ControlPrint::apply()
43 {
44         if (!lv_.view()->available())
45                 return;
46    
47         view().apply();
48
49         if (!printBuffer(lv_.buffer(), params())) {
50                 WriteAlert(_("Error:"),
51                            _("Unable to print"),
52                            _("Check that your parameters are correct"));
53         }
54 }
55
56
57 PrinterParams & ControlPrint::params() const
58 {
59         Assert(params_);
60         return *params_;
61 }
62
63
64 void ControlPrint::setParams()
65 {
66         if (params_) delete params_;
67         params_ = new PrinterParams(getPrinterParams(lv_.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 = N_("Print to file");
85         string const pattern = "*.ps";
86
87         // Show the file browser dialog
88         return browseFile(&lv_, in_name, title, pattern,
89                            make_pair(string(), string()),
90                            make_pair(string(), string()));
91 }