3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS
16 #pragma implementation
20 #include "ControlExternal.h"
21 #include "FormExternal.h"
22 #include "forms/form_external.h"
24 #include "xforms_helpers.h"
25 #include "helper_funcs.h"
27 #include "support/lstrings.h"
28 #include FORMS_H_LOCATION
30 typedef FormCB<ControlExternal, FormDB<FD_external> > base_class;
32 FormExternal::FormExternal()
33 : base_class(_("Edit external file"))
37 void FormExternal::apply()
39 controller().params().filename =
40 fl_get_input(dialog_->input_filename);
41 controller().params().parameters =
42 fl_get_input(dialog_->input_parameters);
44 int const choice = fl_get_choice(dialog_->choice_template) - 1;
45 controller().params().templ = controller().getTemplate(choice);
49 void FormExternal::build()
51 dialog_.reset(build_external(this));
54 ' ' + getStringFromVector(controller().getTemplates(), " | ") + ' ';
55 fl_addto_choice(dialog_->choice_template, choice.c_str());
57 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
58 fl_set_input_return (dialog_->input_parameters, FL_RETURN_CHANGED);
60 setPrehandler(dialog_->input_filename);
61 setPrehandler(dialog_->input_parameters);
63 bc().setOK(dialog_->button_ok);
64 bc().setApply(dialog_->button_apply);
65 bc().setCancel(dialog_->button_close);
67 bc().addReadOnly(dialog_->input_filename);
68 bc().addReadOnly(dialog_->button_filenamebrowse);
69 bc().addReadOnly(dialog_->input_parameters);
73 void FormExternal::update()
75 InsetExternal::Params const & params = controller().params();
77 fl_set_input(dialog_->input_filename, params.filename.c_str());
78 fl_set_input(dialog_->input_parameters, params.parameters.c_str());
80 int const ID = controller().getTemplateNumber(params.templ.lyxName);
82 setEnabled(dialog_->choice_template, true);
83 fl_set_choice(dialog_->choice_template, ID+1);
85 setEnabled(dialog_->choice_template, false);
91 ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
93 if (ob == dialog_->choice_template) {
95 // set to the chosen template
96 int const choice = fl_get_choice(dialog_->choice_template) - 1;
97 controller().params().templ = controller().getTemplate(choice);
101 } else if (ob == dialog_->button_filenamebrowse) {
103 string const in_name = fl_get_input(dialog_->input_filename);
104 string const out_name = controller().Browse(in_name);
105 fl_set_input(dialog_->input_filename, out_name.c_str());
107 } else if (ob == dialog_->button_edit) {
108 controller().editExternal();
110 } else if (ob == dialog_->button_view) {
111 controller().viewExternal();
113 } else if (ob == dialog_->button_update) {
114 controller().updateExternal();
117 return ButtonPolicy::SMI_VALID;
121 void FormExternal::updateComboChange()
123 // Update the help text
124 fl_clear_browser(dialog_->browser_helptext);
125 fl_addto_browser(dialog_->browser_helptext,
126 controller().params().templ.helpText.c_str());
127 fl_set_browser_topline(dialog_->browser_helptext, 0);
129 bool const enabled = (!controller().params().templ.automaticProduction);
130 setEnabled(dialog_->button_update, enabled);