]> git.lyx.org Git - features.git/commitdiff
reintroduce LFUN_BIBDB_ADD and LFUN BIBDB_DEL (bug 961)
authorJürgen Spitzmüller <spitz@lyx.org>
Sat, 25 Jun 2005 15:57:15 +0000 (15:57 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sat, 25 Jun 2005 15:57:15 +0000 (15:57 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10104 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView_pimpl.C
src/ChangeLog
src/LyXAction.C
src/bufferview_funcs.C
src/bufferview_funcs.h
src/insets/ChangeLog
src/insets/insetbibtex.C
src/lfuns.h

index bf2bc7a40d6ebfa73b88e47395049fca36efc028..35ccdb24c50d9cd1c744c82d62f20b4ebe960b92 100644 (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()) {
index a3ae5a0b40da5dd211094f4879bea5d00a11123d..fbaf80acceb7aaf24451cfdf33f9fbcff14be33b 100644 (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
index f803537ef2df62302ab916025f782cc336f0df9e..18d98f60c1136071105b7a80e0226cb28b3894ab 100644 (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 },
index 3135a75461e8840ff99790c423f703b3ca6526e8..d550b7318475f933026e6a31f2a9dba414a5bf1e 100644 (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();
index 1f77007ab5ccf52d50bcbcd4ed68c02ddecda821..291119a1ea340ba59ca3cb3068f50e25ae75b03f 100644 (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
 
index ca7960c82d34571c48ff8126ee327bca670b19d7..f5b7a25904e3f1a231d72b4bb44abca8df493a04 100644 (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 "
index 0fde04aa1f214110cfdbe5541dc7f44c32352ea8..df3f6bde4b231f4a8b26d93420b1e287b942d2da 100644 (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;
        }
index 7de4043b9866d03fd71e70ef989d0a31db17d221..fc930af6b01a7a9115afbca7796be0a45050405b 100644 (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
 };