]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormSendto.C
9c6e7aaf790b3346487b9e1516371010ee4fd0ef
[lyx.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 "Tooltips.h"
20 #include "xforms_helpers.h"
21 #include "converter.h"
22 #include "gettext.h"
23
24 using std::vector;
25
26 typedef FormCB<ControlSendto, FormDB<FD_form_sendto> > base_class;
27
28 FormSendto::FormSendto(ControlSendto & c)
29         : base_class(c, _("Send document to command"))
30 {}
31
32
33 void FormSendto::build()
34 {
35         dialog_.reset(build_sendto());
36
37         fl_set_input_return(dialog_->input_command, FL_RETURN_CHANGED);
38
39         // Manage the ok, apply, restore and cancel/close buttons
40         bc().setOK(dialog_->button_ok);
41         bc().setApply(dialog_->button_apply);
42         bc().setCancel(dialog_->button_cancel);
43
44         // Set up the tooltip mechanism
45         string str = N_("Export the buffer to this format before running the command below on it.");
46         tooltips().initTooltip(dialog_->browser_formats, str);
47
48         str = N_("Run this command on the buffer exported to the chosen format. $$FName will be replaced by the name of this file.");
49         tooltips().initTooltip(dialog_->input_command, str);
50 }
51
52
53 void FormSendto::update()
54 {
55         all_formats_ = controller().allFormats();
56
57         // Check whether the current contents of the browser will be
58         // changed by loading the contents of formats
59         vector<string> keys;
60         keys.resize(all_formats_.size());
61
62         vector<string>::iterator result = keys.begin();
63         vector<Format const *>::const_iterator it  = all_formats_.begin();
64         vector<Format const *>::const_iterator end = all_formats_.end();
65         for (; it != end; ++it, ++result) {
66                 *result = (*it)->prettyname();
67         }
68
69         vector<string> const browser_keys =
70                 getVectorFromBrowser(dialog_->browser_formats);
71
72         if (browser_keys == keys)
73                 return;
74
75         // Reload the browser
76         fl_clear_browser(dialog_->browser_formats);
77
78         for (vector<string>::const_iterator it = keys.begin();
79              it < keys.end(); ++it) {
80                 fl_add_browser_line(dialog_->browser_formats, it->c_str());
81         }
82
83         fl_set_input(dialog_->input_command, controller().getCommand().c_str());
84 }
85
86
87 ButtonPolicy::SMInput FormSendto::input(FL_OBJECT *, long)
88 {
89         int const line = fl_get_browser(dialog_->browser_formats);
90         if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
91                 return ButtonPolicy::SMI_INVALID;
92
93         string cmd = getStringFromInput(dialog_->input_command);
94         cmd = strip(frontStrip(cmd));
95         if (cmd.empty())
96                 return ButtonPolicy::SMI_INVALID;
97
98         return ButtonPolicy::SMI_VALID;
99 }
100
101
102 void FormSendto::apply()
103 {
104         int const line = fl_get_browser(dialog_->browser_formats);
105         if (line < 1 || line > fl_get_browser_maxline(dialog_->browser_formats))
106                 return;
107
108         string const cmd = getStringFromInput(dialog_->input_command);
109
110         controller().setFormat(all_formats_[line-1]);
111         controller().setCommand(cmd);
112 }