reintroduce LFUN_BIBDB_ADD and LFUN BIBDB_DEL (bug 961)

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10104 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2005-06-25 15:57:15 +00:00
parent 7e5a71a8eb
commit 361de37399
8 changed files with 103 additions and 32 deletions

View File

@ -51,6 +51,7 @@
#include "undo.h"
#include "vspace.h"
#include "insets/insetbibtex.h"
#include "insets/insetref.h"
#include "insets/insettext.h"
@ -122,7 +123,7 @@ boost::signals::connection selectioncon;
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)
{
@ -982,6 +983,8 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
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;
@ -1213,6 +1216,26 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
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()) {

View File

@ -1,3 +1,16 @@
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

View File

@ -188,6 +188,8 @@ void LyXAction::init()
{ 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 },

View File

@ -213,56 +213,73 @@ CurStatus status(BufferView const * bv, DocIterator const & dit)
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();

View File

@ -51,13 +51,20 @@ CurStatus status(BufferView const * bv, DocIterator const & dit);
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

View File

@ -1,3 +1,9 @@
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 "

View File

@ -271,7 +271,7 @@ void InsetBibtex::fillWithBibKeys(Buffer const & buffer,
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);
@ -283,16 +283,17 @@ bool InsetBibtex::addDatabase(string const & 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;
}

View File

@ -355,6 +355,8 @@ enum kb_action {
// 270
LFUN_WORDS_COUNT,
LFUN_OUTPUT_CHANGES, // jspitzm 20050121
LFUN_BIBDB_ADD,
LFUN_BIBDB_DEL,
LFUN_LASTACTION // end of the table
};