[LyX/master] Improve functions for bibliography managers (#8193)

Juergen Spitzmueller spitz at lyx.org
Sun Dec 18 11:32:24 UTC 2022


commit 9fc190d61c55f23c8dfccf0b6a237a6d358fce24
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sun Dec 18 13:25:24 2022 +0100

    Improve functions for bibliography managers (#8193)
    
    - new function to list bibtex databases
    - citation-insert returns the list of undefined keys
      if the request comes from the LyX server
    
    Original patch from Benjamin Piwowarski (2012!).
    Modified and updated by Riki Heck and myself.
---
 lib/RELEASE-NOTES  |    4 ++++
 src/BufferView.cpp |   44 ++++++++++++++++++++++++++++++++++++++++++++
 src/FuncCode.h     |    1 +
 src/LyXAction.cpp  |   10 ++++++++++
 4 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES
index 7a42650..c864919 100644
--- a/lib/RELEASE-NOTES
+++ b/lib/RELEASE-NOTES
@@ -128,6 +128,10 @@
 
 !!!The following new LyX functions have been introduced in 2.4:
 
+* bibtex-database-list: output a list of all bibtex files used in the current buffer.
+  The function outputs absolute paths in the OS style and separated by the os-specific
+  path separator. This function is intended for bibliography managers.
+
 * buffer-reset-export advises LyX to remove the auxiliary files before doing the next
   export.
 
diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index 0bbf649..d3cf909 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -20,6 +20,7 @@
 #include "Buffer.h"
 #include "BufferList.h"
 #include "BufferParams.h"
+#include "BiblioInfo.h"
 #include "CoordCache.h"
 #include "Cursor.h"
 #include "CutAndPaste.h"
@@ -69,6 +70,7 @@
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstring.h"
+#include "support/docstring_list.h"
 #include "support/filetools.h"
 #include "support/gettext.h"
 #include "support/lassert.h"
@@ -1223,6 +1225,7 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 	case LFUN_SCREEN_SHOW_CURSOR:
 	case LFUN_BIBTEX_DATABASE_ADD:
 	case LFUN_BIBTEX_DATABASE_DEL:
+	case LFUN_BIBTEX_DATABASE_LIST:
 	case LFUN_STATISTICS:
 	case LFUN_KEYMAP_OFF:
 	case LFUN_KEYMAP_PRIMARY:
@@ -1928,6 +1931,25 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		break;
 	}
 
+	case LFUN_BIBTEX_DATABASE_LIST: {
+		docstring_list const & files = buffer_.getBibfiles();
+		bool first = true;
+		docstring result;
+		char const separator(os::path_separator());
+		for (auto const & file : files) {
+			if (first)
+				first = false;
+			else
+				result += separator;
+
+			FileName const fn = buffer_.getBibfilePath(file);
+			string const path = fn.realPath();
+			result += from_utf8(os::external_path(path));
+		}
+		dr.setMessage(result);
+		break;
+	}
+
 	case LFUN_STATISTICS: {
 		DocIterator from, to;
 		if (cur.selection()) {
@@ -2281,6 +2303,28 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
 		string icstr = InsetCommand::params2string(icp);
 		FuncRequest fr(LFUN_INSET_INSERT, icstr);
 		lyx::dispatch(fr);
+
+		// if the request comes from the LyX server, then we
+		// return a list of the undefined keys, in case some
+		// action could be taken.
+		if (cmd.origin() != FuncRequest::LYXSERVER)
+			break;
+
+		vector<docstring> keys = getVectorFromString(from_utf8(arg));
+		vector<docstring>::iterator it = keys.begin();
+		vector<docstring>::const_iterator end = keys.end();
+
+		BiblioInfo const & bibInfo = buffer_.masterBibInfo();
+		const BiblioInfo::const_iterator bibEnd = bibInfo.end();
+		while (it != end) {
+			if (bibInfo.find(*it) != bibEnd) {
+				it = keys.erase(it);
+				end = keys.end();
+			} else
+				++it;
+		}
+		dr.setMessage(getStringFromVector(keys));
+
 		break;
 	}
 
diff --git a/src/FuncCode.h b/src/FuncCode.h
index aaa88f2..56fb5bf 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -507,6 +507,7 @@ enum FuncCode
 	LFUN_TAB_GROUP_NEXT,            // daniel 20220130
 	LFUN_TAB_GROUP_PREVIOUS,        // daniel 20220130
 	// 395
+	LFUN_BIBTEX_DATABASE_LIST,      // bpiwowar, 20221218
 	LFUN_LASTACTION                 // end of the table
 };
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 96060f8..fc6886b 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -331,6 +331,16 @@ void LyXAction::init()
  */
 		{ LFUN_BIBTEX_DATABASE_DEL, "bibtex-database-del", Noop, Edit },
 
+/*!
+ * \var lyx::FuncCode lyx::LFUN_BIBTEX_DATABASE_LIST
+ * \li Action: Lists the available databases (separated by path separator common
+ *             on the used OS).
+ * \li Notion: Used by bibliographic managers
+ * \li Syntax: bibtex-database-list
+ * \li Origin: bpiwowar, 11 june 2012
+ * \endvar
+ */
+		{ LFUN_BIBTEX_DATABASE_LIST, "bibtex-database-list", ReadOnly, System },
 
 /*!
  * \var lyx::FuncCode lyx::LFUN_BOOKMARK_CLEAR


More information about the lyx-cvs mailing list