[LyX/master] Enable Open Citation menu item iff citation contain locator information or external search script is available.

Pavel Sanda sanda at lyx.org
Sun Aug 23 19:56:54 UTC 2020


commit 894ad70eba5bf6abc523bf9c10df2b2ca4bd876f
Author: Pavel Sanda <sanda at lyx.org>
Date:   Sun Aug 23 22:19:34 2020 +0200

    Enable Open Citation menu item iff citation contain locator information or external search script is available.
    
    Per Juergen's request.
---
 lib/RELEASE-NOTES                |    3 +++
 lib/configure.py                 |    4 +++-
 lib/scripts/prefs2prefs_prefs.py |    8 +++++++-
 src/LyXRC.cpp                    |   17 ++++++++++++++++-
 src/LyXRC.h                      |    8 ++++++++
 src/insets/InsetCitation.cpp     |   36 +++++++++++++++++++++++++++++-------
 src/insets/InsetCitation.h       |    5 ++++-
 7 files changed, 70 insertions(+), 11 deletions(-)

diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES
index 40abf2a..6cfec8a 100644
--- a/lib/RELEASE-NOTES
+++ b/lib/RELEASE-NOTES
@@ -49,6 +49,9 @@
 * \ct_markup_copied true|false: determines whether change tracking markup should be
   preserved on copy/paste (default: false).
 
+* \citation_search_view lyxpaperview: determines whether external script "lyxpaperview"
+  should be used for looking up citation source.
+
 
 !!!The following pref variables were changed in 2.4:
 
diff --git a/lib/configure.py b/lib/configure.py
index 2b4d61f..856b82b 100644
--- a/lib/configure.py
+++ b/lib/configure.py
@@ -1310,6 +1310,8 @@ def checkOtherEntries():
         rc_entry = [ r'\nomencl_command "makeindex -s nomencl.ist"' ])
     checkProg('a python-pygments driver command', ['pygmentize'],
         rc_entry = [ r'\pygmentize_command "%%"' ])
+    checkProg('external script for searching and showing citation sources',
+        ['lyxpaperview'], rc_entry = [ r'\citation_search_view "%%"' ])
     ## FIXME: OCTAVE is not used anywhere
     # path, OCTAVE = checkProg('Octave', ['octave'])
     ## FIXME: MAPLE is not used anywhere
@@ -1875,7 +1877,7 @@ if __name__ == '__main__':
     lyx_check_config = True
     lyx_kpsewhich = True
     outfile = 'lyxrc.defaults'
-    lyxrc_fileformat = 31
+    lyxrc_fileformat = 33
     rc_entries = ''
     lyx_keep_temps = False
     version_suffix = ''
diff --git a/lib/scripts/prefs2prefs_prefs.py b/lib/scripts/prefs2prefs_prefs.py
index 6bbb8ac..d22d758 100644
--- a/lib/scripts/prefs2prefs_prefs.py
+++ b/lib/scripts/prefs2prefs_prefs.py
@@ -129,6 +129,11 @@
 #   Add ct_markup_copied.
 #   No convergence necessary.
 
+# Incremented to format 33, by sanda
+#   Add \citation_search_view.
+#   No conversion necessary.
+
+
 # NOTE: The format should also be updated in LYXRC.cpp and
 # in configure.py.
 
@@ -479,5 +484,6 @@ conversions = [
 	[ 29, [remove_use_pixmap_cache]],
 	[ 30, []],
 	[ 31, []],
-	[ 32, []]
+	[ 32, []],
+	[ 33, []]
 ]
diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp
index 328e683..e3bb0de 100644
--- a/src/LyXRC.cpp
+++ b/src/LyXRC.cpp
@@ -61,7 +61,7 @@ namespace {
 
 // The format should also be updated in configure.py, and conversion code
 // should be added to prefs2prefs_prefs.py.
-static unsigned int const LYXRC_FILEFORMAT = 32; // spitz: add \ct_markup_copied
+static unsigned int const LYXRC_FILEFORMAT = 33; // sanda: add \citation_search_view
 // when adding something to this array keep it sorted!
 LexerKeyword lyxrcTags[] = {
 	{ "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND },
@@ -78,6 +78,7 @@ LexerKeyword lyxrcTags[] = {
 	{ "\\bind_file", LyXRC::RC_BINDFILE },
 	{ "\\check_lastfiles", LyXRC::RC_CHECKLASTFILES },
 	{ "\\chktex_command", LyXRC::RC_CHKTEX_COMMAND },
+	{ "\\citation_search_view", LyXRC::RC_CITATION_SEARCH_VIEW },
 	{ "\\close_buffer_with_last_view", LyXRC::RC_CLOSE_BUFFER_WITH_LAST_VIEW },
 	{ "\\completion_cursor_text", LyXRC::RC_COMPLETION_CURSOR_TEXT },
 	{ "\\completion_inline_delay", LyXRC::RC_COMPLETION_INLINE_DELAY },
@@ -679,6 +680,10 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
 			}
 			break;
 
+		case RC_CITATION_SEARCH_VIEW:
+			lexrc >> citation_search_view;
+			break;
+
 		case RC_CT_ADDITIONS_UNDERLINED:
 			lexrc >> ct_additions_underlined;
 			break;
@@ -1602,6 +1607,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
 		if (tag != RC_LAST)
 			break;
 		// fall through
+	case RC_CITATION_SEARCH_VIEW:
+		if (ignore_system_lyxrc ||
+		    citation_search_view != system_lyxrc.citation_search_view) {
+			os << "\\citaton_search_view "
+			   << citation_search_view << '\n';
+		}
+		if (tag != RC_LAST)
+			break;
+		// fall through
 	case RC_CT_ADDITIONS_UNDERLINED:
 		if (ignore_system_lyxrc ||
 		    ct_additions_underlined
@@ -2774,6 +2788,7 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
 	case LyXRC::RC_BIBTEX_ALTERNATIVES:
 	case LyXRC::RC_BIBTEX_COMMAND:
 	case LyXRC::RC_BINDFILE:
+	case LyXRC::RC_CITATION_SEARCH_VIEW:
 	case LyXRC::RC_CHECKLASTFILES:
 	case LyXRC::RC_COMPLETION_CURSOR_TEXT:
 	case LyXRC::RC_COMPLETION_INLINE_DELAY:
diff --git a/src/LyXRC.h b/src/LyXRC.h
index 955826b..1f32fef 100644
--- a/src/LyXRC.h
+++ b/src/LyXRC.h
@@ -53,6 +53,7 @@ public:
 		RC_BINDFILE,
 		RC_CHECKLASTFILES,
 		RC_CHKTEX_COMMAND,
+		RC_CITATION_SEARCH_VIEW,
 		RC_COMPLETION_CURSOR_TEXT,
 		RC_COMPLETION_INLINE_DELAY,
 		RC_COMPLETION_INLINE_MATH,
@@ -243,6 +244,13 @@ public:
 	/// default paper size for local xdvi/dvips/ghostview/whatever
 	/// command to run chktex incl. options
 	std::string chktex_command = "chktex -n1 -n3 -n6 -n9 -n22 -n25 -n30 -n38";
+	// Name of external script, which searches for file corresponding to a 
+	// given citation. At this moment only script "lyxpaperview" is supported
+	// (search for pdf based on author+year), but we can generalize if requested.
+	// Citation context menu item "Open Citation Content" will be always enabled
+	// if the name of this script in nonempty (last resort when citation entry
+	// does not contain neccessary info.
+	std::string citation_search_view;
 	/// all available commands to run bibtex incl. options
 	CommandSet bibtex_alternatives;
 	/// command to run bibtex incl. options
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index 66db11a..7ae75b8 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -24,6 +24,7 @@
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "LyX.h"
+#include "LyXRC.h"
 #include "output_xhtml.h"
 #include "output_docbook.h"
 #include "ParIterator.h"
@@ -168,20 +169,41 @@ void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
 	}
 }
 
-
-void InsetCitation::openCitation(){
+bool InsetCitation::openCitationPossible() const
+{
 	Buffer const & buf = *buffer_;
-	// Only after the buffer is loaded from file...
+	// only after the buffer is loaded from file...
 	if (!buf.isFullyLoaded())
-		return;
+		return false;
 
 	BiblioInfo const & bi = buf.masterBibInfo();
 	if (bi.empty())
-		return;
+		return false;
 
 	docstring const & key = getParam("key");
 	if (key.empty())
-		return;
+		return false;
+
+	// does bibtex item contains some locator?
+	vector<docstring> keys = getVectorFromString(key);
+	docstring doi, url, file;
+	for (docstring const & kvar : keys) {
+		bi.getLocators(kvar, doi, url, file);
+		if (!file.empty() || !doi.empty() || !url.empty())
+			return true;
+	}
+
+	// last resort: is external script available?
+	if (!lyxrc.citation_search_view.empty())
+		return true;
+	return false;
+}
+
+void InsetCitation::openCitation()
+{
+	Buffer const & buf = *buffer_;
+	BiblioInfo const & bi = buf.masterBibInfo();
+	docstring const & key = getParam("key");
 
 	vector<docstring> keys = getVectorFromString(key);
 	docstring year, author, doi, url, file;
@@ -246,7 +268,7 @@ bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd,
 		}
 		return true;
 	case LFUN_INSET_EDIT:
-		return true;
+		return openCitationPossible();
 	default:
 		return InsetCommand::getStatus(cur, cmd, status);
 	}
diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h
index 29e4b1f..e9f0347 100644
--- a/src/insets/InsetCitation.h
+++ b/src/insets/InsetCitation.h
@@ -94,7 +94,10 @@ public:
 	QualifiedList getQualifiedLists(docstring const & p) const;
 	///
 	static bool last_literal;
-	///
+	/// Check whether citation contains necessary url/file entries
+	/// or external search script is available
+	bool openCitationPossible() const;
+	/// search and open citation source
 	void openCitation();
 
 private:


More information about the lyx-cvs mailing list