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"
19 #include "xforms_helpers.h"
20 #include "converter.h"
25 typedef FormCB<ControlSendto, FormDB<FD_form_sendto> > base_class;
27 FormSendto::FormSendto(ControlSendto & c)
28 : base_class(c, _("Send document to command"))
32 void FormSendto::build()
34 dialog_.reset(build_sendto());
36 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
39 fillTooltipChoice(dialog_->choice_help);
41 // Set up the tooltip mechanism
42 setTooltipHandler(dialog_->browser_formats);
43 setTooltipHandler(dialog_->input_command);
45 // Manage the ok, apply, restore and cancel/close buttons
46 bc().setOK(dialog_->button_ok);
47 bc().setApply(dialog_->button_apply);
48 bc().setCancel(dialog_->button_cancel);
52 void FormSendto::update()
54 all_formats_ = controller().allFormats();
56 // Check whether the current contents of the browser will be
57 // changed by loading the contents of formats
59 keys.resize(all_formats_.size());
61 vector<string>::iterator result = keys.begin();
62 vector<Format const *>::const_iterator it = all_formats_.begin();
63 vector<Format const *>::const_iterator end = all_formats_.end();
64 for (; it != end; ++it, ++result) {
65 *result = (*it)->prettyname();
68 vector<string> const browser_keys =
69 getVectorFromBrowser(dialog_->browser_formats);
71 if (browser_keys == keys)
75 fl_clear_browser(dialog_->browser_formats);
77 for (vector<string>::const_iterator it = keys.begin();
78 it < keys.end(); ++it) {
79 fl_add_browser_line(dialog_->browser_formats, it->c_str());
82 fl_set_input(dialog_->input_command, controller().getCommand().c_str());
86 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT * ob, long)
88 if (ob == dialog_->choice_help) {
89 setTooltipLevel(dialog_->choice_help);
90 return ButtonPolicy::SMI_NOOP;
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;
97 string cmd = getStringFromInput(dialog_->input_command);
98 cmd = strip(frontStrip(cmd));
100 return ButtonPolicy::SMI_INVALID;
102 return ButtonPolicy::SMI_VALID;
106 void FormSendto::apply()
108 int const line = fl_get_browser(dialog_->browser_formats);
109 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
112 string const cmd = getStringFromInput(dialog_->input_command);
114 controller().setFormat(all_formats_[line-1]);
115 controller().setCommand(cmd);
119 string const FormSendto::getVerboseTooltip(FL_OBJECT const * ob) const
123 if (ob == dialog_->browser_formats) {
124 str = N_("Export the buffer to this format before running the command below on it.");
126 } else if (ob == dialog_->input_command) {
127 str = N_("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");