#include "undo.h"
#include "vspace.h"
+#include "insets/insetbibtex.h"
#include "insets/insetref.h"
#include "insets/insettext.h"
boost::signals::connection lostcon;
-/// Get next inset of this class from current cursor position
+/// Return an inset of this class if it exists at the current cursor position
template <class T>
T * getInsetByCode(LCursor & cur, InsetBase::Code code)
{
case LFUN_MARK_ON:
case LFUN_SETMARK:
case LFUN_CENTER:
+ case LFUN_BIBDB_ADD:
+ case LFUN_BIBDB_DEL:
case LFUN_WORDS_COUNT:
flag.enabled(true);
break;
center();
break;
+ case LFUN_BIBDB_ADD: {
+ LCursor tmpcur = cursor_;
+ bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
+ InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
+ InsetBase::BIBTEX_CODE);
+ if (inset)
+ inset->addDatabase(cmd.argument);
+ break;
+ }
+
+ case LFUN_BIBDB_DEL: {
+ LCursor tmpcur = cursor_;
+ bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
+ InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
+ InsetBase::BIBTEX_CODE);
+ if (inset)
+ inset->delDatabase(cmd.argument);
+ break;
+ }
+
case LFUN_WORDS_COUNT: {
DocIterator from, to;
if (cur.selection()) {
+2005-06-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
+
+ * BufferView_pimpl.C:
+ * LyXAction.C:
+ * lfuns.h: reintroduce LFUN_BIBDB_ADD and LFUN_BIBDB_DEL (bug 961)
+
+ * bufferview_funcs.[Ch] (gotoNextInset): rename to findNextInset;
+ (findInset): new functions, refactored from goto Inset that return
+ the position of a certain inset without setting the buffer's cursor
+ (by Jean-Marc);
+ (gotoInset): rewrite to call findInset and then set the cursor
+ (by Jean-Marc).
+
2005-06-16 Angus Leeming <leeming@lyx.org>
* lyxrc.C (output, read): wrap all input and output of paths with
{ LFUN_INSERT_LABEL, "label-insert", Noop },
{ LFUN_INSET_OPTARG, "optional-insert", Noop },
{ LFUN_INSERT_BIBITEM, "bibitem-insert", Noop },
+ { LFUN_BIBDB_ADD, "bibtex-database-add", Noop },
+ { LFUN_BIBDB_DEL, "bibtex-database-del", Noop },
{ LFUN_INSERT_LINE, "line-insert", Noop },
{ LFUN_INSERT_PAGEBREAK, "pagebreak-insert", Noop },
{ LFUN_LANGUAGE, "language", Noop },
namespace {
-bool gotoNextInset(LCursor & cur,
+bool findNextInset(DocIterator & dit,
vector<InsetBase_code> const & codes,
string const & contents)
{
- LCursor tmpcur = cur;
+ DocIterator tmpdit = dit;
- while (tmpcur) {
- InsetBase const * inset = tmpcur.nextInset();
+ while (tmpdit) {
+ InsetBase const * inset = tmpdit.nextInset();
if (inset
&& find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()
&& (contents.empty() ||
static_cast<InsetCommand const *>(inset)->getContents() == contents)) {
- cur = tmpcur;
+ dit = tmpdit;
return true;
}
- tmpcur.forwardInset();
+ tmpdit.forwardInset();
}
return false;
}
-}
+} // namespace anon
-void gotoInset(BufferView * bv, vector<InsetBase_code> const & codes,
+bool findInset(DocIterator & dit, vector<InsetBase_code> const & codes,
bool same_content)
{
string contents;
- LCursor tmpcur = bv->cursor();
- tmpcur.forwardInset();
+ DocIterator tmpdit = dit;
+ tmpdit.forwardInset();
if (same_content) {
- InsetBase const * inset = tmpcur.nextInset();
+ InsetBase const * inset = tmpdit.nextInset();
if (inset
&& find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end()) {
contents = static_cast<InsetCommand const *>(inset)->getContents();
}
}
- if (!gotoNextInset(tmpcur, codes, contents)) {
- if (bv->cursor() != doc_iterator_begin(bv->buffer()->inset())) {
- tmpcur.reset(tmpcur.bottom().inset());
- if (!gotoNextInset(tmpcur, codes, contents)) {
- bv->cursor().message(_("No more insets"));
- return;
+ if (!findNextInset(tmpdit, codes, contents)) {
+ if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
+ tmpdit = doc_iterator_begin(tmpdit.bottom().inset());
+ if (!findNextInset(tmpdit, codes, contents)) {
+ return false;
}
- } else {
- bv->cursor().message(_("No more insets"));
- return;
- }
+ } else
+ return false;
+ }
+
+ dit = tmpdit;
+ return true;
+}
+
+
+void findInset(DocIterator & dit, InsetBase_code code, bool same_content)
+{
+ findInset(dit, vector<InsetBase_code>(1, code), same_content);
+}
+
+
+void gotoInset(BufferView * bv, vector<InsetBase_code> const & codes,
+ bool same_content)
+{
+ LCursor tmpcur = bv->cursor();
+ if (!findInset(tmpcur, codes, same_content)) {
+ bv->cursor().message(_("No more insets"));
+ return;
}
tmpcur.clearSelection();
Point coordOffset(DocIterator const & dit);
-// Moves cursor to the next inset with one of the given codes.
+/// Moves cursor to the next inset with one of the given codes.
void gotoInset(BufferView * bv, std::vector<InsetBase_code> const & codes,
bool same_content);
-// Moves cursor to the next inset with given code.
+/// Moves cursor to the next inset with given code.
void gotoInset(BufferView * bv, InsetBase_code code, bool same_content);
+/// Looks for next inset with one of the the given code
+bool findInset(DocIterator & dit, std::vector<InsetBase_code> const & codes,
+ bool same_content);
+
+/// Looks for next inset with the given code
+void findInset(DocIterator & dit, InsetBase_code code, bool same_content);
+
} // namespace bv_funcs
+2005-06-25 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
+
+ * insetbibtex.C: (addDatabase): do not check for substrings but
+ but for whole tokens.
+ (delDatabase): make it actually work.
+
2005-06-21 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* insetgraphics.C (stripExtensionIfPossible): adjust test for "
bool InsetBibtex::addDatabase(string const & db)
{
string contents(getContents());
- if (!contains(contents, db)) {
+ if (tokenPos(contents, ',', db) == -1) {
if (!contents.empty())
contents += ',';
setContents(contents + db);
bool InsetBibtex::delDatabase(string const & db)
{
- if (contains(getContents(), db)) {
+ string contents(getContents());
+ if (contains(contents, db)) {
+ int const n = tokenPos(contents, ',', db);
string bd = db;
- int const n = tokenPos(getContents(), ',', bd);
if (n > 0) {
- // Weird code, would someone care to explain this?(Lgb)
- string tmp(", ");
- tmp += bd;
- setContents(subst(getContents(), tmp, ", "));
+ // this is not the first database
+ string tmp = ',' + bd;
+ setContents(subst(contents, tmp, ""));
} else if (n == 0)
- setContents(split(getContents(), bd, ','));
+ // this is the first (or only) database
+ setContents(split(contents, bd, ','));
else
return false;
}
// 270
LFUN_WORDS_COUNT,
LFUN_OUTPUT_CHANGES, // jspitzm 20050121
+ LFUN_BIBDB_ADD,
+ LFUN_BIBDB_DEL,
LFUN_LASTACTION // end of the table
};