From a0e6ddd7f4ddb8511864ac297c3416173f1dff2b Mon Sep 17 00:00:00 2001 From: Dekel Tsur Date: Wed, 31 Jan 2001 20:39:53 +0000 Subject: [PATCH] Update citations if the insetbib key has changed. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1434 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.h | 5 ++++- src/BufferView2.C | 20 +++++++++++++++++--- src/ChangeLog | 4 ++++ src/insets/ChangeLog | 4 ++++ src/insets/insetbib.C | 24 ++++++++++++++++++------ src/insets/insetcite.h | 2 ++ src/insets/lyxinset.h | 4 +++- 7 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/BufferView.h b/src/BufferView.h index 6bf6350d14..3300eef6bb 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -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; diff --git a/src/BufferView2.C b/src/BufferView2.C index 24258b3dfa..37c6d948b4 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -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(*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 > keys = buffer()->getBibkeyList(); + if (count_if(keys.begin(), keys.end(), + equal_1st_in_pair(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) diff --git a/src/ChangeLog b/src/ChangeLog index 554311276a..c4cdf8fef1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2001-01-31 Dekel Tsur + * 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 diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 03ae50b178..dd163d6d39 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,7 @@ +2001-01-31 Dekel Tsur + + * insetbib.C (callback): Update citations if the key has changed. + 2001-01-31 Dekel Tsur * insetbib.C (InsetBibKey): Better computation of default key. diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 4f54ecd0bf..c481ef05a8 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -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; diff --git a/src/insets/insetcite.h b/src/insets/insetcite.h index 8fa126caa5..3f896677f8 100644 --- a/src/insets/insetcite.h +++ b/src/insets/insetcite.h @@ -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); }; diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index a8b2d2cc73..9e1136089d 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -107,7 +107,9 @@ public: /// MATHMACRO_CODE, /// - ERROR_CODE + ERROR_CODE, + /// + CITE_CODE }; ///