Jean-Marc Lasgouttes wrote: > Herbert Voss wrote: > >> Michael Schmitt wrote: >> >> > - Insert an "include" inset with an invalid file name; then open its >> dialog and click >> > on "load" -> console message: "OkCancelReadOnlyPolicy: No >> transition for input 3 from state 0" >> >> can somebody help please: I want to test if the chosen file exists, >> but how can I get the filepath, when I enter in the include-gui >> only (for example) "myfile.lyx". In this case the path is the one from >> the active doc, but how can I get this path in ControlInclude.C? > > The path is OnlyPath(params().masterFilename_). So do a > MakeAbsPath(input_file, OnlyPath(params().masterFilename_)) > which shoud do the right thing in all cases.
thanks, this did it. The one from John maybe the cleaner solution, but I don't know ... Here is a small patch for the above problem from Michael's buglist. Herbert -- http://www.lyx.org/help/
Index: src/frontends/controllers/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ChangeLog,v retrieving revision 1.122 diff -u -r1.122 ChangeLog --- src/frontends/controllers/ChangeLog 2002/01/20 16:07:42 1.122 +++ src/frontends/controllers/ChangeLog 2002/01/20 17:53:16 @@ -1,12 +1,17 @@ +2002-01-20 Herbert Voss <[EMAIL PROTECTED]> + + * ControlInclude.[Ch]: better handling when filename doesn't exists. + bool const fileExists() + Index: src/frontends/controllers/ControlInclude.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlInclude.C,v retrieving revision 1.13 diff -u -r1.13 ControlInclude.C --- src/frontends/controllers/ControlInclude.C 2002/01/16 22:17:38 1.13 +++ src/frontends/controllers/ControlInclude.C 2002/01/20 17:53:16 @@ -20,6 +20,7 @@ #include "ControlInclude.h" #include "ControlInset.tmpl" #include "buffer.h" +#include "Alert.h" #include "BufferView.h" #include "Dialogs.h" #include "LyXView.h" @@ -80,3 +81,15 @@ { lv_.getLyXFunc()->dispatch(LFUN_CHILDOPEN, file); } + + +bool const ControlInclude::fileExists(string const & file) +{ + string const fileWithAbsPath = MakeAbsPath(file, +OnlyPath(params().masterFilename_)); + if (IsFileReadable(fileWithAbsPath)) + return true; + else + Alert::alert(_("File doesn't exists!")); + return false; +} + Index: src/frontends/controllers/ControlInclude.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlInclude.h,v retrieving revision 1.5 diff -u -r1.5 ControlInclude.h --- src/frontends/controllers/ControlInclude.h 2001/07/25 12:37:43 1.5 +++ src/frontends/controllers/ControlInclude.h 2002/01/20 17:53:16 @@ -43,6 +43,9 @@ /// load a file void load(string const & file); + /// test if file exist + bool const fileExists(string const & file); + private: /// Dispatch the changed parameters to the kernel. virtual void applyParamsToInset(); Index: src/frontends/xforms/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v retrieving revision 1.256 diff -u -r1.256 ChangeLog --- src/frontends/xforms/ChangeLog 2002/01/19 17:05:23 1.256 +++ src/frontends/xforms/ChangeLog 2002/01/20 17:53:17 @@ -1,3 +1,7 @@ +2002-01-20 Herbert Voss <[EMAIL PROTECTED]> + + * FormInclude.C: better handling when filename doesn't exists + 2002-01-16 Herbert Voss <[EMAIL PROTECTED]> * FormExternal.C (build): activate apply/ok-button when something Index: src/frontends/xforms/FormInclude.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/FormInclude.C,v retrieving revision 1.15 diff -u -r1.15 FormInclude.C --- src/frontends/xforms/FormInclude.C 2001/07/25 12:37:43 1.15 +++ src/frontends/xforms/FormInclude.C 2002/01/20 17:53:17 @@ -90,8 +90,11 @@ { 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; @@ -127,8 +130,9 @@ } else if (ob == dialog_->button_load) { string const in_name = fl_get_input(dialog_->input_filename); - if (!strip(in_name).empty()) { - ApplyButton(); + if (!strip(in_name).empty() && controller().fileExists(in_name)) { +// ApplyButton(); + OKButton(); controller().load(strip(in_name)); action = ButtonPolicy::SMI_NOOP; }