]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormSendto.C
Introduce LFUN_PRINT.
[lyx.git] / src / frontends / xforms / FormSendto.C
1 /**
2  * \file FormSendto.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 #include "FormSendto.h"
14 #include "ControlSendto.h"
15 #include "forms/form_sendto.h"
16
17 #include "Tooltips.h"
18 #include "xforms_helpers.h"
19 #include "xformsBC.h"
20
21 #include "format.h"
22
23 #include "support/lstrings.h"
24
25 #include "lyx_forms.h"
26
27 using lyx::support::trim;
28
29 using std::vector;
30 using std::string;
31
32
33 typedef FormController<ControlSendto, FormView<FD_sendto> > base_class;
34
35 FormSendto::FormSendto(Dialog & parent)
36         : base_class(parent, _("Send document to command"))
37 {}
38
39
40 void FormSendto::build()
41 {
42         dialog_.reset(build_sendto(this));
43
44         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
45         setPrehandler(dialog_->input_command);
46
47         // Manage the ok, apply, restore and cancel/close buttons
48         bcview().setOK(dialog_->button_ok);
49         bcview().setApply(dialog_->button_apply);
50         bcview().setCancel(dialog_->button_close);
51
52         // Set up the tooltip mechanism
53         string str = _("Export the buffer to this format before running the command below on it.");
54         tooltips().init(dialog_->browser_formats, str);
55
56         str = _("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
57         tooltips().init(dialog_->input_command, str);
58 }
59
60
61 void FormSendto::update()
62 {
63         all_formats_ = controller().allFormats();
64
65         // Check whether the current contents of the browser will be
66         // changed by loading the contents of formats
67         vector<string> keys;
68         keys.resize(all_formats_.size());
69
70         vector<string>::iterator result = keys.begin();
71         vector<Format const *>::const_iterator it  = all_formats_.begin();
72         vector<Format const *>::const_iterator end = all_formats_.end();
73         for (; it != end; ++it, ++result) {
74                 *result = (*it)->prettyname();
75         }
76
77         vector<string> const browser_keys =
78                 getVector(dialog_->browser_formats);
79
80         if (browser_keys == keys)
81                 return;
82
83         // Reload the browser
84         fl_clear_browser(dialog_->browser_formats);
85
86         for (vector<string>::const_iterator it = keys.begin();
87              it < keys.end(); ++it) {
88                 fl_add_browser_line(dialog_->browser_formats, it->c_str());
89         }
90
91         fl_set_input(dialog_->input_command, controller().getCommand().c_str());
92 }
93
94
95 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
96 {
97         int const line = fl_get_browser(dialog_->browser_formats);
98         if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
99                 return ButtonPolicy::SMI_INVALID;
100
101         string cmd = getString(dialog_->input_command);
102         cmd = trim(cmd);
103         if (cmd.empty())
104                 return ButtonPolicy::SMI_INVALID;
105
106         return ButtonPolicy::SMI_VALID;
107 }
108
109
110 void FormSendto::apply()
111 {
112         int const line = fl_get_browser(dialog_->browser_formats);
113         if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
114                 return;
115
116         string const cmd = getString(dialog_->input_command);
117
118         controller().setFormat(all_formats_[line-1]);
119         controller().setCommand(cmd);
120 }