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
This commit is contained in:
Dekel Tsur 2001-01-31 20:39:53 +00:00
parent e1b7bd5d36
commit a0e6ddd7f4
7 changed files with 52 additions and 11 deletions

View 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;

View 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)

View 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>

View 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.

View 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;

View 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);
};

View File

@ -107,7 +107,9 @@ public:
///
MATHMACRO_CODE,
///
ERROR_CODE
ERROR_CODE,
///
CITE_CODE
};
///