]> git.lyx.org Git - features.git/commitdiff
Update citations if the insetbib key has changed.
authorDekel Tsur <dekelts@tau.ac.il>
Wed, 31 Jan 2001 20:39:53 +0000 (20:39 +0000)
committerDekel Tsur <dekelts@tau.ac.il>
Wed, 31 Jan 2001 20:39:53 +0000 (20:39 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1434 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.h
src/BufferView2.C
src/ChangeLog
src/insets/ChangeLog
src/insets/insetbib.C
src/insets/insetcite.h
src/insets/lyxinset.h

index 6bf6350d14e253b5431ada779e426f4977b3d371..3300eef6bb11dda58eb8b5b0ec821a64fc239bdf 100644 (file)
@@ -257,10 +257,13 @@ public:
        void leaveView();
 #endif
        ///
-       bool ChangeRefs(string const & from, string const & to);
+       bool ChangeInsets(Inset::Code code, string const & from, 
+                         string const & to);
        ///
        bool ChangeRefsIfUnique(string const & from, string const & to);
        ///
+       bool ChangeCitationsIfUnique(string const & from, string const & to);
+       ///
        void pasteClipboard(bool asPara);
        ///
        void stuffClipboard(string const &) const;
index 24258b3dfa7cf1e260aceae5930f32d4470e40a6..37c6d948b401b52c4828e94ce400ac30c4211590 100644 (file)
@@ -31,6 +31,7 @@
 #include "LaTeX.h"
 #include "BufferView_pimpl.h"
 #include "insets/insetcommand.h" //ChangeRefs
+#include "support/lyxfunctional.h" //equal_1st_in_pair
 
 extern BufferList bufferlist;
 
@@ -40,6 +41,7 @@ using std::ifstream;
 using std::vector;
 using std::find;
 using std::count;
+using std::count_if;
 
 // Inserts a file into current document
 bool BufferView::insertLyXFile(string const & filen)
@@ -879,7 +881,7 @@ void BufferView::updateInset(Inset * inset, bool mark_dirty)
 }
 
 
-bool BufferView::ChangeRefs(string const & from, string const & to)
+bool BufferView::ChangeInsets(Inset::Code code, string const & from, string const & to)
 {
        bool flag = false;
        LyXParagraph * par = buffer()->paragraph;
@@ -897,7 +899,7 @@ bool BufferView::ChangeRefs(string const & from, string const & to)
                bool flag2 = false;
                for (LyXParagraph::inset_iterator it = par->inset_iterator_begin();
                     it != par->inset_iterator_end(); ++it) {
-                       if ((*it)->LyxCode() == Inset::REF_CODE) {
+                       if ((*it)->LyxCode() == code) {
                                InsetCommand * inset = static_cast<InsetCommand *>(*it);
                                if (inset->getContents() == from) {
                                        inset->setContents(to);
@@ -934,10 +936,22 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
        if (count(labels.begin(), labels.end(), from) > 1)
                return false;
 
-       return ChangeRefs(from, to);
+       return ChangeInsets(Inset::REF_CODE, from, to);
 }
 
 
+bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
+{
+
+       vector<pair<string,string> > keys = buffer()->getBibkeyList();  
+       if (count_if(keys.begin(), keys.end(), 
+                    equal_1st_in_pair<string,string>(from)) 
+           > 1)
+               return false;
+
+       return ChangeInsets(Inset::CITE_CODE, from, to);
+}
+
 UpdatableInset * BufferView::theLockingInset() const
 {
        // If NULL is not allowed we should put an Assert here. (Lgb)
index 554311276a7e0854ef79b5ee74298813d4ef12e8..c4cdf8fef14ba5624e064190d0d1249e939b27e4 100644 (file)
@@ -1,5 +1,9 @@
 2001-01-31  Dekel Tsur  <dekelts@tau.ac.il>
 
+       * BufferView2.C (ChangeInsets): Renamed from ChangeRefs. Accept a
+       new argument (code).
+       (ChangeCitationsIfUnique): New method.
+
        * paragraph.C (GetPositionOfInset): Handle bibkey.
 
 2001-01-29  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
index 03ae50b178893d8c18267f86fc2b17b1e367adfe..dd163d6d39b6c5f4991449d0d33870cb16653301 100644 (file)
@@ -1,3 +1,7 @@
+2001-01-31  Dekel Tsur  <dekelts@tau.ac.il>
+
+       * insetbib.C (callback): Update citations if the key has changed.
+
 2001-01-31  Dekel Tsur  <dekelts@tau.ac.il>
 
        * insetbib.C (InsetBibKey): Better computation of default key.
index 4f54ecd0bf0118e073ac113b019e7acab4e8de53..c481ef05a8e1e2589524b4eeb6805bb108627bc3 100644 (file)
@@ -110,19 +110,31 @@ void InsetBibKey::callback( FD_bibitem_form * form, long data )
 {
        switch (data) {
        case 1:
+       {
                // Do NOT change this to
                // holder.view->buffer() as this code is used by both
                // InsetBibKey and InsetBibtex! Ughhhhhhh!!!!
-               if (!current_view->buffer()->isReadonly()) {
-                       setContents(fl_get_input(form->key));
-                       setOptions(fl_get_input(form->label));
-                       // shouldn't mark the buffer dirty unless
-                       // something was actually altered
-                       current_view->updateInset( this, true );
+               if (current_view->buffer()->isReadonly()) {
+                       WarnReadonly(current_view->buffer()->fileName());
+                       break;
+               }
+
+               string key = fl_get_input(form->key);
+               string label = fl_get_input(form->label);
+               if (key != getContents())
+                       current_view->ChangeCitationsIfUnique(getContents(),
+                                                             key);
+
+               if (key != getContents() || label != getOptions()) {
+                       setContents(key);
+                       setOptions(label);
+                       current_view->updateInset(this, true);
                        // We need to do a redraw becuase the maximum 
                        // InsetBibKey width could have changed.
                        current_view->redraw();
+                       current_view->fitCursor(getLyXText(current_view));
                } // fall through to Cancel
+       }
        case 0:
                fl_hide_form(form->bibitem_form);
                break;
index 8fa126caa52a7c9e100b43e4340350fdf294ac4d..3f896677f8e485f720c99863621ba3ac6a627b1f 100644 (file)
@@ -31,6 +31,8 @@ public:
        string const getScreenLabel() const;
        ///
        EDITABLE Editable() const { return IS_EDITABLE; }
+       ///
+       Inset::Code LyxCode() const { return Inset::CITE_CODE; }
         ///
        void Edit(BufferView *, int, int, unsigned int);
 };
index a8b2d2cc73a36fd7b08ddbb9b5bbb0122d31bdd9..9e1136089d9ccec9b974391eb800b2ee68a94342 100644 (file)
@@ -107,7 +107,9 @@ public:
                ///
                MATHMACRO_CODE,
                ///
-               ERROR_CODE
+               ERROR_CODE,
+               ///
+               CITE_CODE
        };
 
        ///