3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming, a.leeming@ic.ac.uk
12 #pragma implementation
15 #include "FormSendto.h"
16 #include "form_sendto.h"
17 #include "ControlSendto.h"
20 #include "xforms_helpers.h"
21 #include "converter.h"
26 typedef FormCB<ControlSendto, FormDB<FD_form_sendto> > base_class;
28 FormSendto::FormSendto(ControlSendto & c)
29 : base_class(c, _("Send document to command"))
33 void FormSendto::build()
35 dialog_.reset(build_sendto());
37 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
38 setPrehandler(dialog_->input_command);
40 // Manage the ok, apply, restore and cancel/close buttons
41 bc().setOK(dialog_->button_ok);
42 bc().setApply(dialog_->button_apply);
43 bc().setCancel(dialog_->button_close);
45 // Set up the tooltip mechanism
46 string str = N_("Export the buffer to this format before running the command below on it.");
47 tooltips().init(dialog_->browser_formats, str);
49 str = N_("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
50 tooltips().init(dialog_->input_command, str);
54 void FormSendto::update()
56 all_formats_ = controller().allFormats();
58 // Check whether the current contents of the browser will be
59 // changed by loading the contents of formats
61 keys.resize(all_formats_.size());
63 vector<string>::iterator result = keys.begin();
64 vector<Format const *>::const_iterator it = all_formats_.begin();
65 vector<Format const *>::const_iterator end = all_formats_.end();
66 for (; it != end; ++it, ++result) {
67 *result = (*it)->prettyname();
70 vector<string> const browser_keys =
71 getVectorFromBrowser(dialog_->browser_formats);
73 if (browser_keys == keys)
77 fl_clear_browser(dialog_->browser_formats);
79 for (vector<string>::const_iterator it = keys.begin();
80 it < keys.end(); ++it) {
81 fl_add_browser_line(dialog_->browser_formats, it->c_str());
84 fl_set_input(dialog_->input_command, controller().getCommand().c_str());
88 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
90 int const line = fl_get_browser(dialog_->browser_formats);
91 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
92 return ButtonPolicy::SMI_INVALID;
94 string cmd = getStringFromInput(dialog_->input_command);
95 cmd = strip(frontStrip(cmd));
97 return ButtonPolicy::SMI_INVALID;
99 return ButtonPolicy::SMI_VALID;
103 void FormSendto::apply()
105 int const line = fl_get_browser(dialog_->browser_formats);
106 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
109 string const cmd = getStringFromInput(dialog_->input_command);
111 controller().setFormat(all_formats_[line-1]);
112 controller().setCommand(cmd);