Hi, I have a revised patch for the little problem of an possibly non existing user-provided listing file in LyX child-document dialog. Following JMarc's suggestion I am now altering the label-text of the Include-inset by an additional string "FILE MISSING: " (of course only if the file is missing!). So the user sees immediately what is going on instead of getting later an LaTex-error during conversation (for example in PDF).
Hth Jürgen PS: If the small change is worth to merge in LyX: what is about the translation of the new introduced string into all supported languages and whats about the LyX documentation (also all languages)? Am 25.02.2019 um 18:33 schrieb Jean-Marc Lasgouttes: > Le 22/02/2019 à 21:29, Jürgen Womser-Schütz a écrit : >> Hi alltogether, >> >> I have a revised patch for the little problem of possibly non existing >> user-provided listing file in LyX child-document dialog. >> If the listing file don't exist, a warning QMessageBox is displayed: >> "The listing file " FILENAME " does not exist. You will not be able >> to export your LyX-file (LaTeX-errors)." >> The diff-file is attached. > > Another possibility would be to change the label of the include inset > to start with "INVALID" of something like that. This is already what > we do with broken cross references. This would also appear in the > outline and the user would see it immediately after clicking OK. > >> In my opinion the whole LyX child-document dialog needs a revision. >> Im am not a user of this dialog at all but if I select instead of >> "Program Listing" for example "Input" or "Include" I get errors. > > This is my problem too. I am a very light user of the dialog. > > JMarc >
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp old mode 100644 new mode 100755 index 51cc147333..a74a51600b --- a/src/insets/InsetInclude.cpp +++ b/src/insets/InsetInclude.cpp @@ -55,6 +55,7 @@ #include "support/convert.h" #include "support/debug.h" #include "support/docstream.h" +#include "support/FileName.h" #include "support/FileNameList.h" #include "support/filetools.h" #include "support/gettext.h" @@ -188,7 +189,7 @@ char_type replaceCommaInBraces(docstring & params) InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p) : InsetCommand(buf, p), include_label(uniqueID()), preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false), - set_label_(false), label_(0), child_buffer_(0) + set_label_(false), label_(0), child_buffer_(0), file_exist_(false) { preview_->connect([=](){ fileChanged(); }); @@ -203,7 +204,7 @@ InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p) InsetInclude::InsetInclude(InsetInclude const & other) : InsetCommand(other), include_label(other.include_label), preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false), - set_label_(false), label_(0), child_buffer_(0) + set_label_(false), label_(0), child_buffer_(0), file_exist_(other.file_exist_) { preview_->connect([=](){ fileChanged(); }); @@ -391,6 +392,8 @@ bool InsetInclude::isChildIncluded() const docstring InsetInclude::screenLabel() const { + docstring pre = file_exist_ ? _("") : _("FILE MISSING: "); + docstring temp; switch (type(params())) { @@ -418,13 +421,9 @@ docstring InsetInclude::screenLabel() const } temp += ": "; + temp += from_utf8(onlyFileName(to_utf8(params()["filename"]))); - if (params()["filename"].empty()) - temp += "???"; - else - temp += from_utf8(onlyFileName(to_utf8(params()["filename"]))); - - return temp; + return pre + temp; } @@ -513,8 +512,8 @@ void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const { string incfile = to_utf8(params()["filename"]); - // Do nothing if no file name has been specified - if (incfile.empty()) + // Do nothing if file doesn't exist + if (!listingFileExist()) return; FileName const included_file = includedFileName(buffer(), params()); @@ -1330,6 +1329,8 @@ void InsetInclude::updateCommand() void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype) { + file_exist_ = listingFileExist(); + button_.update(screenLabel(), true, false); Buffer const * const childbuffer = getChildBuffer(); @@ -1359,4 +1360,12 @@ void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype) } +bool InsetInclude::listingFileExist() const +{ + // check whether the file of the listing exist + string listingFileName = to_utf8(params()["filename"]); + FileName fn = support::makeAbsPath(listingFileName, support::onlyPath(buffer().absFileName())); + return fn.exists(); +} + } // namespace lyx diff --git a/src/insets/InsetInclude.h b/src/insets/InsetInclude.h old mode 100644 new mode 100755 index 9ecaf42e7e..65e2945c92 --- a/src/insets/InsetInclude.h +++ b/src/insets/InsetInclude.h @@ -137,6 +137,8 @@ private: void editIncluded(std::string const & file); /// bool isChildIncluded() const; + /// check whether the file of the listing exist + bool listingFileExist() const; /// \name Private functions inherited from Inset class //@{ @@ -170,6 +172,7 @@ private: mutable docstring listings_label_; InsetLabel * label_; mutable Buffer * child_buffer_; + mutable bool file_exist_; };