]> git.lyx.org Git - features.git/commitdiff
Improve functions for bibliography managers (#8193)
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 18 Dec 2022 12:25:24 +0000 (13:25 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 18 Dec 2022 12:25:24 +0000 (13:25 +0100)
- 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
src/BufferView.cpp
src/FuncCode.h
src/LyXAction.cpp

index 7a426506dc1164c965e13fd805a393d4179dc0fa..c864919bf8dc2f3b4beb62d9d12ee94caf6b6552 100644 (file)
 
 !!!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.
 
index 0bbf6497964536773073c44e2490c486d3f25476..d3cf909ea351fd2c74547bd3f41adc9c85814725 100644 (file)
@@ -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;
        }
 
index aaa88f246673adda01dd89d5dbc9ade1c4417e26..56fb5bfd06a2d3141766491387dd767a75f99fb6 100644 (file)
@@ -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
 };
 
index 96060f80fed0758d27e4d673751cc6a8ca741b5c..fc6886bd7c0736b2b2703c5f075c262ef057c4d4 100644 (file)
@@ -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