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.
13 #include "FormSendto.h"
14 #include "ControlSendto.h"
15 #include "forms/form_sendto.h"
18 #include "xforms_helpers.h"
23 #include "support/lstrings.h"
25 #include "lyx_forms.h"
27 using lyx::support::trim;
33 typedef FormController<ControlSendto, FormView<FD_sendto> > base_class;
35 FormSendto::FormSendto(Dialog & parent)
36 : base_class(parent, _("Send document to command"))
40 void FormSendto::build()
42 dialog_.reset(build_sendto(this));
44 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
45 setPrehandler(dialog_->input_command);
47 // Manage the ok, apply, restore and cancel/close buttons
48 bcview().setOK(dialog_->button_ok);
49 bcview().setApply(dialog_->button_apply);
50 bcview().setCancel(dialog_->button_close);
52 // Set up the tooltip mechanism
53 string str = _("Export the buffer to this format before running the command below on it.");
54 tooltips().init(dialog_->browser_formats, str);
56 str = _("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
57 tooltips().init(dialog_->input_command, str);
61 void FormSendto::update()
63 all_formats_ = controller().allFormats();
65 // Check whether the current contents of the browser will be
66 // changed by loading the contents of formats
68 keys.resize(all_formats_.size());
70 vector<string>::iterator result = keys.begin();
71 vector<Format const *>::const_iterator it = all_formats_.begin();
72 vector<Format const *>::const_iterator end = all_formats_.end();
73 for (; it != end; ++it, ++result) {
74 *result = (*it)->prettyname();
77 vector<string> const browser_keys =
78 getVector(dialog_->browser_formats);
80 if (browser_keys == keys)
84 fl_clear_browser(dialog_->browser_formats);
86 for (vector<string>::const_iterator it = keys.begin();
87 it < keys.end(); ++it) {
88 fl_add_browser_line(dialog_->browser_formats, it->c_str());
91 fl_set_input(dialog_->input_command, controller().getCommand().c_str());
95 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
97 int const line = fl_get_browser(dialog_->browser_formats);
98 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
99 return ButtonPolicy::SMI_INVALID;
101 string cmd = getString(dialog_->input_command);
104 return ButtonPolicy::SMI_INVALID;
106 return ButtonPolicy::SMI_VALID;
110 void FormSendto::apply()
112 int const line = fl_get_browser(dialog_->browser_formats);
113 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
116 string const cmd = getString(dialog_->input_command);
118 controller().setFormat(all_formats_[line-1]);
119 controller().setCommand(cmd);