]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormExternal.C
Clean-up yesterday's code-splurge and sort the translated language names.
[lyx.git] / src / frontends / xforms / FormExternal.C
1 /**
2  * \file FormExternal.C
3  * Copyright 2000-2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Asger Alstrup
7  * \author John Levon, moz@compsoc.man.ac.uk
8  * \author Angus Leeming, a.leeming@ic.ac.uk
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "xformsBC.h"
18 #include "ControlExternal.h"
19 #include "FormExternal.h"
20 #include "form_external.h"
21 #include "gettext.h"
22 #include "xforms_helpers.h"
23 #include "helper_funcs.h"
24
25 #include "support/lstrings.h"
26
27 typedef FormCB<ControlExternal, FormDB<FD_form_external> > base_class;
28
29 FormExternal::FormExternal(ControlExternal & c)
30         : base_class(c, _("Edit external file"))
31 {}
32
33
34 void FormExternal::apply()
35 {
36         controller().params().filename =
37                 fl_get_input(dialog_->input_filename);
38         controller().params().parameters =
39                 fl_get_input(dialog_->input_parameters);
40
41         int const choice = fl_get_choice(dialog_->choice_template);
42         controller().params().templ = controller().getTemplate(choice);
43 }
44
45
46 void FormExternal::build()
47 {
48         dialog_.reset(build_external());
49
50         string const choice =
51                 " " + getStringFromVector(controller().getTemplates(), " | ") + " ";
52         fl_addto_choice(dialog_->choice_template, choice.c_str());
53
54         fl_set_input_return (dialog_->input_filename,  FL_RETURN_CHANGED);
55         fl_set_input_return (dialog_->input_parameters, FL_RETURN_CHANGED);
56
57         setPrehandler(dialog_->input_filename);
58         setPrehandler(dialog_->input_parameters);
59
60         bc().setOK(dialog_->button_ok);
61         bc().setApply(dialog_->button_apply);
62         bc().setCancel(dialog_->button_close);
63
64         bc().addReadOnly(dialog_->input_filename);
65         bc().addReadOnly(dialog_->button_filenamebrowse);
66         bc().addReadOnly(dialog_->input_parameters);
67 }
68
69
70 void FormExternal::update()
71 {
72         InsetExternal::Params const & params = controller().params();
73
74         fl_set_input(dialog_->input_filename, params.filename.c_str());
75         fl_set_input(dialog_->input_parameters, params.parameters.c_str());
76
77         int const ID = controller().getTemplateNumber(params.templ.lyxName);
78         if (ID >= 0) {
79                 setEnabled(dialog_->choice_template, true);
80                 fl_set_choice(dialog_->choice_template, ID+1);
81         } else
82                 setEnabled(dialog_->choice_template, false);
83
84         updateComboChange();
85 }
86
87
88 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
89 {
90         if (ob == dialog_->choice_template) {
91
92                 // set to the chosen template
93                 int const choice = fl_get_choice(dialog_->choice_template);
94                 controller().params().templ = controller().getTemplate(choice);
95
96                 updateComboChange();
97
98         } else if (ob == dialog_->button_filenamebrowse) {
99
100                 string const in_name  = fl_get_input(dialog_->input_filename);
101                 string const out_name = controller().Browse(in_name);
102                 fl_set_input(dialog_->input_filename, out_name.c_str());
103
104         } else if (ob == dialog_->button_edit) {
105                 controller().editExternal();
106
107         } else if (ob == dialog_->button_view) {
108                 controller().viewExternal();
109
110         } else if (ob == dialog_->button_update) {
111                 controller().updateExternal();
112         }
113
114         return ButtonPolicy::SMI_VALID;
115 }
116
117
118 void FormExternal::updateComboChange()
119 {
120         // Update the help text
121         fl_clear_browser(dialog_->browser_helptext);
122         fl_addto_browser(dialog_->browser_helptext,
123                          controller().params().templ.helpText.c_str());
124         fl_set_browser_topline(dialog_->browser_helptext, 0);
125
126         bool const enabled = (!controller().params().templ.automaticProduction);
127         setEnabled(dialog_->button_update, enabled);
128 }