]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlPrint.C
new alert code
[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 "ViewBase.h"
22 #include "ButtonControllerBase.h"
23 #include "ControlPrint.h"
24 #include "buffer.h"
25 #include "Dialogs.h"
26 #include "LyXView.h"
27 #include "lyxrc.h"
28 #include "PrinterParams.h"
29 #include "Liason.h"
30 #include "helper_funcs.h" // browseFile
31 #include "frontends/Alert.h"
32 #include "gettext.h"
33 #include "BufferView.h"
34 #include "support/LAssert.h"
35
36 using Liason::printBuffer;
37 using Liason::getPrinterParams;
38 using std::make_pair;
39
40 ControlPrint::ControlPrint(LyXView & lv, Dialogs & d)
41     : ControlDialog<ControlConnectBD>(lv, d),
42       params_(0)
43 {
44         d_.showPrint.connect(SigC::slot(this, &ControlPrint::show));
45 }
46
47
48 void ControlPrint::apply()
49 {
50         if (!lv_.view()->available())
51                 return;
52    
53         view().apply();
54
55         if (!printBuffer(lv_.buffer(), params())) {
56                 Alert::alert(_("Error:"),
57                            _("Unable to print"),
58                            _("Check that your parameters are correct"));
59         }
60 }
61
62
63 PrinterParams & ControlPrint::params() const
64 {
65         lyx::Assert(params_);
66         return *params_;
67 }
68
69
70 void ControlPrint::setParams()
71 {
72         if (params_) delete params_;
73         params_ = new PrinterParams(getPrinterParams(lv_.buffer()));
74
75         bc().valid(); // so that the user can press Ok
76 }
77
78
79 void ControlPrint::clearParams()
80 {
81         if (params_) {
82                 delete params_;
83                 params_ = 0;
84         }
85 }
86
87
88 string const ControlPrint::Browse(string const & in_name)
89 {
90         string const title = N_("Print to file");
91         string const pattern = "*.ps";
92
93         // Show the file browser dialog
94         return browseFile(&lv_, in_name, title, pattern,
95                            make_pair(string(), string()),
96                            make_pair(string(), string()));
97 }