]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormExternal.C
iThe cursor now behaves properly in the dialogs...
[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 typedef FormCB<ControlExternal, FormDB<FD_form_external> > base_class;
26
27 FormExternal::FormExternal(ControlExternal & c)
28         : base_class(c, _("Edit external file"))
29 {}
30
31
32 void FormExternal::apply()
33 {
34         controller().params().filename =
35                 fl_get_input(dialog_->input_filename);
36         controller().params().parameters =
37                 fl_get_input(dialog_->input_parameters);
38
39         int const choice = fl_get_choice(dialog_->choice_template);
40         controller().params().templ = controller().getTemplate(choice);
41 }
42
43
44 void FormExternal::build()
45 {
46         dialog_.reset(build_external());
47
48         string const choice =
49             " " + getStringFromVector(controller().getTemplates(), " | ") + " ";
50         fl_addto_choice(dialog_->choice_template, choice.c_str());
51
52         fl_set_input_return (dialog_->input_filename,  FL_RETURN_CHANGED);
53         fl_set_input_return (dialog_->input_parameters, FL_RETURN_CHANGED);
54
55         setPrehandler(dialog_->input_filename);
56         setPrehandler(dialog_->input_parameters);
57
58         bc().setOK(dialog_->button_ok);
59         bc().setApply(dialog_->button_apply);
60         bc().setCancel(dialog_->button_close);
61
62         bc().addReadOnly(dialog_->input_filename);
63         bc().addReadOnly(dialog_->button_filenamebrowse);
64         bc().addReadOnly(dialog_->input_parameters);
65 }
66
67
68 void FormExternal::update()
69 {
70         InsetExternal::Params const & params = controller().params();
71
72         fl_set_input(dialog_->input_filename, params.filename.c_str());
73         fl_set_input(dialog_->input_parameters, params.parameters.c_str());
74
75         int const ID = controller().getTemplateNumber(params.templ.lyxName);
76         if (ID >= 0) {
77                 setEnabled(dialog_->choice_template, true);
78                 fl_set_choice(dialog_->choice_template, ID+1);
79         } else
80                 setEnabled(dialog_->choice_template, false);
81
82         updateComboChange();
83 }
84
85
86 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
87 {
88         if (ob == dialog_->choice_template) {
89
90                 // set to the chosen template
91                 int const choice = fl_get_choice(dialog_->choice_template);
92                 controller().params().templ = controller().getTemplate(choice);
93
94                 updateComboChange();
95
96         } else if (ob == dialog_->button_filenamebrowse) {
97
98                 string const in_name  = fl_get_input(dialog_->input_filename);
99                 string const out_name = controller().Browse(in_name);
100                 fl_set_input(dialog_->input_filename, out_name.c_str());
101
102         } else if (ob == dialog_->button_edit) {
103                 controller().editExternal();
104
105         } else if (ob == dialog_->button_view) {
106                 controller().viewExternal();
107
108         } else if (ob == dialog_->button_update) {
109                 controller().updateExternal();
110         }
111
112         return ButtonPolicy::SMI_VALID;
113 }
114
115
116 void FormExternal::updateComboChange()
117 {
118         // Update the help text
119         fl_clear_browser(dialog_->browser_helptext);
120         fl_addto_browser(dialog_->browser_helptext,
121                          controller().params().templ.helpText.c_str());
122         fl_set_browser_topline(dialog_->browser_helptext, 0);
123
124         bool const enabled = (!controller().params().templ.automaticProduction);
125         setEnabled(dialog_->button_update, enabled);
126 }