1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * ======================================================
10 * \file FormExternal.C
11 * \author Asger Alstrup
13 * \author Angus Leeming, a.leeming@ic.ac.uk
19 #pragma implementation
23 #include "ControlExternal.h"
24 #include "FormExternal.h"
25 #include "form_external.h"
27 #include "xforms_helpers.h"
28 #include "helper_funcs.h"
30 typedef FormCB<ControlExternal, FormDB<FD_form_external> > base_class;
32 FormExternal::FormExternal(ControlExternal & c)
33 : base_class(c, _("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);
45 controller().params().templ = controller().getTemplate(choice);
49 void FormExternal::build()
51 dialog_.reset(build_external());
54 " " + getStringFromVector(controller().getTemplates(), " | ") + " ";
55 fl_addto_choice(dialog_->choice_template, choice.c_str());
56 fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
58 bc().setOK(dialog_->button_ok);
59 bc().setApply(dialog_->button_apply);
60 bc().setCancel(dialog_->button_cancel);
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);