]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormExternal.C
sourcedoc-friendly files.
[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         fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
52
53         bc().setOK(dialog_->button_ok);
54         bc().setApply(dialog_->button_apply);
55         bc().setCancel(dialog_->button_cancel);
56
57         bc().addReadOnly(dialog_->input_filename);
58         bc().addReadOnly(dialog_->button_filenamebrowse);
59         bc().addReadOnly(dialog_->input_parameters);
60 }
61
62
63 void FormExternal::update()
64 {
65         InsetExternal::Params const & params = controller().params();
66
67         fl_set_input(dialog_->input_filename, params.filename.c_str());
68         fl_set_input(dialog_->input_parameters, params.parameters.c_str());
69
70         int const ID = controller().getTemplateNumber(params.templ.lyxName);
71         if (ID >= 0) {
72                 setEnabled(dialog_->choice_template, true);
73                 fl_set_choice(dialog_->choice_template, ID+1);
74         } else
75                 setEnabled(dialog_->choice_template, false);
76
77         updateComboChange();
78 }
79
80
81 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
82 {
83         if (ob == dialog_->choice_template) {
84
85                 // set to the chosen template
86                 int const choice = fl_get_choice(dialog_->choice_template);
87                 controller().params().templ = controller().getTemplate(choice);
88
89                 updateComboChange();
90
91         } else if (ob == dialog_->button_filenamebrowse) {
92
93                 string const in_name  = fl_get_input(dialog_->input_filename);
94                 string const out_name = controller().Browse(in_name);
95                 fl_set_input(dialog_->input_filename, out_name.c_str());
96
97         } else if (ob == dialog_->button_edit) {
98                 controller().editExternal();
99
100         } else if (ob == dialog_->button_view) {
101                 controller().viewExternal();
102
103         } else if (ob == dialog_->button_update) {
104                 controller().updateExternal();
105         }
106
107         return ButtonPolicy::SMI_VALID;
108 }
109
110
111 void FormExternal::updateComboChange()
112 {
113         // Update the help text
114         fl_clear_browser(dialog_->browser_helptext);
115         fl_addto_browser(dialog_->browser_helptext,
116                          controller().params().templ.helpText.c_str());
117         fl_set_browser_topline(dialog_->browser_helptext, 0);
118
119         bool const enabled = (!controller().params().templ.automaticProduction);
120         setEnabled(dialog_->button_update, enabled);
121 }