[LyX/master] Report back if citation target could not be opened

Juergen Spitzmueller spitz at lyx.org
Thu Aug 27 09:27:11 UTC 2020


commit ff14d0bd007065f058951d902255496f38a6d056
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Thu Aug 27 11:52:52 2020 +0200

    Report back if citation target could not be opened
---
 lib/scripts/lyxpaperview.py     |    4 ++--
 src/frontends/qt/qt_helpers.cpp |   22 +++++++++++++++++-----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/lib/scripts/lyxpaperview.py b/lib/scripts/lyxpaperview.py
index 3a611a6..f62c5ea 100755
--- a/lib/scripts/lyxpaperview.py
+++ b/lib/scripts/lyxpaperview.py
@@ -122,7 +122,7 @@ def main(argv):
     result = find(args, path = os.environ["HOME"])
     if result == "":
         message("no document found!")
-        return 0
+        exit(2)
     else:
         message("found document %s" % result)
 
@@ -140,7 +140,7 @@ def main(argv):
     
     subprocess.call([viewer, result])
     
-    return 0
+    exit(0)
 
 if __name__ == "__main__":
     main(sys.argv)
diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp
index f064d50..20f5803 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -298,7 +298,8 @@ void showDirectory(FileName const & directory)
 		LYXERR0("Unable to open QUrl even though dir exists!");
 }
 
-void showTarget(string const & target, string const & pdfv, string const & psv){
+void showTarget(string const & target, string const & pdfv, string const & psv)
+{
 	LYXERR(Debug::INSETS, "Showtarget:" << target << "\n");
 	if (prefixIs(target, "EXTERNAL ")) {
 		if (!lyxrc.citation_search)
@@ -311,12 +312,23 @@ void showTarget(string const & target, string const & pdfv, string const & psv){
 			opts += " -w " + psv;
 		if (!opts.empty())
 			opts += " ";
-		FuncRequest cmd = FuncRequest(LFUN_VC_COMMAND,"U . \"" +
-		                  lyxrc.citation_search_view + " " + opts + tar + "\"");
-		lyx::dispatch(cmd);
+		Systemcall one;
+		string const command = lyxrc.citation_search_view + " " + opts + tar;
+		int const result = one.startscript(Systemcall::Wait, command);
+		if (result == 1)
+			// Script failed
+			frontend::Alert::error(_("Could not open file"),
+				_("The lyxpaperview script failed."));
+		else if (result == 2)
+			frontend::Alert::error(_("Could not open file"),
+				bformat(_("No file was found using the pattern `%1$s'."),
+					from_utf8(tar)));
 		return;
 	}
-	QDesktopServices::openUrl(QUrl(toqstr(target), QUrl::TolerantMode));
+	if (!QDesktopServices::openUrl(QUrl(toqstr(target), QUrl::TolerantMode)))
+		frontend::Alert::error(_("Could not open file"),
+			bformat(_("The target `%1$s' could not be resolved."),
+				from_utf8(target)));
 }
 } // namespace frontend
 


More information about the lyx-cvs mailing list