3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Asger Alstrup
7 * \author John Levon, moz@compsoc.man.ac.uk
8 * \author Angus Leeming, a.leeming@ic.ac.uk
14 #pragma implementation
18 #include "ControlExternal.h"
19 #include "FormExternal.h"
20 #include "form_external.h"
22 #include "xforms_helpers.h"
23 #include "helper_funcs.h"
25 typedef FormCB<ControlExternal, FormDB<FD_form_external> > base_class;
27 FormExternal::FormExternal(ControlExternal & c)
28 : base_class(c, _("Edit external file"))
32 void FormExternal::apply()
34 controller().params().filename =
35 fl_get_input(dialog_->input_filename);
36 controller().params().parameters =
37 fl_get_input(dialog_->input_parameters);
39 int const choice = fl_get_choice(dialog_->choice_template);
40 controller().params().templ = controller().getTemplate(choice);
44 void FormExternal::build()
46 dialog_.reset(build_external());
49 " " + getStringFromVector(controller().getTemplates(), " | ") + " ";
50 fl_addto_choice(dialog_->choice_template, choice.c_str());
52 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
53 fl_set_input_return (dialog_->input_parameters, FL_RETURN_CHANGED);
55 setPrehandler(dialog_->input_filename);
56 setPrehandler(dialog_->input_parameters);
58 bc().setOK(dialog_->button_ok);
59 bc().setApply(dialog_->button_apply);
60 bc().setCancel(dialog_->button_close);
62 bc().addReadOnly(dialog_->input_filename);
63 bc().addReadOnly(dialog_->button_filenamebrowse);
64 bc().addReadOnly(dialog_->input_parameters);
68 void FormExternal::update()
70 InsetExternal::Params const & params = controller().params();
72 fl_set_input(dialog_->input_filename, params.filename.c_str());
73 fl_set_input(dialog_->input_parameters, params.parameters.c_str());
75 int const ID = controller().getTemplateNumber(params.templ.lyxName);
77 setEnabled(dialog_->choice_template, true);
78 fl_set_choice(dialog_->choice_template, ID+1);
80 setEnabled(dialog_->choice_template, false);
86 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
88 if (ob == dialog_->choice_template) {
90 // set to the chosen template
91 int const choice = fl_get_choice(dialog_->choice_template);
92 controller().params().templ = controller().getTemplate(choice);
96 } else if (ob == dialog_->button_filenamebrowse) {
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());
102 } else if (ob == dialog_->button_edit) {
103 controller().editExternal();
105 } else if (ob == dialog_->button_view) {
106 controller().viewExternal();
108 } else if (ob == dialog_->button_update) {
109 controller().updateExternal();
112 return ButtonPolicy::SMI_VALID;
116 void FormExternal::updateComboChange()
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);
124 bool const enabled = (!controller().params().templ.automaticProduction);
125 setEnabled(dialog_->button_update, enabled);