X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FFormInclude.C;h=636574b121c51444b9c75c75c1a59a348c1d4714;hb=27652900a60fd078f161ce866ddaed21dba21eff;hp=66efb6d0879a9aef9c7c67447056192673c9a41b;hpb=9705be9f1b8441175048b4e2065795051adafdc6;p=lyx.git diff --git a/src/frontends/xforms/FormInclude.C b/src/frontends/xforms/FormInclude.C index 66efb6d087..636574b121 100644 --- a/src/frontends/xforms/FormInclude.C +++ b/src/frontends/xforms/FormInclude.C @@ -8,31 +8,20 @@ * \author Angus Leeming, a.leeming@.ac.uk */ +#include #include -#include #ifdef __GNUG__ #pragma implementation #endif -#include #include "xformsBC.h" #include "ControlInclude.h" #include "FormInclude.h" #include "form_include.h" #include "insets/insetinclude.h" - -#include "frontends/FileDialog.h" -#include "LyXView.h" -#include "buffer.h" - #include "xforms_helpers.h" // setEnabled -#include "support/filetools.h" -#include "support/lstrings.h" -#include "lyxrc.h" - -using std::make_pair; -using std::pair; +#include "support/lstrings.h" // strip typedef FormCB > base_class; @@ -45,10 +34,11 @@ void FormInclude::build() { dialog_.reset(build_include()); + 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); @@ -100,8 +90,11 @@ void FormInclude::apply() { controller().params().noload = fl_get_button(dialog_->check_typeset); - controller().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)) controller().params().flag = InsetInclude::INPUT; @@ -118,65 +111,45 @@ void FormInclude::apply() ButtonPolicy::SMInput FormInclude::input(FL_OBJECT * ob, long) { - if (ob == dialog_->button_browse) - return inputBrowse(); - - if (ob == dialog_->button_load) { - if (compare(fl_get_input(dialog_->input_filename),"")) { - ApplyButton(); - return ButtonPolicy::SMI_NOOP; + 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; } - } - if (ob == dialog_->check_verbatim) { + } else if (ob == dialog_->check_verbatim) { setEnabled(dialog_->check_visiblespace, true); } else if (ob == dialog_->check_useinclude || ob == dialog_->check_useinput) { fl_set_button(dialog_->check_visiblespace, 0); setEnabled(dialog_->check_visiblespace, false); - } - - return ButtonPolicy::SMI_VALID; -} - - -ButtonPolicy::SMInput FormInclude::inputBrowse() -{ - // Should browsing too be disabled in RO-mode? - FileDialog fileDlg(controller().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 const mpath = - OnlyPath(controller().params().masterFilename_); - FileDialog::Result const result = - fileDlg.Select(mpath, ext, - fl_get_input(dialog_->input_filename)); - - // check selected filename - if (result.second.empty()) - return ButtonPolicy::SMI_NOOP; + } 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; + } - 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()); - - return ButtonPolicy::SMI_VALID; + return action; }