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