3 * Read the file COPYING
5 * \author Angus Leeming
7 * Full author contact details are available in file CREDITS
13 #pragma implementation
16 #include "FormSendto.h"
17 #include "forms/form_sendto.h"
18 #include "ControlSendto.h"
21 #include "xforms_helpers.h"
22 #include "converter.h"
24 #include FORMS_H_LOCATION
28 typedef FormCB<ControlSendto, FormDB<FD_sendto> > base_class;
30 FormSendto::FormSendto()
31 : base_class(_("Send document to command"))
35 void FormSendto::build()
37 dialog_.reset(build_sendto(this));
39 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
40 setPrehandler(dialog_->input_command);
42 // Manage the ok, apply, restore and cancel/close buttons
43 bc().setOK(dialog_->button_ok);
44 bc().setApply(dialog_->button_apply);
45 bc().setCancel(dialog_->button_close);
47 // Set up the tooltip mechanism
48 string str = _("Export the buffer to this format before running the command below on it.");
49 tooltips().init(dialog_->browser_formats, str);
51 str = _("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
52 tooltips().init(dialog_->input_command, str);
56 void FormSendto::update()
58 all_formats_ = controller().allFormats();
60 // Check whether the current contents of the browser will be
61 // changed by loading the contents of formats
63 keys.resize(all_formats_.size());
65 vector<string>::iterator result = keys.begin();
66 vector<Format const *>::const_iterator it = all_formats_.begin();
67 vector<Format const *>::const_iterator end = all_formats_.end();
68 for (; it != end; ++it, ++result) {
69 *result = (*it)->prettyname();
72 vector<string> const browser_keys =
73 getVector(dialog_->browser_formats);
75 if (browser_keys == keys)
79 fl_clear_browser(dialog_->browser_formats);
81 for (vector<string>::const_iterator it = keys.begin();
82 it < keys.end(); ++it) {
83 fl_add_browser_line(dialog_->browser_formats, it->c_str());
86 fl_set_input(dialog_->input_command, controller().getCommand().c_str());
90 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
92 int const line = fl_get_browser(dialog_->browser_formats);
93 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
94 return ButtonPolicy::SMI_INVALID;
96 string cmd = getString(dialog_->input_command);
99 return ButtonPolicy::SMI_INVALID;
101 return ButtonPolicy::SMI_VALID;
105 void FormSendto::apply()
107 int const line = fl_get_browser(dialog_->browser_formats);
108 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
111 string const cmd = getString(dialog_->input_command);
113 controller().setFormat(all_formats_[line-1]);
114 controller().setCommand(cmd);