]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormSendto.C
shared-4.diff. Gui independant config.h
[lyx.git] / src / frontends / xforms / FormSendto.C
1 /**
2  * \file FormSendto.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13
14 #include "FormSendto.h"
15 #include "forms/form_sendto.h"
16 #include "ControlSendto.h"
17 #include "xformsBC.h"
18 #include "Tooltips.h"
19 #include "xforms_helpers.h"
20 #include "format.h"
21 #include "gettext.h"
22 #include "lyx_forms.h"
23
24 using std::vector;
25
26 typedef FormCB<ControlSendto, FormDB<FD_sendto> > base_class;
27
28 FormSendto::FormSendto()
29         : base_class(_("Send document to command"))
30 {}
31
32
33 void FormSendto::build()
34 {
35         dialog_.reset(build_sendto(this));
36
37         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
38         setPrehandler(dialog_->input_command);
39
40         // Manage the ok, apply, restore and cancel/close buttons
41         bcview().setOK(dialog_->button_ok);
42         bcview().setApply(dialog_->button_apply);
43         bcview().setCancel(dialog_->button_close);
44
45         // Set up the tooltip mechanism
46         string str = _("Export the buffer to this format before running the command below on it.");
47         tooltips().init(dialog_->browser_formats, str);
48
49         str = _("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
50         tooltips().init(dialog_->input_command, str);
51 }
52
53
54 void FormSendto::update()
55 {
56         all_formats_ = controller().allFormats();
57
58         // Check whether the current contents of the browser will be
59         // changed by loading the contents of formats
60         vector<string> keys;
61         keys.resize(all_formats_.size());
62
63         vector<string>::iterator result = keys.begin();
64         vector<Format const *>::const_iterator it  = all_formats_.begin();
65         vector<Format const *>::const_iterator end = all_formats_.end();
66         for (; it != end; ++it, ++result) {
67                 *result = (*it)->prettyname();
68         }
69
70         vector<string> const browser_keys =
71                 getVector(dialog_->browser_formats);
72
73         if (browser_keys == keys)
74                 return;
75
76         // Reload the browser
77         fl_clear_browser(dialog_->browser_formats);
78
79         for (vector<string>::const_iterator it = keys.begin();
80              it < keys.end(); ++it) {
81                 fl_add_browser_line(dialog_->browser_formats, it->c_str());
82         }
83
84         fl_set_input(dialog_->input_command, controller().getCommand().c_str());
85 }
86
87
88 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
89 {
90         int const line = fl_get_browser(dialog_->browser_formats);
91         if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
92                 return ButtonPolicy::SMI_INVALID;
93
94         string cmd = getString(dialog_->input_command);
95         cmd = trim(cmd);
96         if (cmd.empty())
97                 return ButtonPolicy::SMI_INVALID;
98
99         return ButtonPolicy::SMI_VALID;
100 }
101
102
103 void FormSendto::apply()
104 {
105         int const line = fl_get_browser(dialog_->browser_formats);
106         if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
107                 return;
108
109         string const cmd = getString(dialog_->input_command);
110
111         controller().setFormat(all_formats_[line-1]);
112         controller().setCommand(cmd);
113 }