Inset::addToToc(): change signature. Use DocIterator instead of ParConstIterator. The idea is to have more accurate navigation in the paragraph. But this doesn't work yet.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24747 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2008-05-13 08:23:44 +00:00
parent 842587a1a6
commit 1e51e87f68
27 changed files with 64 additions and 65 deletions

View File

@ -22,6 +22,7 @@
#include "Layout.h"
#include "LyXAction.h"
#include "Paragraph.h"
#include "ParIterator.h"
#include "TextClass.h"
#include "insets/InsetOptArg.h"
@ -43,15 +44,15 @@ namespace lyx {
//
///////////////////////////////////////////////////////////////////////////
TocItem::TocItem(ParConstIterator const & par_it, int d, docstring const & s)
: par_it_(par_it), depth_(d), str_(s)
TocItem::TocItem(DocIterator const & dit, int d, docstring const & s)
: dit_(dit), depth_(d), str_(s)
{
}
int TocItem::id() const
{
return par_it_->id();
return dit_.paragraph().id();
}
@ -101,7 +102,7 @@ Toc & TocBackend::toc(string const & type)
}
void TocBackend::updateItem(ParConstIterator const & par_it)
void TocBackend::updateItem(DocIterator const & dit)
{
if (toc("tableofcontents").empty()) {
// FIXME: should not happen,
@ -113,32 +114,33 @@ void TocBackend::updateItem(ParConstIterator const & par_it)
BufferParams const & bufparams = buffer_->params();
const int min_toclevel = bufparams.documentClass().min_toclevel();
TocIterator toc_item = item("tableofcontents", par_it);
TocIterator toc_item = item("tableofcontents", dit);
docstring tocstring;
// For each paragraph, traverse its insets and let them add
// their toc items
InsetList::const_iterator it = toc_item->par_it_->insetList().begin();
InsetList::const_iterator end = toc_item->par_it_->insetList().end();
Paragraph & par = toc_item->dit_.paragraph();
InsetList::const_iterator it = par.insetList().begin();
InsetList::const_iterator end = par.insetList().end();
for (; it != end; ++it) {
Inset & inset = *it->inset;
if (inset.lyxCode() == OPTARG_CODE) {
if (!tocstring.empty())
break;
Paragraph const & par =
Paragraph const & inset_par =
*static_cast<InsetOptArg&>(inset).paragraphs().begin();
if (!toc_item->par_it_->labelString().empty())
tocstring = toc_item->par_it_->labelString() + ' ';
tocstring += par.asString(false);
if (!par.labelString().empty())
tocstring = par.labelString() + ' ';
tocstring += inset_par.asString(false);
break;
}
}
int const toclevel = toc_item->par_it_->layout().toclevel;
int const toclevel = par.layout().toclevel;
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel
&& tocstring.empty())
tocstring = toc_item->par_it_->asString(true);
tocstring = par.asString(true);
const_cast<TocItem &>(*toc_item).str_ = tocstring;
}
@ -165,6 +167,7 @@ void TocBackend::update()
InsetList::const_iterator end = pit->insetList().end();
for (; it != end; ++it) {
Inset & inset = *it->inset;
pit.pos() = it->pos;
//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
inset.addToToc(pit);
switch (inset.lyxCode()) {
@ -198,7 +201,7 @@ void TocBackend::update()
TocIterator TocBackend::item(string const & type,
ParConstIterator const & par_it) const
DocIterator const & dit) const
{
TocList::const_iterator toclist_it = tocs_.find(type);
// Is the type supported?
@ -212,7 +215,7 @@ TocIterator TocBackend::item(string const & type,
--it;
ParConstIterator par_it_text = par_it;
ParConstIterator par_it_text(dit);
if (par_it_text.inMathed()) {
// We are only interested in text so remove the math CursorSlice.
while (par_it_text.inMathed())
@ -223,9 +226,9 @@ TocIterator TocBackend::item(string const & type,
// We verify that we don't compare contents of two
// different document. This happens when you
// have parent and child documents.
if (&it->par_it_[0].inset() != &par_it_text[0].inset())
if (&it->dit_[0].inset() != &par_it_text[0].inset())
continue;
if (it->par_it_ <= par_it_text)
if (it->dit_ <= par_it_text)
return it;
}

View File

@ -14,7 +14,7 @@
#ifndef TOC_BACKEND_H
#define TOC_BACKEND_H
#include "ParIterator.h"
#include "DocIterator.h"
#include "support/strfwd.h"
@ -39,7 +39,7 @@ public:
/// Default constructor for STL containers.
TocItem() {}
///
TocItem(ParConstIterator const & par_it,
TocItem(DocIterator const & dit,
int depth,
docstring const & s
);
@ -59,7 +59,7 @@ public:
protected:
/// Current position of item.
ParConstIterator par_it_;
DocIterator dit_;
/// nesting depth
int depth_;
@ -92,7 +92,7 @@ public:
///
void update();
///
void updateItem(ParConstIterator const & pit);
void updateItem(DocIterator const & pit);
///
TocList const & tocs() const { return tocs_; }
@ -105,7 +105,7 @@ public:
/// Return the first Toc Item before the cursor
TocIterator item(
std::string const & type, ///< Type of Toc.
ParConstIterator const & ///< The cursor location in the document.
DocIterator const & dit ///< The cursor location in the document.
) const;
///

View File

@ -42,6 +42,7 @@
#include "LyX.h" // for lastfiles
#include "LyXFunc.h"
#include "Paragraph.h"
#include "ParIterator.h"
#include "Session.h"
#include "TextClass.h"
#include "TocBackend.h"

View File

@ -436,7 +436,7 @@ public:
virtual void addPreview(graphics::PreviewLoader &) const {}
/// Add an entry to the TocList
/// pit is the ParConstIterator of the paragraph containing the inset
virtual void addToToc(ParConstIterator const &) const {}
virtual void addToToc(DocIterator const &) {}
/// Fill keys with BibTeX information
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {}
/// Update the counters of this inset and of its contents

View File

@ -102,16 +102,16 @@ void InsetCaption::setCustomLabel(docstring const & label)
}
void InsetCaption::addToToc(ParConstIterator const & cpit) const
void InsetCaption::addToToc(DocIterator const & cpit)
{
if (type_.empty())
return;
ParConstIterator pit = cpit;
pit.push_back(*this);
DocIterator pit = cpit;
pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc(type_);
docstring const str = full_label_ + ". " + pit->asString(false);
docstring const str = full_label_ + ". " + text_.getPar(0).asString(false);
toc.push_back(TocItem(pit, 0, str));
}

View File

@ -71,7 +71,7 @@ private:
///
void setCustomLabel(docstring const & label);
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
virtual bool forceEmptyLayout(idx_type = 0) const { return true; }
/// Captions don't accept alignment, spacing, etc.

View File

@ -427,7 +427,7 @@ void InsetCitation::updateLabels(ParIterator const &)
}
void InsetCitation::addToToc(ParConstIterator const & cpit) const
void InsetCitation::addToToc(DocIterator const & cpit)
{
Toc & toc = buffer().tocBackend().toc("citation");
toc.push_back(TocItem(cpit, 0, cache.screen_label));

View File

@ -54,7 +54,7 @@ public:
///
void updateLabels(ParIterator const & it);
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
static ParamInfo const & findInfo(std::string const &);

View File

@ -64,13 +64,12 @@ void InsetFoot::updateLabels(ParIterator const & it)
}
void InsetFoot::addToToc(ParConstIterator const & cpit) const
void InsetFoot::addToToc(DocIterator const & cpit)
{
ParConstIterator pit = cpit;
pit.push_back(*this);
DocIterator pit = cpit;
pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("footnote");
// FIXME: we probably want the footnote number too.
docstring str;
str = custom_label_ + ": " + getNewLabel(str);
toc.push_back(TocItem(pit, 0, str));

View File

@ -42,7 +42,7 @@ private:
/// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &);
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
docstring toolTip(BufferView const & bv, int x, int y) const;
///

View File

@ -907,7 +907,7 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
}
void InsetGraphics::addToToc(ParConstIterator const & cpit) const
void InsetGraphics::addToToc(DocIterator const & cpit)
{
TocBackend & backend = buffer().tocBackend();

View File

@ -105,7 +105,7 @@ private:
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
docstring contextMenu(BufferView const & bv, int x, int y) const;
/// Force inset into LTR environment if surroundings are RTL?

View File

@ -880,7 +880,7 @@ void InsetInclude::addPreview(graphics::PreviewLoader & ploader) const
}
void InsetInclude::addToToc(ParConstIterator const & cpit) const
void InsetInclude::addToToc(DocIterator const & cpit)
{
TocBackend & backend = buffer().tocBackend();
@ -895,8 +895,8 @@ void InsetInclude::addToToc(ParConstIterator const & cpit) const
Toc & toc = backend.toc("listing");
docstring str = convert<docstring>(toc.size() + 1)
+ ". " + from_utf8(caption);
ParConstIterator pit = cpit;
pit.push_back(*this);
DocIterator pit = cpit;
pit.push_back(CursorSlice(*this));
toc.push_back(TocItem(pit, 0, str));
return;
}

View File

@ -84,7 +84,7 @@ public:
///
void addPreview(graphics::PreviewLoader &) const;
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
void updateLabels(ParIterator const &);
///

View File

@ -93,10 +93,10 @@ void InsetIndex::write(ostream & os) const
}
void InsetIndex::addToToc(ParConstIterator const & cpit) const
void InsetIndex::addToToc(DocIterator const & cpit)
{
ParConstIterator pit = cpit;
pit.push_back(*this);
DocIterator pit = cpit;
pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("index");
docstring str;

View File

@ -41,7 +41,7 @@ private:
/// should paragraph indendation be omitted in any case?
bool neverIndent() const { return true; }
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
Inset * clone() const { return new InsetIndex(*this); }
};

View File

@ -111,7 +111,7 @@ void InsetLabel::updateLabels(ParIterator const &)
}
void InsetLabel::addToToc(ParConstIterator const & cpit) const
void InsetLabel::addToToc(DocIterator const & cpit)
{
docstring const & label = getParam("name");
Toc & toc = buffer().tocBackend().toc("label");
@ -124,7 +124,7 @@ void InsetLabel::addToToc(ParConstIterator const & cpit) const
Buffer::References::const_iterator it = refs.begin();
Buffer::References::const_iterator end = refs.end();
for (; it != end; ++it) {
ParConstIterator const ref_pit(it->second);
DocIterator const ref_pit(it->second);
toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel()));
}
}

