lyx_mirror/src/frontends/xforms/FormExternal.C

130 lines
3.4 KiB
C++
Raw Normal View History

/**
* \file FormExternal.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Asger Alstrup
* \author John Levon
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#include "xformsBC.h"
#include "ControlExternal.h"
#include "FormExternal.h"
#include "forms/form_external.h"
#include "gettext.h"
#include "xforms_helpers.h"
#include "helper_funcs.h"
#include "support/lstrings.h"
#include "lyx_forms.h"
typedef FormController<ControlExternal, FormView<FD_external> > base_class;
FormExternal::FormExternal(Dialog & parent)
: base_class(parent, _("External Material"))
{}
void FormExternal::apply()
{
InsetExternal::Params params = controller().params();
params.filename = fl_get_input(dialog_->input_filename);
params.parameters = fl_get_input(dialog_->input_parameters);
int const choice = fl_get_choice(dialog_->choice_template) - 1;
params.templ = controller().getTemplate(choice);
controller().setParams(params);
}
void FormExternal::build()
{
dialog_.reset(build_external(this));
string const choice =
' ' + getStringFromVector(controller().getTemplates(), " | ") + ' ';
fl_addto_choice(dialog_->choice_template, choice.c_str());
fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
fl_set_input_return (dialog_->input_parameters, FL_RETURN_CHANGED);
setPrehandler(dialog_->input_filename);
setPrehandler(dialog_->input_parameters);
bcview().setOK(dialog_->button_ok);
bcview().setApply(dialog_->button_apply);
bcview().setCancel(dialog_->button_close);
bcview().addReadOnly(dialog_->input_filename);
bcview().addReadOnly(dialog_->button_filenamebrowse);
bcview().addReadOnly(dialog_->input_parameters);
}
void FormExternal::update()
{
InsetExternal::Params const & params = controller().params();
fl_set_input(dialog_->input_filename, params.filename.c_str());
fl_set_input(dialog_->input_parameters, params.parameters.c_str());
int ID = controller().getTemplateNumber(params.templ.lyxName);
if (ID < 0) ID = 0;
fl_set_choice(dialog_->choice_template, ID+1);
updateComboChange();
}
ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
{
if (ob == dialog_->choice_template) {
// set to the chosen template
int const choice = fl_get_choice(dialog_->choice_template) - 1;
InsetExternal::Params params = controller().params();
params.templ = controller().getTemplate(choice);
controller().setParams(params);
updateComboChange();
} else if (ob == dialog_->button_filenamebrowse) {
string const in_name = fl_get_input(dialog_->input_filename);
string const out_name = controller().Browse(in_name);
fl_set_input(dialog_->input_filename, out_name.c_str());
} else if (ob == dialog_->button_edit) {
controller().editExternal();
} else if (ob == dialog_->button_view) {
controller().viewExternal();
} else if (ob == dialog_->button_update) {
controller().updateExternal();
}
return ButtonPolicy::SMI_VALID;
}
void FormExternal::updateComboChange()
{
// Update the help text
fl_clear_browser(dialog_->browser_helptext);
fl_addto_browser(dialog_->browser_helptext,
controller().params().templ.helpText.c_str());
fl_set_browser_topline(dialog_->browser_helptext, 0);
bool const enabled = (!controller().params().templ.automaticProduction);
setEnabled(dialog_->button_update, enabled);
}