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 namespace lyx::support;
32 typedef FormCB<ControlSendto, FormDB<FD_sendto> > base_class;
34 FormSendto::FormSendto()
35 : base_class(_("Send document to command"))
39 void FormSendto::build()
41 dialog_.reset(build_sendto(this));
43 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
44 setPrehandler(dialog_->input_command);
46 // Manage the ok, apply, restore and cancel/close buttons
47 bcview().setOK(dialog_->button_ok);
48 bcview().setApply(dialog_->button_apply);
49 bcview().setCancel(dialog_->button_close);
51 // Set up the tooltip mechanism
52 string str = _("Export the buffer to this format before running the command below on it.");
53 tooltips().init(dialog_->browser_formats, str);
55 str = _("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
56 tooltips().init(dialog_->input_command, str);
60 void FormSendto::update()
62 all_formats_ = controller().allFormats();
64 // Check whether the current contents of the browser will be
65 // changed by loading the contents of formats
67 keys.resize(all_formats_.size());
69 vector<string>::iterator result = keys.begin();
70 vector<Format const *>::const_iterator it = all_formats_.begin();
71 vector<Format const *>::const_iterator end = all_formats_.end();
72 for (; it != end; ++it, ++result) {
73 *result = (*it)->prettyname();
76 vector<string> const browser_keys =
77 getVector(dialog_->browser_formats);
79 if (browser_keys == keys)
83 fl_clear_browser(dialog_->browser_formats);
85 for (vector<string>::const_iterator it = keys.begin();
86 it < keys.end(); ++it) {
87 fl_add_browser_line(dialog_->browser_formats, it->c_str());
90 fl_set_input(dialog_->input_command, controller().getCommand().c_str());
94 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
96 int const line = fl_get_browser(dialog_->browser_formats);
97 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
98 return ButtonPolicy::SMI_INVALID;
100 string cmd = getString(dialog_->input_command);
103 return ButtonPolicy::SMI_INVALID;
105 return ButtonPolicy::SMI_VALID;
109 void FormSendto::apply()
111 int const line = fl_get_browser(dialog_->browser_formats);
112 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
115 string const cmd = getString(dialog_->input_command);
117 controller().setFormat(all_formats_[line-1]);
118 controller().setCommand(cmd);