View File

@ -53,7 +53,7 @@ public:
///
void updateLabels(ParIterator const & it);
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
void updateCommand(docstring const & new_label, bool updaterefs = true);
protected:

View File

@ -66,10 +66,10 @@ int InsetMarginal::docbook(odocstream & os,
}
void InsetMarginal::addToToc(ParConstIterator const & cpit) const
void InsetMarginal::addToToc(DocIterator const & cpit)
{
ParConstIterator pit = cpit;
pit.push_back(*this);
DocIterator pit = cpit;
pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("marginalnote");
docstring str;

View File

@ -39,7 +39,7 @@ public:
///
docstring editMessage() const;
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
private:
///
Inset * clone() const { return new InsetMarginal(*this); }

View File

@ -221,10 +221,10 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
}
void InsetNote::addToToc(ParConstIterator const & cpit) const
void InsetNote::addToToc(DocIterator const & cpit)
{
ParConstIterator pit = cpit;
pit.push_back(*this);
DocIterator pit = cpit;
pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("note");
docstring str;

View File

@ -95,7 +95,7 @@ private:
///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
void doDispatch(Cursor & cur, FuncRequest & cmd);
///

View File

@ -142,7 +142,7 @@ void InsetRef::updateLabels(ParIterator const & it)
}
void InsetRef::addToToc(ParConstIterator const & cpit) const
void InsetRef::addToToc(DocIterator const & cpit)
{
docstring const & label = getParam("reference");
if (buffer().insetLabel(label))

View File

@ -67,7 +67,7 @@ public:
///
void updateLabels(ParIterator const & it);
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
protected:
///
InsetRef(InsetRef const &);

View File

@ -423,7 +423,7 @@ ParagraphList & InsetText::paragraphs()
}
//void InsetInclude::addToToc(ParConstIterator const & cpit) const
//void InsetInclude::addToToc(DocIterator const & cpit)
//{
//}

View File

@ -236,7 +236,7 @@ void InsetMathHull::updateLabels(ParIterator const & it)
}
void InsetMathHull::addToToc(ParConstIterator const & pit) const
void InsetMathHull::addToToc(DocIterator const & pit)
{
if (!buffer_) {
//FIXME: buffer_ should be set at creation for this inset! Problem is
@ -245,10 +245,6 @@ void InsetMathHull::addToToc(ParConstIterator const & pit) const
return;
}
// FIXME: it would be way better to directly use InsetLabel instead of this
// label list. But it should be possible to copy&paste the code in
// InsetLabel::addToToc() anyway.
Toc & toc = buffer().tocBackend().toc("equation");
for (row_type row = 0; row != nrows(); ++row) {

View File

@ -38,7 +38,7 @@ public:
///
void updateLabels(ParIterator const &);
///
void addToToc(ParConstIterator const &) const;
void addToToc(DocIterator const &);
///
InsetMathHull & operator=(InsetMathHull const &);
///