3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "FormSendto.h"
18 #include "forms/form_sendto.h"
19 #include "ControlSendto.h"
22 #include "xforms_helpers.h"
23 #include "converter.h"
25 #include FORMS_H_LOCATION
29 typedef FormCB<ControlSendto, FormDB<FD_sendto> > base_class;
31 FormSendto::FormSendto()
32 : base_class(_("Send document to command"))
36 void FormSendto::build()
38 dialog_.reset(build_sendto(this));
40 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
41 setPrehandler(dialog_->input_command);
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);
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);
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);
57 void FormSendto::update()
59 all_formats_ = controller().allFormats();
61 // Check whether the current contents of the browser will be
62 // changed by loading the contents of formats
64 keys.resize(all_formats_.size());
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();
73 vector<string> const browser_keys =
74 getVector(dialog_->browser_formats);
76 if (browser_keys == keys)
80 fl_clear_browser(dialog_->browser_formats);
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());
87 fl_set_input(dialog_->input_command, controller().getCommand().c_str());
91 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
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 = getString(dialog_->input_command);
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 = getString(dialog_->input_command);
114 controller().setFormat(all_formats_[line-1]);
115 controller().setCommand(cmd);