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