X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FFormInclude.C;h=57bbb468e5fab34ad7f0fc43344aae83e535dec6;hb=37e82a546392d43f787826b85481a11f2a27af15;hp=78f80f27381f7a4cd184062cc0cd94e6522b049e;hpb=58d99b4a97b85a750704cf84c9639b408117271c;p=lyx.git diff --git a/src/frontends/xforms/FormInclude.C b/src/frontends/xforms/FormInclude.C index 78f80f2738..57bbb468e5 100644 --- a/src/frontends/xforms/FormInclude.C +++ b/src/frontends/xforms/FormInclude.C @@ -1,145 +1,191 @@ /** * \file FormInclude.C - * Copyright 2001 the LyX Team - * Read the file COPYING + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * * \author Alejandro Aguilar Sierra - * \author John Levon, moz@compsoc.man.ac.uk - * \author Angus Leeming, a.leeming@.ac.uk + * \author John Levon + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS. */ #include -#include - -#ifdef __GNUG__ -#pragma implementation -#endif -#include "xformsBC.h" -#include "ControlInclude.h" #include "FormInclude.h" -#include "form_include.h" -#include "insets/insetinclude.h" +#include "ControlInclude.h" +#include "forms/form_include.h" + +#include "Tooltips.h" #include "xforms_helpers.h" // setEnabled -#include "support/lstrings.h" // compare +#include "xformsBC.h" + +#include "support/lstrings.h" // strip -typedef FormCB > base_class; +#include "lyx_forms.h" -FormInclude::FormInclude(ControlInclude & c) - : base_class(c, _("Include file")) +using std::string; + +namespace lyx { + +using support::rtrim; + +namespace frontend { + +typedef FormController > base_class; + +FormInclude::FormInclude(Dialog & parent) + : base_class(parent, _("Child Document")) {} void FormInclude::build() { - dialog_.reset(build_include()); + dialog_.reset(build_include(this)); // Manage the ok and cancel buttons - bc().setOK(dialog_->button_ok); - bc().setCancel(dialog_->button_cancel); - bc().refresh(); - - bc().addReadOnly(dialog_->button_browse); - bc().addReadOnly(dialog_->check_verbatim); - bc().addReadOnly(dialog_->check_typeset); - bc().addReadOnly(dialog_->check_useinput); - bc().addReadOnly(dialog_->check_useinclude); + bcview().setOK(dialog_->button_ok); + bcview().setCancel(dialog_->button_close); + + // trigger an input event for cut&paste with middle mouse button. + setPrehandler(dialog_->input_filename); + + fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED); + + // disable for read-only documents + bcview().addReadOnly(dialog_->button_browse); + bcview().addReadOnly(dialog_->radio_useinput); + bcview().addReadOnly(dialog_->radio_useinclude); + bcview().addReadOnly(dialog_->radio_verbatim); + + type_.init(dialog_->radio_useinput, ControlInclude::INPUT); + type_.init(dialog_->radio_useinclude, ControlInclude::INCLUDE); + type_.init(dialog_->radio_verbatim, ControlInclude::VERBATIM); + + // set up the tooltips + string str = _("File name to include."); + tooltips().init(dialog_->input_filename, str); + str = _("Browse directories for file name."); + tooltips().init(dialog_->button_browse, str); + str = _("Use LaTeX \\input."); + tooltips().init(dialog_->radio_useinput, str); + str = _("Use LaTeX \\include."); + tooltips().init(dialog_->radio_useinclude, str); + str = _("Use LaTeX \\verbatiminput."); + tooltips().init(dialog_->radio_verbatim, str); + str = _("Underline spaces in generated output."); + tooltips().init(dialog_->check_visiblespace, str); + str = _("Show LaTeX preview."); + tooltips().init(dialog_->check_preview, str); + str = _("Load the file."); + tooltips().init(dialog_->button_load, str); } void FormInclude::update() { - if (controller().params().noload) { - fl_set_input(dialog_->input_filename, ""); - fl_set_button(dialog_->check_typeset, 0); - fl_set_button(dialog_->check_useinput, 0); - fl_set_button(dialog_->check_useinclude, 1); - fl_set_button(dialog_->check_verbatim, 0); - fl_set_button(dialog_->check_visiblespace, 0); - fl_deactivate_object(dialog_->check_visiblespace); - fl_set_object_lcol(dialog_->check_visiblespace, FL_INACTIVE); - return; - } + string const filename = controller().params().getContents(); + string const cmdname = controller().params().getCmdName(); + bool const preview = static_cast((controller().params().preview())); + + fl_set_input(dialog_->input_filename, filename.c_str()); - fl_set_input(dialog_->input_filename, - controller().params().cparams.getContents().c_str()); + bool const inputCommand = cmdname == "input"; + bool const includeCommand = cmdname == "include"; + bool const verbatimStarCommand = cmdname == "verbatiminput*"; + bool const verbatimCommand = cmdname == "verbatiminput"; - string const cmdname = controller().params().cparams.getCmdName(); + setEnabled(dialog_->check_preview, inputCommand); + fl_set_button(dialog_->check_preview, inputCommand ? preview : 0); - fl_set_button(dialog_->check_typeset, - int(controller().params().noload)); + if (cmdname.empty()) + type_.set(ControlInclude::INPUT); + + if (includeCommand) + type_.set(ControlInclude::INCLUDE); - fl_set_button(dialog_->check_useinput, cmdname == "input"); - fl_set_button(dialog_->check_useinclude, cmdname == "include"); - if (cmdname == "verbatiminput" || cmdname == "verbatiminput*") { - fl_set_button(dialog_->check_verbatim, 1); - fl_set_button(dialog_->check_visiblespace, cmdname == "verbatiminput*"); + if (verbatimCommand || verbatimStarCommand) { + type_.set(ControlInclude::VERBATIM); + fl_set_button(dialog_->check_visiblespace, verbatimStarCommand); setEnabled(dialog_->check_visiblespace, true); + setEnabled(dialog_->button_load, false); } else { fl_set_button(dialog_->check_visiblespace, 0); setEnabled(dialog_->check_visiblespace, false); + setEnabled(dialog_->button_load, true); } - - if (cmdname.empty()) - fl_set_button(dialog_->check_useinclude, 1); } void FormInclude::apply() { - controller().params().noload = fl_get_button(dialog_->check_typeset); + InsetCommandParams params = controller().params(); - controller().params().cparams. - setContents(fl_get_input(dialog_->input_filename)); + params.preview(fl_get_button(dialog_->check_preview)); + params.setContents(getString(dialog_->input_filename)); - if (fl_get_button(dialog_->check_useinput)) - controller().params().flag = InsetInclude::INPUT; - else if (fl_get_button(dialog_->check_useinclude)) - controller().params().flag = InsetInclude::INCLUDE; - else if (fl_get_button(dialog_->check_verbatim)) { + ControlInclude::Type const type = ControlInclude::Type(type_.get()); + if (type == ControlInclude::INPUT) + params.setCmdName("input"); + else if (type == ControlInclude::INCLUDE) + params.setCmdName("include"); + else if (type == ControlInclude::VERBATIM) { if (fl_get_button(dialog_->check_visiblespace)) - controller().params().flag = InsetInclude::VERBAST; + params.setCmdName("verbatiminput*"); else - controller().params().flag = InsetInclude::VERB; + params.setCmdName("verbatiminput"); } + + controller().setParams(params); } ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long) { - if (ob == dialog_->button_browse) { - ControlInclude::Type type; - if (fl_get_button(dialog_->check_useinput)) - type = ControlInclude::INPUT; - else if (fl_get_button(dialog_->check_verbatim)) - type = ControlInclude::VERBATIM; - else - type = ControlInclude::INCLUDE; + ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID; - string const in_name = fl_get_input(dialog_->input_filename); - fl_freeze_form(form()); - string const out_name = controller().Browse(in_name, type); + if (ob == dialog_->button_browse) { + string const in_name = getString(dialog_->input_filename); + fl_freeze_form(form()); + ControlInclude::Type const type = ControlInclude::Type(type_.get()); + string const out_name = controller().browse(in_name, type); fl_set_input(dialog_->input_filename, out_name.c_str()); - fl_unfreeze_form(form()); - - return ButtonPolicy::SMI_VALID; - } - - if (ob == dialog_->button_load) { - if (compare(fl_get_input(dialog_->input_filename),"")) { - ApplyButton(); - return ButtonPolicy::SMI_NOOP; + fl_unfreeze_form(form()); + + } else if (ob == dialog_->button_load) { + string const in_name = getString(dialog_->input_filename); + if (!rtrim(in_name).empty() && controller().fileExists(in_name)) { + dialog().OKButton(); + controller().load(rtrim(in_name)); + action = ButtonPolicy::SMI_NOOP; } - } - if (ob == dialog_->check_verbatim) { + } else if (ob == dialog_->radio_verbatim) { setEnabled(dialog_->check_visiblespace, true); + setEnabled(dialog_->button_load, false); - } else if (ob == dialog_->check_useinclude || - ob == dialog_->check_useinput) { + } else if (ob == dialog_->radio_useinclude || + ob == dialog_->radio_useinput) { fl_set_button(dialog_->check_visiblespace, 0); setEnabled(dialog_->check_visiblespace, false); + setEnabled(dialog_->button_load, true); + + } else if (ob == dialog_->input_filename) { + string const in_name = getString(dialog_->input_filename); + if (rtrim(in_name).empty()) + action = ButtonPolicy::SMI_INVALID; } - - return ButtonPolicy::SMI_VALID; + + if (ob == dialog_->radio_useinput) { + setEnabled(dialog_->check_preview, true); + } else if (ob == dialog_->radio_verbatim || + ob == dialog_->radio_useinclude) { + fl_set_button(dialog_->check_preview, 0); + setEnabled(dialog_->check_preview, false); + } + + return action; } + +} // namespace frontend +} // namespace lyx