X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FFormInclude.C;h=636574b121c51444b9c75c75c1a59a348c1d4714;hb=27652900a60fd078f161ce866ddaed21dba21eff;hp=1d33dd9557a5959cdd0bd202d3c8bed61f0d9248;hpb=9c36dd0f40f2e2e90fce8b2f33519a5d99d9be8b;p=lyx.git diff --git a/src/frontends/xforms/FormInclude.C b/src/frontends/xforms/FormInclude.C index 1d33dd9557..636574b121 100644 --- a/src/frontends/xforms/FormInclude.C +++ b/src/frontends/xforms/FormInclude.C @@ -4,115 +4,53 @@ * Read the file COPYING * * \author Alejandro Aguilar Sierra - * \author John Levon + * \author John Levon, moz@compsoc.man.ac.uk + * \author Angus Leeming, a.leeming@.ac.uk */ + #include #include -#include #ifdef __GNUG__ #pragma implementation #endif -#include "Dialogs.h" +#include "xformsBC.h" +#include "ControlInclude.h" #include "FormInclude.h" -#include "insets/insetinclude.h" -#include "frontends/FileDialog.h" -#include "support/filetools.h" -#include "support/lstrings.h" -#include "LyXView.h" -#include "buffer.h" -#include "lyxrc.h" -#include "lyxfunc.h" -#include "xforms_helpers.h" - #include "form_include.h" +#include "insets/insetinclude.h" +#include "xforms_helpers.h" // setEnabled +#include "support/lstrings.h" // strip -using std::make_pair; -using std::pair; - -FormInclude::FormInclude(LyXView * lv, Dialogs * d) - : FormBaseBD(lv, d, _("Include file")), - ih_(0), inset_(0) -{ - d->showInclude.connect(slot(this, &FormInclude::showInclude)); -} - - -FL_FORM * FormInclude::form() const -{ - if (dialog_.get()) - return dialog_->form; - return 0; -} - - -void FormInclude::connect() -{ - u_ = d_->updateBufferDependent. - connect(slot(this, &FormInclude::updateSlot)); - h_ = d_->hideBufferDependent. - connect(slot(this, &FormInclude::hide)); - FormBaseDeprecated::connect(); -} - - -void FormInclude::disconnect() -{ - ih_.disconnect(); - FormBaseBD::disconnect(); - inset_ = 0; -} - +typedef FormCB > base_class; -void FormInclude::updateSlot(bool switched) -{ - if (switched) - hide(); - else - update(); -} +FormInclude::FormInclude(ControlInclude & c) + : base_class(c, _("Include file")) +{} void FormInclude::build() { dialog_.reset(build_include()); - // Workaround dumb xforms sizing bug - minw_ = form()->w; - minh_ = form()->h; + fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED); // 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); -} - - -void FormInclude::showInclude(InsetInclude * inset) -{ - // If connected to another inset, disconnect from it. - if (inset_) - ih_.disconnect(); - - inset_ = inset; - params = inset->params(); - ih_ = inset->hideDialog.connect(slot(this, &FormInclude::hide)); - show(); + bc().setOK(dialog_->button_ok); + bc().setCancel(dialog_->button_cancel); + + 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); } void FormInclude::update() { - bc().readOnly(lv_->buffer()->isReadonly()); - - if (!inset_) { + if (controller().params().noload) { fl_set_input(dialog_->input_filename, ""); fl_set_button(dialog_->check_typeset, 0); fl_set_button(dialog_->check_useinput, 0); @@ -124,11 +62,13 @@ void FormInclude::update() return; } - fl_set_input(dialog_->input_filename, params.cparams.getContents().c_str()); + fl_set_input(dialog_->input_filename, + controller().params().cparams.getContents().c_str()); - string const cmdname = params.cparams.getCmdName(); + string const cmdname = controller().params().cparams.getCmdName(); - fl_set_button(dialog_->check_typeset, int(params.noload)); + fl_set_button(dialog_->check_typeset, + int(controller().params().noload)); fl_set_button(dialog_->check_useinput, cmdname == "input"); fl_set_button(dialog_->check_useinclude, cmdname == "include"); @@ -148,86 +88,68 @@ void FormInclude::update() void FormInclude::apply() { - if (lv_->buffer()->isReadonly()) - return; - - params.noload = fl_get_button(dialog_->check_typeset); + controller().params().noload = fl_get_button(dialog_->check_typeset); - params.cparams.setContents(fl_get_input(dialog_->input_filename)); + string const file = fl_get_input(dialog_->input_filename); + if (controller().fileExists(file)) + controller().params().cparams.setContents(file); + else + controller().params().cparams.setContents(""); if (fl_get_button(dialog_->check_useinput)) - params.flag = InsetInclude::INPUT; + controller().params().flag = InsetInclude::INPUT; else if (fl_get_button(dialog_->check_useinclude)) - params.flag = InsetInclude::INCLUDE; + controller().params().flag = InsetInclude::INCLUDE; else if (fl_get_button(dialog_->check_verbatim)) { if (fl_get_button(dialog_->check_visiblespace)) - params.flag = InsetInclude::VERBAST; + controller().params().flag = InsetInclude::VERBAST; else - params.flag = InsetInclude::VERB; + controller().params().flag = InsetInclude::VERB; } - - inset_->setFromParams(params); - lv_->view()->updateInset(inset_, true); } -#ifdef WITH_WARNINGS -#warning convert this to use the buttoncontroller -#endif -bool FormInclude::input(FL_OBJECT *, long data) + +ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long) { - State state = static_cast(data); - - switch (state) { - case BROWSE: { - // Should browsing too be disabled in RO-mode? - FileDialog fileDlg(lv_, _("Select document to include"), - LFUN_SELECT_FILE_SYNC, - make_pair(string(_("Documents")), string(lyxrc.document_path))); - - string ext; - - /* input TeX, verbatim, or LyX file ? */ - if (fl_get_button(dialog_->check_useinput)) - ext = _("*.tex| LaTeX Documents (*.tex)"); - else if (fl_get_button(dialog_->check_verbatim)) - ext = _("*| All files "); - else - ext = _("*.lyx| LyX Documents (*.lyx)"); - - string mpath; + ButtonPolicy::SMInput action = ButtonPolicy::SMI_VALID; + + 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; + + string const in_name = fl_get_input(dialog_->input_filename); + fl_freeze_form(form()); + string const out_name = controller().Browse(in_name, type); + fl_set_input(dialog_->input_filename, out_name.c_str()); + fl_unfreeze_form(form()); + + } else if (ob == dialog_->button_load) { + string const in_name = fl_get_input(dialog_->input_filename); + if (!strip(in_name).empty() && controller().fileExists(in_name)) { +// ApplyButton(); + OKButton(); + controller().load(strip(in_name)); + action = ButtonPolicy::SMI_NOOP; + } + + } else if (ob == dialog_->check_verbatim) { + setEnabled(dialog_->check_visiblespace, true); - mpath = OnlyPath(params.buffer->fileName()); + } else if (ob == dialog_->check_useinclude || + ob == dialog_->check_useinput) { + fl_set_button(dialog_->check_visiblespace, 0); + setEnabled(dialog_->check_visiblespace, false); - FileDialog::Result result = fileDlg.Select(mpath, ext, fl_get_input(dialog_->input_filename)); - - // check selected filename - if (result.second.empty()) - break; - - string const filename2 = MakeRelPath(result.second, mpath); - - if (prefixIs(filename2, "..")) - fl_set_input(dialog_->input_filename, result.second.c_str()); - else - fl_set_input(dialog_->input_filename, filename2.c_str()); - - } break; - - case LOAD: - if (compare(fl_get_input(dialog_->input_filename),"")) { - apply(); - lv_->getLyXFunc()->Dispatch(LFUN_CHILDOPEN, params.cparams.getContents()); - } - break; - - case VERBATIM: - setEnabled(dialog_->check_visiblespace, true); - break; - - case INPUTINCLUDE: - fl_set_button(dialog_->check_visiblespace, 0); - setEnabled(dialog_->check_visiblespace, false); - break; + } else if (ob == dialog_->input_filename) { + string const in_name = fl_get_input(dialog_->input_filename); + if (strip(in_name).empty()) + action = ButtonPolicy::SMI_INVALID; } - return true; + + return action; }