[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-devel
Subject:    Re: LyX functions for bibliography managers
From:       Benjamin Piwowarski <benjamin.piwowarski () lip6 ! fr>
Date:       2012-10-26 13:28:47
Message-ID: 96065D81-64C6-494F-96B5-511195ED1BAD () lip6 ! fr
[Download RAW message or body]

Hi,

here is the file containing the five patches

["bibtex-insert-000.patch" (bibtex-insert-000.patch)]

From 1bf2db72ca629a9b0d596c81eef4cd36f4f75172 Mon Sep 17 00:00:00 2001
From: Benjamin Piwowarski <benjamin@bpiwowar.net>
Date: Thu, 11 Oct 2012 14:11:29 +0200
Subject: [PATCH 1/5] Refactored BibTeX parsing

---
 src/insets/InsetBibtex.cpp |  113 +++++++++++++++++++++++++-------------------
 1 file changed, 65 insertions(+), 48 deletions(-)

diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index 8f33a2d..4bf98be 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -431,17 +431,36 @@ support::FileNameList InsetBibtex::getBibFiles() const
 
 }
 
-namespace {
-
-	// methods for parsing bibtex files
-
+/**
+  This bibtex parser is a first step to parse bibtex files
+  more precisely.
+
+- it reads the whole bibtex entry and does a syntax check
+  (matching delimiters, missing commas,...
+- it recovers from errors starting with the next @-character
+- it reads @string definitions and replaces them in the
+  field values.
+- it accepts more characters in keys or value names than
+  bibtex does.
+
+Officially bibtex does only support ASCII, but in practice
+you can use the encoding of the main document as long as
+some elements like keys and names are pure ASCII. Therefore
+we convert the file from the buffer encoding.
+We don't restrict keys to ASCII in LyX, since our own
+InsetBibitem can generate non-ASCII keys, and nonstandard
+8bit clean bibtex forks exist.
+*/
+class BibtexParser {
+public:
 	typedef map<docstring, docstring> VarMap;
 
+
 	/// remove whitespace characters, optionally a single comma,
 	/// and further whitespace characters from the stream.
 	/// @return true if a comma was found, false otherwise
 	///
-	bool removeWSAndComma(ifdocstream & ifs) {
+	bool removeWSAndComma(std::basic_istream<char_type> & ifs) {
 		char_type ch;
 
 		if (!ifs)
@@ -484,7 +503,7 @@ namespace {
 	///
 	/// @return true if a string of length > 0 could be read.
 	///
-	bool readTypeOrKey(docstring & val, ifdocstream & ifs,
+	bool readTypeOrKey(docstring & val, std::basic_istream<char_type> & ifs,
 		docstring const & delimChars, docstring const & illegalChars,
 		charCase chCase) {
 
@@ -539,7 +558,7 @@ namespace {
 	/// the variable strings.
 	/// @return true if reading was successfull (all single parts were delimited
 	/// correctly)
-	bool readValue(docstring & val, ifdocstream & ifs, const VarMap & strings) {
+	bool readValue(docstring & val, std::basic_istream<char_type> & ifs, const VarMap & \
strings) {  
 		char_type ch;
 
@@ -669,48 +688,19 @@ namespace {
 
 		return true;
 	}
-}
-
-
-void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/) const
-{
-	parseBibTeXFiles();
-}
-
 
-void InsetBibtex::parseBibTeXFiles() const
-{
-	// This bibtex parser is a first step to parse bibtex files
-	// more precisely.
-	//
-	// - it reads the whole bibtex entry and does a syntax check
-	//   (matching delimiters, missing commas,...
-	// - it recovers from errors starting with the next @-character
-	// - it reads @string definitions and replaces them in the
-	//   field values.
-	// - it accepts more characters in keys or value names than
-	//   bibtex does.
-	//
-	// Officially bibtex does only support ASCII, but in practice
-	// you can use the encoding of the main document as long as
-	// some elements like keys and names are pure ASCII. Therefore
-	// we convert the file from the buffer encoding.
-	// We don't restrict keys to ASCII in LyX, since our own
-	// InsetBibitem can generate non-ASCII keys, and nonstandard
-	// 8bit clean bibtex forks exist.
+	VarMap strings;
+	public:
 
-	BiblioInfo keylist;
+	int errors;
+	int warnings;
 
-	support::FileNameList const files = getBibFiles();
-	support::FileNameList::const_iterator it = files.begin();
-	support::FileNameList::const_iterator en = files.end();
-	for (; it != en; ++ it) {
-		ifdocstream ifs(it->toFilesystemEncoding().c_str(),
-			ios_base::in, buffer().params().encoding().iconvName());
+	BibtexParser() : errors(0), warnings(0) {
+	}
 
+	void parse(std::basic_istream<char_type> & ifs, BiblioInfo & keylist) {
 		char_type ch;
-		VarMap strings;
-
+		
 		while (ifs) {
 
 			ifs.get(ch);
@@ -772,12 +762,14 @@ void InsetBibtex::parseBibTeXFiles() const
 				if (!ifs || ch != '=') {
 					lyxerr << "BibTeX Parser: No `=' after string name: " <<
 							name << "." << std::endl;
+					errors++;
 					continue;
 				}
 
 				if (!readValue(value, ifs, strings)) {
 					lyxerr << "BibTeX Parser: Unable to read value for string: " <<
 							name << "." << std::endl;
+					errors++;
 					continue;
 				}
 
@@ -824,25 +816,27 @@ void InsetBibtex::parseBibTeXFiles() const
 				BibTeXInfo keyvalmap(key, entryType);
 
 				bool readNext = removeWSAndComma(ifs);
-
 				while (ifs && readNext) {
-
 					// read field name
 					if (!readTypeOrKey(name, ifs, from_ascii("="),
-					                   from_ascii("{}(),"), makeLowerCase) || !ifs)
+					                   from_ascii("{}(),"), makeLowerCase) || !ifs) {
+						errors++;
 						break;
+					}
 
 					// next char must be an equal sign
 					// FIXME Whitespace??
 					ifs.get(ch);
 					if (!ifs) {
 						lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
+						errors++;
 						break;
 					}
 					if (ch != '=') {
 						lyxerr << "BibTeX Parser: Missing `=' after field name: " <<
 								name << ", for key: " << key << "." << std::endl;
 						ifs.putback(ch);
+						errors++;
 						break;
 					}
 
@@ -850,6 +844,7 @@ void InsetBibtex::parseBibTeXFiles() const
 					if (!readValue(value, ifs, strings)) {
 						lyxerr << "BibTeX Parser: Unable to read value for field: " <<
 								name << ", for key: " << key << "." << std::endl;
+						errors++;
 						break;
 					}
 
@@ -865,12 +860,34 @@ void InsetBibtex::parseBibTeXFiles() const
 				keylist[key] = keyvalmap;
 			} //< else (citation entry)
 		} //< searching '@'
+	}
+};
+
+
+void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/) const
+{
+	parseBibTeXFiles();
+}
+
+
+void InsetBibtex::parseBibTeXFiles() const
+{
+	support::FileNameList const files = getBibFiles();
+	support::FileNameList::const_iterator it = files.begin();
+	support::FileNameList::const_iterator en = files.end();
+	BiblioInfo keylist;
+
+	for (; it != en; ++ it) {
+		ifdocstream ifs(it->toFilesystemEncoding().c_str(),
+			ios_base::in, buffer().params().encoding().iconvName());
+		BibtexParser parser;
+		parser.parse(ifs, keylist);
+
 	} //< for loop over files
 
 	buffer().addBiblioInfo(keylist);
 }
 
-
 FileName InsetBibtex::getBibTeXPath(docstring const & filename, Buffer const & buf)
 {
 	string texfile = changeExtension(to_utf8(filename), "bib");
-- 
1.7.10.2 (Apple Git-33)


From d0151ba8868853a2bf9de135f154149914ee1363 Mon Sep 17 00:00:00 2001
From: Benjamin Piwowarski <benjamin@bpiwowar.net>
Date: Thu, 11 Oct 2012 14:20:05 +0200
Subject: [PATCH 2/5] Add a method to update a BibTeX file

---
 src/BiblioInfo.h           |    2 ++
 src/insets/InsetBibtex.cpp |   69 +++++++++++++++++++++++++++++++++++++++++++-
 src/insets/InsetBibtex.h   |    4 +++
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h
index 65d1b21..3dd036c 100644
--- a/src/BiblioInfo.h
+++ b/src/BiblioInfo.h
@@ -67,6 +67,8 @@ public:
 	///
 	const_iterator find(docstring const & f) const { return bimap_.find(f); }
 	///
+	const_iterator begin() const { return bimap_.begin(); }
+	///
 	const_iterator end() const { return bimap_.end(); }
 	/// \return value for field f
 	/// note that this will create an empty field if it does not exist
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index 4bf98be..6fdbc5f 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -11,6 +11,8 @@
 
 #include <config.h>
 
+#include <sstream>
+
 #include "InsetBibtex.h"
 
 #include "BiblioInfo.h"
@@ -882,12 +884,77 @@ void InsetBibtex::parseBibTeXFiles() const
 			ios_base::in, buffer().params().encoding().iconvName());
 		BibtexParser parser;
 		parser.parse(ifs, keylist);
-
 	} //< for loop over files
 
 	buffer().addBiblioInfo(keylist);
 }
 
+namespace {
+	void output(BiblioInfo const &keylist, ofdocstream &ofs, BiblioInfo *skip = NULL) {
+		for(BiblioInfo::const_iterator it = keylist.begin(), end = keylist.end(); it != \
end; it++) { +			const BibTeXInfo &info = it->second;
+			if (skip && skip->find(it->first) != skip->end()) {
+				continue;
+			}
+			ofs << "@" << info.entryType() << "{" << info.key() << "," << std::endl;
+			for(BibTeXInfo::const_iterator it_fields = info.begin(), end_fields = info.end(); \
it_fields != end_fields; it_fields++) { +				ofs << it_fields->first << " = "
+					<< "{" << it_fields->second << "}"
+					<< (it_fields == end_fields ? "" : ",")
+					<< std::endl;
+			}
+			ofs << "}" << std::endl << std::endl;
+		}
+	}
+}
+
+/// Update entries in a bibtex file
+bool InsetBibtex::updateEntries(support::FileName const & filename,
+	docstring const & content, std::vector<docstring> &entries) {
+
+	std::basic_stringstream<char_type> ifs(content);
+
+	// Parse the bibtex
+	BibtexParser parser;
+	BiblioInfo keylist;
+	parser.parse(ifs, keylist);
+	if (parser.errors > 0)
+		return false;
+
+	// Parse the file bibtex
+	BibtexParser parser_file;
+	BiblioInfo keylist_file;
+	ifdocstream ifs_file(filename.toFilesystemEncoding().c_str(),
+		ios_base::in, buffer().params().encoding().iconvName());
+
+	parser_file.parse(ifs_file, keylist_file);
+	if (parser.errors > 0)
+		return false;
+
+	// Now, write a new file with the keys
+	FileName tmpFilename = filename.tempName(filename.parentPath(), "lyxbib.bib");
+	ofdocstream ofs(tmpFilename.toFilesystemEncoding().c_str(), std::ios_base::out, \
buffer().params().encoding().iconvName()); +
+	// Copy strings
+	for(BibtexParser::VarMap::const_iterator it = parser_file.strings.begin(),
+		end = parser_file.strings.end(); it != end; it++) {
+		ofs << "@string{" << it->first << "={" << it->second << "}}" << std::endl << \
std::endl; +	}
+
+	// Copy entries
+	output(keylist_file, ofs, &keylist);
+	output(keylist, ofs);
+
+	// Close and replace the original file
+	ofs.close();
+	tmpFilename.moveTo(filename);
+	buffer().addBiblioInfo(keylist);
+
+	// Return keys
+	entries = keylist.getKeys();
+	return true;
+}
+
 FileName InsetBibtex::getBibTeXPath(docstring const & filename, Buffer const & buf)
 {
 	string texfile = changeExtension(to_utf8(filename), "bib");
diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h
index 3b85101..bb72902 100644
--- a/src/insets/InsetBibtex.h
+++ b/src/insets/InsetBibtex.h
@@ -72,6 +72,10 @@ public:
 		{ return s == "bibtex"; }
 	//@}
 
+	/// Update BibTeX file entries
+	/// Stores the updated entries keys in entries and returns true if everything went \
well +	bool updateEntries(support::FileName const & filename, docstring const & s, \
std::vector<docstring> & entries); +
 private:
 	/// look up the path to the file using TeX
 	static support::FileName
-- 
1.7.10.2 (Apple Git-33)


From 27eb3c953db7f99996be5e2927d3d98fb7689263 Mon Sep 17 00:00:00 2001
From: Benjamin Piwowarski <benjamin@bpiwowar.net>
Date: Thu, 11 Oct 2012 14:30:39 +0200
Subject: [PATCH 3/5] Detection and status cache of BibTeX managed files

---
 src/Buffer.cpp             |   11 +++++++----
 src/Buffer.h               |    3 +++
 src/insets/InsetBibtex.cpp |    6 ++++++
 src/insets/InsetBibtex.h   |    8 ++++++++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 8b052ad..86413cc 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -266,8 +266,8 @@ public:
 	mutable bool bibinfo_cache_valid_;
 	/// whether the bibfile cache is valid
 	mutable bool bibfile_cache_valid_;
-	/// Cache of timestamps of .bib files
-	map<FileName, time_t> bibfile_status_;
+	/// Cache of some informations (timestamp, managed) about .bib files
+	map<FileName, BibFileInfo> bibfile_status_;
 	/// Indicates whether the bibinfo has changed since the last time
 	/// we ran updateBuffer(), i.e., whether citation labels may need
 	/// to be updated.
@@ -2059,11 +2059,11 @@ void Buffer::checkIfBibInfoCacheIsValid() const
 	FileNameList::const_iterator en = bibfiles_cache.end();
 	for (; ei != en; ++ ei) {
 		time_t lastw = ei->lastModified();
-		time_t prevw = d->bibfile_status_[*ei];
+		time_t prevw = d->bibfile_status_[*ei].timestamp;
 		if (lastw != prevw) {
 			d->bibinfo_cache_valid_ = false;
 			d->cite_labels_valid_ = false;
-			d->bibfile_status_[*ei] = lastw;
+			d->bibfile_status_[*ei].timestamp = lastw;
 		}
 	}
 }
@@ -2112,6 +2112,9 @@ void Buffer::addBibTeXInfo(docstring const & key, BibTeXInfo \
const & bi) const  masterbi[key] = bi;
 }
 
+BibFileInfo & Buffer::getBibFileInfo(FileName const &filename) const {
+	return d->bibfile_status_[filename];
+}
 
 bool Buffer::citeLabelsValid() const
 {
diff --git a/src/Buffer.h b/src/Buffer.h
index 246e1ce..2ca0f67 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -61,6 +61,7 @@ class TexRow;
 class TocBackend;
 class Undo;
 class WordLangTuple;
+class BibFileInfo;
 
 namespace frontend {
 class GuiBufferDelegate;
@@ -486,6 +487,8 @@ public:
 	void addBiblioInfo(BiblioInfo const & bi) const;
 	/// add a single piece of bibliography info to our cache
 	void addBibTeXInfo(docstring const & key, BibTeXInfo const & bi) const;
+	/// Get cached information about a parsed bibtex file
+	BibFileInfo &getBibFileInfo(support::FileName const &filename) const;
 	///
 	bool citeLabelsValid() const;
 	///
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index 6fdbc5f..6181e23 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -700,6 +700,11 @@ public:
 	BibtexParser() : errors(0), warnings(0) {
 	}
 
+	bool isManaged() const {
+               VarMap::const_iterator it = \
strings.find(from_utf8("__lyx__managed__")); +               return (it != \
strings.end()) && (it->second == from_utf8("true")); +	}
+
 	void parse(std::basic_istream<char_type> & ifs, BiblioInfo & keylist) {
 		char_type ch;
 		
@@ -884,6 +889,7 @@ void InsetBibtex::parseBibTeXFiles() const
 			ios_base::in, buffer().params().encoding().iconvName());
 		BibtexParser parser;
 		parser.parse(ifs, keylist);
+		buffer().getBibFileInfo(*it).managed = parser.isManaged();
 	} //< for loop over files
 
 	buffer().addBiblioInfo(keylist);
diff --git a/src/insets/InsetBibtex.h b/src/insets/InsetBibtex.h
index bb72902..cd7a812 100644
--- a/src/insets/InsetBibtex.h
+++ b/src/insets/InsetBibtex.h
@@ -23,6 +23,14 @@ namespace support {
 	class FileNameList;
 }
 
+/** Used to cache information about parsed BibTeX files */
+struct BibFileInfo {
+	/// Last update timestamp
+	time_t timestamp;
+	/// True if the file is managed by LyX
+	bool managed;
+};
+
 /** Used to insert BibTeX's information
   */
 class InsetBibtex : public InsetCommand {
-- 
1.7.10.2 (Apple Git-33)


From a7b87bcd572137dc2d2e38f22174f45f05030c66 Mon Sep 17 00:00:00 2001
From: Benjamin Piwowarski <benjamin@bpiwowar.net>
Date: Thu, 11 Oct 2012 14:34:54 +0200
Subject: [PATCH 4/5] Method to add a set of keys to InsetCitation

---
 src/insets/InsetCitation.cpp |   25 +++++++++++++++++++++++++
 src/insets/InsetCitation.h   |    6 ++++++
 2 files changed, 31 insertions(+)

diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index fdd6e0b..d901183 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -110,6 +110,31 @@ void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
 	InsetCommand::doDispatch(cur, cmd);
 }
 
+size_t InsetCitation::addKeys(std::vector<docstring> const & keys)
+{
+	// Retrieve keys
+	vector<docstring> list = getVectorFromString(getParam("key"));
+	set<docstring> curkeys;
+	curkeys.insert(list.begin(), list.end());
+
+	// Add keys
+	size_t added = 0;
+	for(std::vector<docstring>::const_iterator it = keys.begin(), end = keys.end(); it \
!= end; it++) +		if (curkeys.find(*it) == curkeys.end()) {
+			list.push_back(*it);
+			added++;
+		}
+
+
+	// Exit now if nothing changed
+	if (added > 0) {
+		setParam("key", getStringFromVector(list));
+		cache.recalculate = true;
+	}
+
+	return added;
+}
+
 
 docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
 {
diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h
index 0cdde7b..3e28f2a 100644
--- a/src/insets/InsetCitation.h
+++ b/src/insets/InsetCitation.h
@@ -13,6 +13,10 @@
 #ifndef INSET_CITATION_H
 #define INSET_CITATION_H
 
+#include <vector>
+
+#include "support/strfwd.h"
+
 #include "InsetCommand.h"
 
 #include "Citation.h"
@@ -31,6 +35,8 @@ class InsetCitation : public InsetCommand
 public:
 	///
 	InsetCitation(Buffer * buf, InsetCommandParams const &);
+	/// Add a citation key to the inset, returning the number of added keys
+	size_t addKeys(std::vector<docstring> const & key);
 
 	/// \name Public functions inherited from Inset class
 	//@{
-- 
1.7.10.2 (Apple Git-33)


From c9cd0b271a4f2b55adbc388573ab6397e8374ca8 Mon Sep 17 00:00:00 2001
From: Benjamin Piwowarski <benjamin@bpiwowar.net>
Date: Thu, 11 Oct 2012 14:41:35 +0200
Subject: [PATCH 5/5] Add bibtex-insert LFUN

---
 src/BufferView.cpp |   83 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/FuncCode.h     |    1 +
 src/LyXAction.cpp  |    9 ++++++
 3 files changed, 93 insertions(+)

diff --git a/src/BufferView.cpp b/src/BufferView.cpp
index bb5ed50..a98b384 100644
--- a/src/BufferView.cpp
+++ b/src/BufferView.cpp
@@ -54,6 +54,7 @@
 #include "WordLangTuple.h"
 
 #include "insets/InsetBibtex.h"
+#include "insets/InsetCitation.h"
 #include "insets/InsetCommand.h" // ChangeRefs
 #include "insets/InsetExternal.h"
 #include "insets/InsetGraphics.h"
@@ -77,6 +78,8 @@
 #include "support/lstrings.h"
 #include "support/Package.h"
 #include "support/types.h"
+#include "support/FileName.h"
+#include "support/FileNameList.h"
 
 #include <cerrno>
 #include <fstream>
@@ -1168,6 +1171,12 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus \
& flag)  flag.setEnabled(lyx::getStatus(fr).enabled());
 		break;
 	}
+
+	case LFUN_BIBTEX_INSERT: {
+		flag.setEnabled(cur.inTexted());
+		break;
+	}
+
 	case LFUN_INSET_APPLY: {
 		string const name = cmd.getArg(0);
 		Inset * inset = editedInset(name);
@@ -1916,6 +1925,80 @@ void BufferView::dispatch(FuncRequest const & cmd, \
DispatchResult & dr)  break;
 	}
 
+	case LFUN_BIBTEX_INSERT: {
+		if (argument.empty()) {
+			// Must be called with an argument
+			dr.setError(true);
+			dr.setMessage("bibtex-insert should be called with an argument");
+			break;
+		}
+
+		// Find matching InsetBibtex
+		Cursor tmpcur = cur;
+		findInset(tmpcur, BIBTEX_CODE, false);
+		InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
+						BIBTEX_CODE);
+
+		// Find LyX managed bibliography
+		if (!inset) {
+			dr.setError(true);
+			dr.setMessage("Could not find a bibliography");
+			break;
+		}
+
+		support::FileNameList list = inset->getBibFiles();
+		support::FileNameList::const_iterator it = list.begin();
+		support::FileNameList::const_iterator en = list.end();
+		for (; it != en; ++ it) {
+			if (buffer().getBibFileInfo(*it).managed)
+				break;
+		}
+
+		if (it == en) {
+			// If none, could ask the user if wanting to add a LyX Managed bibliography
+			dr.setError(true);
+			dr.setMessage("Could not find a LyX managed bibliography");
+			break;
+		}
+
+		// Update bibtex entries in the bibtex file
+		std::vector<docstring> entries;
+		bool result = inset->updateEntries(*it, from_utf8(argument), entries);
+		if (!result) {
+			dr.setError(true);
+			dr.setMessage("An error occurred while updating bibtex file");
+			break;
+		}
+
+		// if our cursor is direclty in front of or behind a citation inset,
+		// we will instead add the new key to it.
+		Inset * citation_inset = cur.nextInset();
+		if (!citation_inset || citation_inset->lyxCode() != CITE_CODE)
+			citation_inset = cur.prevInset();
+		if (citation_inset && citation_inset->lyxCode() == CITE_CODE) {
+			InsetCitation & icite = dynamic_cast<InsetCitation &>(*citation_inset);
+			if (icite.addKeys(entries) > 0) {
+				dr.forceBufferUpdate();
+				dr.screenUpdate(Update::FitCursor | Update::SinglePar);
+			}
+			dispatched = true;
+			break;
+		}
+
+		// Inserts citation(s) creating a new inset
+		InsetCommandParams icp(CITE_CODE);
+		docstring key;
+		for(size_t i = 0; i < entries.size(); i++)
+			key += (i == 0 ? "" : ",") + entries[i];
+		icp["key"] = key;
+		string icstr = InsetCommand::params2string(icp);
+		FuncRequest fr(LFUN_INSET_INSERT, icstr);
+		lyx::dispatch(fr);
+
+		dispatched = true;
+		break;
+	}
+
 	case LFUN_INSET_APPLY: {
 		string const name = cmd.getArg(0);
 		Inset * inset = editedInset(name);
diff --git a/src/FuncCode.h b/src/FuncCode.h
index c5749c3..d7cc2af 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -452,6 +452,7 @@ enum FuncCode
 	// 350
 	LFUN_BRANCH_MASTER_ACTIVATE,    // spitz 20120930
 	LFUN_BRANCH_MASTER_DEACTIVATE,  // spitz 20120930
+	LFUN_BIBTEX_INSERT,             // bpiwowar 20121004
 	LFUN_LASTACTION                 // end of the table
 };
 
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index dbda5c0..c51d8d9 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -1457,6 +1457,15 @@ void LyXAction::init()
  */
 		{ LFUN_CITATION_INSERT, "citation-insert", Noop, Edit },
 /*!
+ * \var lyx::FuncCode lyx::LFUN_BIBTEX_INSERT
+ * \li Action: Inserts citations as bibtex entries and update the bibtex database
+ * \li Syntax: citation- [<BIBTEX>]
+ * \li Params: <BIBTEX>: A valid BibTeX entry. \n
+ * \li Origin: bpiwowar, 03 October 2012
+ * \endvar
+ */
+		{ LFUN_BIBTEX_INSERT, "bibtex-insert", Noop, Edit },
+/*!
  * \var lyx::FuncCode lyx::LFUN_BIBTEX_DATABASE_ADD
  * \li Action: Adds database, which will be used for bibtex citations.
  * \li Notion: Databases are added to the first BibTeX inset
-- 
1.7.10.2 (Apple Git-33)



best,
Benjamin

On Oct 26, 2012, at 15:26 , Richard Heck <rgheck@lyx.org> wrote:

> On 10/25/2012 03:30 PM, Richard Heck wrote:
> > On 10/25/2012 02:43 PM, Benjamin Piwowarski wrote:
> > > Hi,
> > > 
> > > could I have at least some feedback on the patch - I know it is not finished \
> > > yet (at least for part 5), so it would be good to validate (and maybe commit) \
> > > parts 1-4. 
> > I'll try to have a look this weekend. Just very busy.
> > 
> Let me suggest, too, that you post up-to-date versions of all five patches to this \
> list. That's the usual way to request comment. 
> rh
> 



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic