* "Goto label" in reference dialog works with master and child documents

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27590 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-11-16 21:28:06 +00:00
parent ffa48ab035
commit 412f520892
3 changed files with 68 additions and 14 deletions

View File

@ -101,6 +101,7 @@
#include <fstream>
#include <iomanip>
#include <map>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
@ -124,6 +125,8 @@ typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
} // namespace anon
class BufferSet : public std::set<Buffer const *> {};
class Buffer::Impl
{
public:
@ -1682,12 +1685,38 @@ void Buffer::setParent(Buffer const * buffer)
}
Buffer const * Buffer::parent()
Buffer const * Buffer::parent() const
{
return d->parent_buffer;
}
void Buffer::collectRelatives(BufferSet & bufs) const
{
bufs.insert(this);
if (parent())
parent()->collectRelatives(bufs);
// loop over children
Impl::BufferPositionMap::iterator it = d->children_positions.begin();
Impl::BufferPositionMap::iterator end = d->children_positions.end();
for (; it != end; ++it)
bufs.insert(const_cast<Buffer *>(it->first));
}
std::vector<Buffer const *> Buffer::allRelatives() const
{
BufferSet bufs;
collectRelatives(bufs);
BufferSet::iterator it = bufs.begin();
std::vector<Buffer const *> ret;
for (; it != bufs.end(); ++it)
ret.push_back(*it);
return ret;
}
Buffer const * Buffer::masterBuffer() const
{
if (!d->parent_buffer)
@ -1703,6 +1732,16 @@ bool Buffer::isChild(Buffer * child) const
}
DocIterator Buffer::firstChildPosition(Buffer const * child)
{
Impl::BufferPositionMap::iterator it;
it = d->children_positions.find(child);
if (it == d->children_positions.end())
return DocIterator();
return it->second;
}
template<typename M>
typename M::iterator greatest_below(M & m, typename M::key_type const & x)
{

View File

@ -26,6 +26,7 @@ namespace lyx {
class BiblioInfo;
class BufferParams;
class BufferSet;
class DocIterator;
class ErrorItem;
class ErrorList;
@ -272,7 +273,10 @@ public:
/// Set document's parent Buffer.
void setParent(Buffer const *);
Buffer const * parent();
Buffer const * parent() const;
// Collect all relative buffer
std::vector<Buffer const *> allRelatives() const;
/** Get the document's master (or \c this if this is not a
child document)
@ -359,6 +363,9 @@ public:
///
ParConstIterator par_iterator_end() const;
// Position of the child buffer where it appears first in the master.
DocIterator firstChildPosition(Buffer const * child);
/** \returns true only when the file is fully loaded.
* Used to prevent the premature generation of previews
* and by the citation inset.
@ -482,6 +489,9 @@ private:
void updateMacros(DocIterator & it,
DocIterator & scope) const;
///
void collectRelatives(BufferSet & bufs) const;
///
bool readFileHelper(support::FileName const & s);
///

View File

@ -1074,16 +1074,14 @@ bool BufferView::dispatch(FuncRequest const & cmd)
docstring label = cmd.argument();
if (label.empty()) {
InsetRef * inset =
getInsetByCode<InsetRef>(d->cursor_,
REF_CODE);
getInsetByCode<InsetRef>(d->cursor_, REF_CODE);
if (inset) {
label = inset->getParam("reference");
// persistent=false: use temp_bookmark
saveBookmark(0);
}
}
if (!label.empty())
if (!label.empty())
gotoLabel(label);
break;
}
@ -1809,15 +1807,22 @@ bool BufferView::setCursorFromInset(Inset const * inset)
void BufferView::gotoLabel(docstring const & label)
{
Toc & toc = buffer().tocBackend().toc("label");
TocIterator toc_it = toc.begin();
TocIterator end = toc.end();
for (; toc_it != end; ++toc_it) {
if (label == toc_it->str())
dispatch(toc_it->action());
std::vector<Buffer const *> bufs = buffer().allRelatives();
std::vector<Buffer const *>::iterator it = bufs.begin();
for (; it != bufs.end(); ++it) {
Buffer const * buf = *it;
// find label
Toc & toc = buf->tocBackend().toc("label");
TocIterator toc_it = toc.begin();
TocIterator end = toc.end();
for (; toc_it != end; ++toc_it) {
if (label == toc_it->str()) {
dispatch(toc_it->action());
return;
}
}
}
//FIXME: We could do a bit more searching thanks to this:
//InsetLabel const * inset = buffer_.insetLabel(label);
}