Fix bug 2744:

* buffer.[Ch] (changeRefsIfUnique): extend to handle bibitems 
	as well	(the function takes a InsetCode argument now) [bug 2744];
	clean up by using InsetIterator.

* math_hullinset.C (doDispatch): changeRefsIfUnique needs a
	InsetCode argument now (bug 2744).

* insetlabel (doDispatch): changeRefsIfUnique needs a
	InsetCode argument now.

* insetbibitem (doDispatch): use changeRefsIfUnique
	(actual fix for bug 2744).

* insetcommand.[Ch]:
* insetcite.[Ch]: implement replaceContents, which is
	used by changeRefsIfUnique.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_4_X@15282 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2006-10-09 09:52:07 +00:00
parent 294109c66a
commit 11b7b84d1f
13 changed files with 80 additions and 25 deletions

View File

@ -1,3 +1,9 @@
2006-10-09 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* buffer.[Ch] (changeRefsIfUnique): extend to handle bibitems
as well (the function takes a InsetCode argument now) [bug 2744];
clean up by using InsetIterator.
2006-09-21 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* lyxfunc.C (getStatus): fix handling of LFUN_RUNCHKTEX (bug 2831)

View File

@ -67,7 +67,7 @@
#include "support/lyxalgo.h"
#include "support/filetools.h"
#include "support/fs_extras.h"
# include "support/gzstream.h"
#include "support/gzstream.h"
#include "support/lyxlib.h"
#include "support/os.h"
#include "support/path.h"
@ -1612,31 +1612,30 @@ void Buffer::saveCursor(StableDocIterator cur, StableDocIterator anc)
}
void Buffer::changeRefsIfUnique(string const & from, string const & to)
void Buffer::changeRefsIfUnique(string const & from, string const & to, InsetBase::Code code)
{
BOOST_ASSERT(code == InsetBase::CITE_CODE || code == InsetBase::REF_CODE);
// Check if the label 'from' appears more than once
vector<string> labels;
getLabelList(labels);
if (code == InsetBase::CITE_CODE) {
vector<pair<string, string> > keys;
fillWithBibKeys(keys);
vector<pair<string, string> >::const_iterator bit = keys.begin();
vector<pair<string, string> >::const_iterator bend = keys.end();
for (; bit != bend; ++bit)
labels.push_back(bit->first);
} else
getLabelList(labels);
if (lyx::count(labels.begin(), labels.end(), from) > 1)
return;
InsetBase::Code code = InsetBase::REF_CODE;
ParIterator it = par_iterator_begin();
ParIterator end = par_iterator_end();
for ( ; it != end; ++it) {
bool changed_inset = false;
for (InsetList::iterator it2 = it->insetlist.begin();
it2 != it->insetlist.end(); ++it2) {
if (it2->inset->lyxCode() == code) {
InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
if (inset->getContents() == from) {
inset->setContents(to);
//inset->setButtonLabel();
changed_inset = true;
}
}
for (InsetIterator it = inset_iterator_begin(inset()); it; ++it) {
if (it->lyxCode() == code) {
InsetCommand & inset = dynamic_cast<InsetCommand &>(*it);
inset.replaceContents(from, to);
}
}
}

View File

@ -343,7 +343,7 @@ public:
///
StableDocIterator getAnchor() const { return anchor_; }
///
void changeRefsIfUnique(std::string const & from, std::string const & to);
void changeRefsIfUnique(std::string const & from, std::string const & to, InsetBase::Code code);
private:
/** Inserts a file into a document

View File

@ -1,3 +1,15 @@
2006-10-09 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetlabel (doDispatch): changeRefsIfUnique needs a
InsetCode argument now.
* insetbibitem (doDispatch): use changeRefsIfUnique
(actual fix for bug 2744).
* insetcommand.[Ch]:
* insetcite.[Ch]: implement replaceContents, which is
used by changeRefsIfUnique.
2006-10-03 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetvspace.C (doDispatch): open dialog on mouse release,

View File

@ -61,10 +61,14 @@ void InsetBibitem::doDispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_INSET_MODIFY: {
InsetCommandParams p;
InsetCommandMailer::string2params("bibitem", cmd.argument, p);
if (!p.getCmdName().empty())
setParams(p);
else
if (p.getCmdName().empty()) {
cur.noUpdate();
break;
}
if (p.getContents() != params().getContents())
cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
p.getContents(), InsetBase::CITE_CODE);
setParams(p);
break;
}

View File

@ -28,14 +28,19 @@
#include <boost/filesystem/operations.hpp>
#include <algorithm>
using lyx::support::ascii_lowercase;
using lyx::support::contains;
using lyx::support::getVectorFromString;
using lyx::support::getStringFromVector;
using lyx::support::ltrim;
using lyx::support::rtrim;
using lyx::support::split;
using lyx::support::tokenPos;
using std::endl;
using std::replace;
using std::string;
using std::ostream;
using std::vector;
@ -430,3 +435,14 @@ void InsetCitation::validate(LaTeXFeatures & features) const
break;
}
}
void InsetCitation::replaceContents(string const & from, string const & to)
{
if (tokenPos(getContents(), ',', from) != -1) {
vector<string> items = getVectorFromString(getContents());
replace(items.begin(), items.end(), from, to);
setContents(getStringFromVector(items));
}
}

View File

@ -43,6 +43,8 @@ public:
OutputParams const &) const;
///
void validate(LaTeXFeatures &) const;
///
void replaceContents(std::string const & from, std::string const & to);
private:
virtual std::auto_ptr<InsetBase> doClone() const

View File

@ -156,6 +156,13 @@ bool InsetCommand::getStatus(LCursor & cur, FuncRequest const & cmd,
}
void InsetCommand::replaceContents(std::string const & from, string const & to)
{
if (getContents() == from)
setContents(to);
}
InsetCommandMailer::InsetCommandMailer(string const & name,
InsetCommand & inset)
: name_(name), inset_(inset)

View File

@ -72,6 +72,8 @@ public:
p_.setContents(c);
}
///
virtual void replaceContents(std::string const & from, std::string const & to);
///
std::string const & getOptions() const { return p_.getOptions(); }
///
std::string const & getSecOptions() const { return p_.getSecOptions(); }

View File

@ -71,7 +71,7 @@ void InsetLabel::doDispatch(LCursor & cur, FuncRequest & cmd)
}
if (p.getContents() != params().getContents())
cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
p.getContents());
p.getContents(), InsetBase::REF_CODE);
setParams(p);
break;
}

View File

@ -1,3 +1,8 @@
2006-10-09 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* math_hullinset.C (doDispatch): changeRefsIfUnique needs a
InsetCode argument now (bug 2744).
2006-09-25 Enrico Forestieri <forenr@tlc.unipr.it>
* math_symbolinset.C (maxima): newer maxima versions use inf

View File

@ -1078,7 +1078,7 @@ void MathHullInset::doDispatch(LCursor & cur, FuncRequest & cmd)
numbered(r, true);
string old = label(r);
if (str != old) {
cur.bv().buffer()->changeRefsIfUnique(old, str);
cur.bv().buffer()->changeRefsIfUnique(old, str, InsetBase::REF_CODE);
label(r, str);
}
break;

View File

@ -40,6 +40,8 @@ What's new
- Support lgathered and rgathered math environments.
- Update bibliography references when the entry has been changed (bug 2744).
* User Interface:
- Fix a crash that occured on exit if the clipboard was not empty (only on