mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 13:31:49 +00:00
* Buffer.{cpp,h}:
- rewrite LFUN_BRANCHES_RENAME with an InsetIterator approach. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30464 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
ca070ea260
commit
808dfaabea
@ -1707,9 +1707,37 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr)
|
||||
}
|
||||
|
||||
case LFUN_BRANCHES_RENAME: {
|
||||
if (func.argument().empty())
|
||||
break;
|
||||
|
||||
docstring const oldname = from_utf8(func.getArg(0));
|
||||
docstring const newname = from_utf8(func.getArg(1));
|
||||
renameBranches(oldname, newname);
|
||||
InsetIterator it = inset_iterator_begin(inset());
|
||||
InsetIterator const end = inset_iterator_end(inset());
|
||||
bool success = false;
|
||||
for (; it != end; ++it) {
|
||||
if (it->lyxCode() == BRANCH_CODE) {
|
||||
InsetBranch & ins = static_cast<InsetBranch &>(*it);
|
||||
if (ins.branch() == oldname) {
|
||||
undo().recordUndo(it);
|
||||
ins.rename(newname);
|
||||
success = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (it->lyxCode() == INCLUDE_CODE) {
|
||||
// get buffer of external file
|
||||
InsetInclude const & ins =
|
||||
static_cast<InsetInclude const &>(*it);
|
||||
Buffer * child = ins.getChildBuffer();
|
||||
if (!child)
|
||||
continue;
|
||||
child->dispatch(func, dr);
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
dr.update(Update::Force);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2413,55 +2441,6 @@ void Buffer::getUsedBranches(std::list<docstring> & result, bool const from_mast
|
||||
}
|
||||
|
||||
|
||||
void Buffer::renameBranches(docstring const & oldname, docstring const & newname)
|
||||
{
|
||||
// Iterate over buffer, starting with first paragraph
|
||||
// The scope must be bigger than any lookup DocIterator
|
||||
// later. For the global lookup, lastpit+1 is used, hence
|
||||
// we use lastpit+2 here.
|
||||
DocIterator it = par_iterator_begin();
|
||||
DocIterator scope = it;
|
||||
scope.pit() = scope.lastpit() + 2;
|
||||
pit_type lastpit = it.lastpit();
|
||||
|
||||
while (it.pit() <= lastpit) {
|
||||
Paragraph & par = it.paragraph();
|
||||
|
||||
// iterate over the insets of the current paragraph
|
||||
InsetList const & insets = par.insetList();
|
||||
InsetList::const_iterator iit = insets.begin();
|
||||
InsetList::const_iterator end = insets.end();
|
||||
for (; iit != end; ++iit) {
|
||||
it.pos() = iit->pos;
|
||||
|
||||
if (iit->inset->lyxCode() == BRANCH_CODE) {
|
||||
// get buffer of external file
|
||||
InsetBranch & br =
|
||||
static_cast<InsetBranch &>(*iit->inset);
|
||||
undo().recordUndo(it);
|
||||
if (br.branch() == oldname)
|
||||
br.rename(newname);
|
||||
continue;
|
||||
}
|
||||
|
||||
// is it an external file?
|
||||
if (iit->inset->lyxCode() == INCLUDE_CODE) {
|
||||
// get buffer of external file
|
||||
InsetInclude const & inset =
|
||||
static_cast<InsetInclude const &>(*iit->inset);
|
||||
Buffer * child = inset.getChildBuffer();
|
||||
if (!child)
|
||||
continue;
|
||||
child->renameBranches(oldname, newname);
|
||||
}
|
||||
}
|
||||
// next paragraph
|
||||
it.pit()++;
|
||||
it.pos() = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Buffer::updateMacroInstances() const
|
||||
{
|
||||
LYXERR(Debug::MACROS, "updateMacroInstances for "
|
||||
|
@ -509,8 +509,6 @@ public:
|
||||
|
||||
/// return a list of all used branches (also in children)
|
||||
void getUsedBranches(std::list<docstring> &, bool const from_master = false) const;
|
||||
/// rename all branches of \p oldname in the buffer to \p newname.
|
||||
void renameBranches(docstring const & oldname, docstring const & newname);
|
||||
|
||||
/// sets the buffer_ member for every inset in this buffer.
|
||||
// FIXME This really shouldn't be needed, but at the moment it's not
|
||||
|
Loading…
Reference in New Issue
Block a user