]> git.lyx.org Git - features.git/blob - src/frontends/xforms/FormSendto.C
fa4a9e884516c56db2f6acb487fd5c570bc94285
[features.git] / src / frontends / xforms / FormSendto.C
1 /*
2  * \file FormSendto.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Angus Leeming <a.leeming@ic.ac.uk>
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "FormSendto.h"
16 #include "form_sendto.h"
17 #include "ControlSendto.h"
18 #include "xformsBC.h"
19 #include "xforms_helpers.h"
20 #include "converter.h"
21 #include "gettext.h"
22
23 using std::vector;
24
25 typedef FormCB<ControlSendto, FormDB<FD_form_sendto> > base_class;
26
27 FormSendto::FormSendto(ControlSendto & c)
28         : base_class(c, _("Send document to command"))
29 {}
30
31
32 void FormSendto::build()
33 {
34         dialog_.reset(build_sendto());
35
36         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
37
38         // The help choice
39         fillTooltipChoice(dialog_->choice_help);
40
41         // Set up the tooltip mechanism
42         setTooltipHandler(dialog_->browser_formats);
43         setTooltipHandler(dialog_->input_command);
44
45         // Manage the ok, apply, restore and cancel/close buttons
46         bc().setOK(dialog_->button_ok);
47         bc().setApply(dialog_->button_apply);
48         bc().setCancel(dialog_->button_cancel);
49 }
50
51
52 void FormSendto::update()
53 {
54         all_formats_ = controller().allFormats();
55
56         // Check whether the current contents of the browser will be
57         // changed by loading the contents of formats
58         vector<string> keys;
59         keys.resize(all_formats_.size());
60
61         vector<string>::iterator result = keys.begin();
62         vector<Format const *>::const_iterator it  = all_formats_.begin();
63         vector<Format const *>::const_iterator end = all_formats_.end();
64         for (; it != end; ++it, ++result) {
65                 *result = (*it)->prettyname();
66         }
67         
68         vector<string> const browser_keys =
69                 getVectorFromBrowser(dialog_->browser_formats);
70
71         if (browser_keys == keys)
72                 return;
73
74         // Reload the browser
75         fl_clear_browser(dialog_->browser_formats);
76
77         for (vector<string>::const_iterator it = keys.begin();
78              it < keys.end(); ++it) {
79                 fl_add_browser_line(dialog_->browser_formats, it->c_str());
80         }
81
82         fl_set_input(dialog_->input_command, controller().getCommand().c_str());
83 }
84
85
86 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT * ob, long)
87 {
88         if (ob == dialog_->choice_help) {
89                 setTooltipLevel(dialog_->choice_help);
90                 return ButtonPolicy::SMI_NOOP;
91         }
92
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;
96
97         string cmd = getStringFromInput(dialog_->input_command);
98         cmd = strip(frontStrip(cmd));
99         if (cmd.empty())
100                 return ButtonPolicy::SMI_INVALID;
101
102         return ButtonPolicy::SMI_VALID;
103 }
104
105
106 void FormSendto::apply()
107 {
108         int const line = fl_get_browser(dialog_->browser_formats);
109         if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
110                 return;
111
112         string const cmd = getStringFromInput(dialog_->input_command);
113
114         controller().setFormat(all_formats_[line-1]);
115         controller().setCommand(cmd);
116 }
117
118
119 string const FormSendto::getVerboseTooltip(FL_OBJECT const * ob) const
120 {
121         string str;
122
123         if (ob == dialog_->browser_formats) {
124                 str = N_("Export the buffer to this format before running the command below on it.");
125                 
126         } else if (ob == dialog_->input_command) {
127                 str = N_("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
128         }
129         
130         return str;
131 }