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