* 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
#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"
#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>
}
-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);
}
}
}
///
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);
#include "insetbibitem.h"
#include "buffer.h"
+#include "BufferView.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "lyxfont.h"
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:
#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;
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));
+ }
+}
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
}
+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)
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(); }
}
if (p.getContents() != params().getContents())
cur.bv().buffer()->changeRefsIfUnique(params().getContents(),
- p.getContents());
+ p.getContents(), InsetBase::REF_CODE);
setParams(p);
break;
}
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;