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 #include "support/lstrings.h"
27 typedef FormCB<ControlExternal, FormDB<FD_form_external> > base_class;
29 FormExternal::FormExternal(ControlExternal & c)
30 : base_class(c, _("Edit external file"))
34 void FormExternal::apply()
36 controller().params().filename =
37 fl_get_input(dialog_->input_filename);
38 controller().params().parameters =
39 fl_get_input(dialog_->input_parameters);
41 int const choice = fl_get_choice(dialog_->choice_template);
42 controller().params().templ = controller().getTemplate(choice);
46 void FormExternal::build()
48 dialog_.reset(build_external());
51 " " + getStringFromVector(controller().getTemplates(), " | ") + " ";
52 fl_addto_choice(dialog_->choice_template, choice.c_str());
54 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
55 fl_set_input_return (dialog_->input_parameters, FL_RETURN_CHANGED);
57 setPrehandler(dialog_->input_filename);
58 setPrehandler(dialog_->input_parameters);
60 bc().setOK(dialog_->button_ok);
61 bc().setApply(dialog_->button_apply);
62 bc().setCancel(dialog_->button_close);
64 bc().addReadOnly(dialog_->input_filename);
65 bc().addReadOnly(dialog_->button_filenamebrowse);
66 bc().addReadOnly(dialog_->input_parameters);
70 void FormExternal::update()
72 InsetExternal::Params const & params = controller().params();
74 fl_set_input(dialog_->input_filename, params.filename.c_str());
75 fl_set_input(dialog_->input_parameters, params.parameters.c_str());
77 int const ID = controller().getTemplateNumber(params.templ.lyxName);
79 setEnabled(dialog_->choice_template, true);
80 fl_set_choice(dialog_->choice_template, ID+1);
82 setEnabled(dialog_->choice_template, false);
88 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
90 if (ob == dialog_->choice_template) {
92 // set to the chosen template
93 int const choice = fl_get_choice(dialog_->choice_template);
94 controller().params().templ = controller().getTemplate(choice);
98 } else if (ob == dialog_->button_filenamebrowse) {
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());
104 } else if (ob == dialog_->button_edit) {
105 controller().editExternal();
107 } else if (ob == dialog_->button_view) {
108 controller().viewExternal();
110 } else if (ob == dialog_->button_update) {
111 controller().updateExternal();
114 return ButtonPolicy::SMI_VALID;
118 void FormExternal::updateComboChange()
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);
126 bool const enabled = (!controller().params().templ.automaticProduction);
127 setEnabled(dialog_->button_update, enabled);