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"
36 typedef FormController<ControlSendto, FormView<FD_sendto> > base_class;
38 FormSendto::FormSendto(Dialog & parent)
39 : base_class(parent, _("Send document to command"))
43 void FormSendto::build()
45 dialog_.reset(build_sendto(this));
47 fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
48 setPrehandler(dialog_->input_command);
50 // Manage the ok, apply, restore and cancel/close buttons
51 bcview().setOK(dialog_->button_ok);
52 bcview().setApply(dialog_->button_apply);
53 bcview().setCancel(dialog_->button_close);
55 // Set up the tooltip mechanism
56 string str = _("Export the buffer to this format before running the command below on it.");
57 tooltips().init(dialog_->browser_formats, str);
59 str = _("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
60 tooltips().init(dialog_->input_command, str);
64 void FormSendto::update()
66 all_formats_ = controller().allFormats();
68 // Check whether the current contents of the browser will be
69 // changed by loading the contents of formats
71 keys.resize(all_formats_.size());
73 vector<string>::iterator result = keys.begin();
74 vector<Format const *>::const_iterator it = all_formats_.begin();
75 vector<Format const *>::const_iterator end = all_formats_.end();
76 for (; it != end; ++it, ++result) {
77 *result = (*it)->prettyname();
80 vector<string> const browser_keys =
81 getVector(dialog_->browser_formats);
83 if (browser_keys == keys)
87 fl_clear_browser(dialog_->browser_formats);
89 for (vector<string>::const_iterator it = keys.begin();
90 it < keys.end(); ++it) {
91 fl_add_browser_line(dialog_->browser_formats, it->c_str());
94 fl_set_input(dialog_->input_command, controller().getCommand().c_str());
98 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
100 int const line = fl_get_browser(dialog_->browser_formats);
101 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
102 return ButtonPolicy::SMI_INVALID;
104 string cmd = getString(dialog_->input_command);
107 return ButtonPolicy::SMI_INVALID;
109 return ButtonPolicy::SMI_VALID;
113 void FormSendto::apply()
115 int const line = fl_get_browser(dialog_->browser_formats);
116 if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
119 string const cmd = getString(dialog_->input_command);
121 controller().setFormat(all_formats_[line-1]);
122 controller().setCommand(cmd);
125 } // namespace frontend