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());
51 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
53 bc().setOK(dialog_->button_ok);
54 bc().setApply(dialog_->button_apply);
55 bc().setCancel(dialog_->button_cancel);
57 bc().addReadOnly(dialog_->input_filename);
58 bc().addReadOnly(dialog_->button_filenamebrowse);
59 bc().addReadOnly(dialog_->input_parameters);
63 void FormExternal::update()
65 InsetExternal::Params const & params = controller().params();
67 fl_set_input(dialog_->input_filename, params.filename.c_str());
68 fl_set_input(dialog_->input_parameters, params.parameters.c_str());
70 int const ID = controller().getTemplateNumber(params.templ.lyxName);
72 setEnabled(dialog_->choice_template, true);
73 fl_set_choice(dialog_->choice_template, ID+1);
75 setEnabled(dialog_->choice_template, false);
81 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
83 if (ob == dialog_->choice_template) {
85 // set to the chosen template
86 int const choice = fl_get_choice(dialog_->choice_template);
87 controller().params().templ = controller().getTemplate(choice);
91 } else if (ob == dialog_->button_filenamebrowse) {
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());
97 } else if (ob == dialog_->button_edit) {
98 controller().editExternal();
100 } else if (ob == dialog_->button_view) {
101 controller().viewExternal();
103 } else if (ob == dialog_->button_update) {
104 controller().updateExternal();
107 return ButtonPolicy::SMI_VALID;
111 void FormExternal::updateComboChange()
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);
119 bool const enabled = (!controller().params().templ.automaticProduction);
120 setEnabled(dialog_->button_update, enabled);