#include <fstream>
#include <iomanip>
#include <map>
+#include <set>
#include <sstream>
#include <stack>
#include <vector>
} // namespace anon
+class BufferSet : public std::set<Buffer const *> {};
+
class Buffer::Impl
{
public:
}
-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)
}
+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)
{
class BiblioInfo;
class BufferParams;
+class BufferSet;
class DocIterator;
class ErrorItem;
class ErrorList;
/// 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)
///
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.
void updateMacros(DocIterator & it,
DocIterator & scope) const;
+ ///
+ void collectRelatives(BufferSet & bufs) const;
+
///
bool readFileHelper(support::FileName const & s);
///
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;
}
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);
}