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

View File

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

View File

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

View File

@ -436,7 +436,7 @@ public:
virtual void addPreview(graphics::PreviewLoader &) const {} virtual void addPreview(graphics::PreviewLoader &) const {}
/// Add an entry to the TocList /// Add an entry to the TocList
/// pit is the ParConstIterator of the paragraph containing the inset /// 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 /// Fill keys with BibTeX information
virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {} virtual void fillWithBibKeys(BiblioInfo &, InsetIterator const &) const {}
/// Update the counters of this inset and of its contents /// 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()) if (type_.empty())
return; return;
ParConstIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(*this); pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc(type_); 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)); toc.push_back(TocItem(pit, 0, str));
} }

View File

@ -71,7 +71,7 @@ private:
/// ///
void setCustomLabel(docstring const & label); void setCustomLabel(docstring const & label);
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
/// ///
virtual bool forceEmptyLayout(idx_type = 0) const { return true; } virtual bool forceEmptyLayout(idx_type = 0) const { return true; }
/// Captions don't accept alignment, spacing, etc. /// 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 & toc = buffer().tocBackend().toc("citation");
toc.push_back(TocItem(cpit, 0, cache.screen_label)); toc.push_back(TocItem(cpit, 0, cache.screen_label));

View File

@ -54,7 +54,7 @@ public:
/// ///
void updateLabels(ParIterator const & it); void updateLabels(ParIterator const & it);
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
/// ///
static ParamInfo const & findInfo(std::string 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; DocIterator pit = cpit;
pit.push_back(*this); pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("footnote"); Toc & toc = buffer().tocBackend().toc("footnote");
// FIXME: we probably want the footnote number too.
docstring str; docstring str;
str = custom_label_ + ": " + getNewLabel(str); str = custom_label_ + ": " + getNewLabel(str);
toc.push_back(TocItem(pit, 0, 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 /// Update the counters of this inset and of its contents
void updateLabels(ParIterator const &); void updateLabels(ParIterator const &);
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
/// ///
docstring toolTip(BufferView const & bv, int x, int y) 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(); TocBackend & backend = buffer().tocBackend();

View File

@ -105,7 +105,7 @@ private:
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; 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; docstring contextMenu(BufferView const & bv, int x, int y) const;
/// Force inset into LTR environment if surroundings are RTL? /// 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(); TocBackend & backend = buffer().tocBackend();
@ -895,8 +895,8 @@ void InsetInclude::addToToc(ParConstIterator const & cpit) const
Toc & toc = backend.toc("listing"); Toc & toc = backend.toc("listing");
docstring str = convert<docstring>(toc.size() + 1) docstring str = convert<docstring>(toc.size() + 1)
+ ". " + from_utf8(caption); + ". " + from_utf8(caption);
ParConstIterator pit = cpit; DocIterator pit = cpit;
pit.push_back(*this); pit.push_back(CursorSlice(*this));
toc.push_back(TocItem(pit, 0, str)); toc.push_back(TocItem(pit, 0, str));
return; return;
} }

View File

@ -84,7 +84,7 @@ public:
/// ///
void addPreview(graphics::PreviewLoader &) const; void addPreview(graphics::PreviewLoader &) const;
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
/// ///
void updateLabels(ParIterator 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; DocIterator pit = cpit;
pit.push_back(*this); pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("index"); Toc & toc = buffer().tocBackend().toc("index");
docstring str; docstring str;

View File

@ -41,7 +41,7 @@ private:
/// should paragraph indendation be omitted in any case? /// should paragraph indendation be omitted in any case?
bool neverIndent() const { return true; } bool neverIndent() const { return true; }
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
/// ///
Inset * clone() const { return new InsetIndex(*this); } 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"); docstring const & label = getParam("name");
Toc & toc = buffer().tocBackend().toc("label"); 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 it = refs.begin();
Buffer::References::const_iterator end = refs.end(); Buffer::References::const_iterator end = refs.end();
for (; it != end; ++it) { 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())); toc.push_back(TocItem(ref_pit, 1, it->first->screenLabel()));
} }
} }

View File

@ -53,7 +53,7 @@ public:
/// ///
void updateLabels(ParIterator const & it); void updateLabels(ParIterator const & it);
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
/// ///
void updateCommand(docstring const & new_label, bool updaterefs = true); void updateCommand(docstring const & new_label, bool updaterefs = true);
protected: 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; DocIterator pit = cpit;
pit.push_back(*this); pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("marginalnote"); Toc & toc = buffer().tocBackend().toc("marginalnote");
docstring str; docstring str;

View File

@ -39,7 +39,7 @@ public:
/// ///
docstring editMessage() const; docstring editMessage() const;
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
private: private:
/// ///
Inset * clone() const { return new InsetMarginal(*this); } 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; DocIterator pit = cpit;
pit.push_back(*this); pit.push_back(CursorSlice(*this));
Toc & toc = buffer().tocBackend().toc("note"); Toc & toc = buffer().tocBackend().toc("note");
docstring str; docstring str;

View File

@ -95,7 +95,7 @@ private:
/// ///
bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const; bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
/// ///
void doDispatch(Cursor & cur, FuncRequest & cmd); 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"); docstring const & label = getParam("reference");
if (buffer().insetLabel(label)) if (buffer().insetLabel(label))

View File

@ -67,7 +67,7 @@ public:
/// ///
void updateLabels(ParIterator const & it); void updateLabels(ParIterator const & it);
/// ///
void addToToc(ParConstIterator const &) const; void addToToc(DocIterator const &);
protected: protected:
/// ///
InsetRef(InsetRef const &); 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_) { if (!buffer_) {
//FIXME: buffer_ should be set at creation for this inset! Problem is //FIXME: buffer_ should be set at creation for this inset! Problem is
@ -245,10 +245,6 @@ void InsetMathHull::addToToc(ParConstIterator const & pit) const
return; 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"); Toc & toc = buffer().tocBackend().toc("equation");
for (row_type row = 0; row != nrows(); ++row) { for (row_type row = 0; row != nrows(); ++row) {

View File

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