mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 05:25:26 +00:00
Fix bug 2744:
* buffer.[Ch] (changeRefsIfUnique): extend to handle bibitems as well (the function takes a InsetCode argument now); clean up by using InsetIterator. * InsetMathHull.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/trunk@15289 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
e7a64fb3e4
commit
05be07de9e
46
src/buffer.C
46
src/buffer.C
@ -68,9 +68,9 @@
|
||||
#include "support/lyxalgo.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/fs_extras.h"
|
||||
# include <boost/iostreams/filtering_stream.hpp>
|
||||
# include <boost/iostreams/filter/gzip.hpp>
|
||||
# include <boost/iostreams/device/file.hpp>
|
||||
#include <boost/iostreams/filtering_stream.hpp>
|
||||
#include <boost/iostreams/filter/gzip.hpp>
|
||||
#include <boost/iostreams/device/file.hpp>
|
||||
namespace io = boost::iostreams;
|
||||
#include "support/lyxlib.h"
|
||||
#include "support/os.h"
|
||||
@ -83,9 +83,9 @@ namespace io = boost::iostreams;
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
|
||||
#if defined (HAVE_UTIME_H)
|
||||
# include <utime.h>
|
||||
#include <utime.h>
|
||||
#elif defined (HAVE_SYS_UTIME_H)
|
||||
# include <sys/utime.h>
|
||||
#include <sys/utime.h>
|
||||
#endif
|
||||
|
||||
#include <iomanip>
|
||||
@ -1556,31 +1556,31 @@ 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)
|
||||
{
|
||||
//FIXME: This does not work for child documents yet.
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -340,7 +340,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);
|
||||
/// get source code (latex/docbook) for some paragraphs, or all paragraphs
|
||||
/// including preamble
|
||||
void getSourceCode(std::ostream & os, lyx::pit_type par_begin, lyx::pit_type par_end, bool full_source);
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "insetbibitem.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "BufferView.h"
|
||||
#include "dispatchresult.h"
|
||||
#include "funcrequest.h"
|
||||
#include "lyxfont.h"
|
||||
@ -63,11 +64,14 @@ void InsetBibitem::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
case LFUN_INSET_MODIFY: {
|
||||
InsetCommandParams p;
|
||||
InsetCommandMailer::string2params("bibitem", lyx::to_utf8(cmd.argument()), p);
|
||||
if (!p.getCmdName().empty())
|
||||
setParams(p);
|
||||
else
|
||||
cur.noUpdate();
|
||||
break;
|
||||
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);
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -25,17 +25,22 @@
|
||||
#include "support/fs_extras.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/exception.hpp>
|
||||
|
||||
using lyx::support::ascii_lowercase;
|
||||
using lyx::support::contains;
|
||||
using lyx::support::getStringFromVector;
|
||||
using lyx::support::getVectorFromString;
|
||||
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;
|
||||
@ -437,3 +442,13 @@ 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));
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -149,6 +149,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)
|
||||
|
@ -69,6 +69,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(); }
|
||||
|
@ -69,7 +69,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;
|
||||
}
|
||||
|
@ -1121,7 +1121,8 @@ void InsetMathHull::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;
|
||||
|
Loading…
Reference in New Issue
Block a user