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