diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES index 7a426506dc..c864919bf8 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 0bbf649796..d3cf909ea3 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 keys = getVectorFromString(from_utf8(arg)); + vector::iterator it = keys.begin(); + vector::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 aaa88f2466..56fb5bfd06 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 96060f80fe..fc6886bd7c 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