mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Toc: clean-up
This commit is contained in:
parent
6144bbfbf8
commit
aedc6720c7
@ -49,9 +49,9 @@ namespace lyx {
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TocItem::TocItem(DocIterator const & dit, int d, docstring const & s,
|
||||
bool output_active, docstring const & t, FuncRequest action) :
|
||||
dit_(dit), depth_(d), str_(s), tooltip_(t), output_(output_active),
|
||||
action_(action)
|
||||
bool output_active, docstring const & t, FuncRequest action)
|
||||
: dit_(dit), depth_(d), str_(s), tooltip_(t), output_(output_active),
|
||||
action_(action)
|
||||
{
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ TocBuilder::TocBuilder(shared_ptr<Toc> toc)
|
||||
}
|
||||
|
||||
void TocBuilder::pushItem(DocIterator const & dit, docstring const & s,
|
||||
bool output_active, bool is_captioned)
|
||||
bool output_active, bool is_captioned)
|
||||
{
|
||||
toc_->push_back(TocItem(dit, stack_.size(), s, output_active));
|
||||
frame f = {
|
||||
@ -171,7 +171,7 @@ void TocBuilder::pushItem(DocIterator const & dit, docstring const & s,
|
||||
}
|
||||
|
||||
void TocBuilder::captionItem(DocIterator const & dit, docstring const & s,
|
||||
bool output_active)
|
||||
bool output_active)
|
||||
{
|
||||
// first show the float before moving to the caption
|
||||
docstring arg = "paragraph-goto " + paragraph_goto_arg(dit);
|
||||
@ -207,23 +207,6 @@ void TocBuilder::pop()
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TocBuilderStore implementation
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
shared_ptr<TocBuilder> TocBuilderStore::get(string const & type,
|
||||
shared_ptr<Toc> toc)
|
||||
{
|
||||
map_t::const_iterator it = map_.find(type);
|
||||
if (it == map_.end())
|
||||
it = map_.insert(make_pair(type, make_shared<TocBuilder>(toc))).first;
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TocBackend implementation
|
||||
@ -241,16 +224,17 @@ shared_ptr<Toc const> TocBackend::toc(string const & type) const
|
||||
|
||||
shared_ptr<Toc> TocBackend::toc(string const & type)
|
||||
{
|
||||
TocList::const_iterator it = tocs_.find(type);
|
||||
if (it == tocs_.end())
|
||||
it = tocs_.insert(make_pair(type, make_shared<Toc>())).first;
|
||||
return it->second;
|
||||
// std::map::insert only really performs the insertion if the key is not
|
||||
// already bound, and otherwise returns an iterator to the element already
|
||||
// there, see manual.
|
||||
return tocs_.insert({type, make_shared<Toc>()}).first->second;
|
||||
}
|
||||
|
||||
|
||||
shared_ptr<TocBuilder> TocBackend::builder(string const & type)
|
||||
TocBuilder & TocBackend::builder(string const & type)
|
||||
{
|
||||
return builders_.get(type, toc(type));
|
||||
auto p = make_unique<TocBuilder>(toc(type));
|
||||
return * builders_.insert(make_pair(type, move(p))).first->second;
|
||||
}
|
||||
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "Toc.h"
|
||||
|
||||
#include "support/strfwd.h"
|
||||
#include "support/unique_ptr.h"
|
||||
|
||||
#include <stack>
|
||||
|
||||
@ -74,12 +75,11 @@ public:
|
||||
TocItem() : dit_(0), depth_(0), output_(false) {}
|
||||
///
|
||||
TocItem(DocIterator const & dit,
|
||||
int depth,
|
||||
docstring const & s,
|
||||
bool output_active,
|
||||
docstring const & t = docstring(),
|
||||
FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
|
||||
);
|
||||
int depth,
|
||||
docstring const & s,
|
||||
bool output_active,
|
||||
docstring const & t = docstring(),
|
||||
FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION));
|
||||
///
|
||||
~TocItem() {}
|
||||
///
|
||||
@ -128,10 +128,10 @@ public:
|
||||
TocBuilder(shared_ptr<Toc> const toc);
|
||||
/// When entering a float
|
||||
void pushItem(DocIterator const & dit, docstring const & s,
|
||||
bool output_active, bool is_captioned = false);
|
||||
bool output_active, bool is_captioned = false);
|
||||
/// When encountering a caption
|
||||
void captionItem(DocIterator const & dit, docstring const & s,
|
||||
bool output_active);
|
||||
bool output_active);
|
||||
/// When exiting a float
|
||||
void pop();
|
||||
private:
|
||||
@ -148,24 +148,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
class TocBuilderStore
|
||||
{
|
||||
public:
|
||||
TocBuilderStore() {};
|
||||
///
|
||||
shared_ptr<TocBuilder> get(std::string const & type, shared_ptr<Toc> toc);
|
||||
///
|
||||
void clear() { map_.clear(); };
|
||||
private:
|
||||
typedef std::map<std::string, shared_ptr<TocBuilder>> map_t;
|
||||
map_t map_;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/**
|
||||
*/
|
||||
/// Class to build and access the Tocs of a particular buffer.
|
||||
class TocBackend
|
||||
{
|
||||
public:
|
||||
@ -187,14 +170,16 @@ public:
|
||||
TocList const & tocs() const { return tocs_; }
|
||||
/// never null
|
||||
shared_ptr<Toc const> toc(std::string const & type) const;
|
||||
/// never null
|
||||
shared_ptr<Toc> toc(std::string const & type);
|
||||
/// nevel null
|
||||
shared_ptr<TocBuilder> builder(std::string const & type);
|
||||
/// Return the first Toc Item before the cursor
|
||||
Toc::const_iterator item(
|
||||
std::string const & type, ///< Type of Toc.
|
||||
DocIterator const & dit ///< The cursor location in the document.
|
||||
) const;
|
||||
/// \return the current TocBuilder for the Toc of type \param type, or
|
||||
/// creates one if it does not already exist.
|
||||
TocBuilder & builder(std::string const & type);
|
||||
/// \return the first Toc Item before the cursor.
|
||||
/// \param type: Type of Toc.
|
||||
/// \param dit: The cursor location in the document.
|
||||
Toc::const_iterator
|
||||
item(std::string const & type, DocIterator const & dit) const;
|
||||
|
||||
///
|
||||
void writePlaintextTocList(std::string const & type,
|
||||
@ -206,7 +191,7 @@ private:
|
||||
///
|
||||
TocList tocs_;
|
||||
///
|
||||
TocBuilderStore builders_;
|
||||
std::map<std::string, unique_ptr<TocBuilder>> builders_;
|
||||
///
|
||||
Buffer const * buffer_;
|
||||
}; // TocBackend
|
||||
|
@ -107,7 +107,7 @@ void InsetCaption::addToToc(DocIterator const & cpit, bool output_active,
|
||||
str = full_label_;
|
||||
text().forOutliner(str, length);
|
||||
}
|
||||
buffer().tocBackend().builder(type)->captionItem(pit, str, output_active);
|
||||
buffer().tocBackend().builder(type).captionItem(pit, str, output_active);
|
||||
// Proceed with the rest of the inset.
|
||||
InsetText::addToToc(cpit, output_active, utype);
|
||||
}
|
||||
|
@ -55,11 +55,11 @@ void InsetCaptionable::addToToc(DocIterator const & cpit, bool output_active,
|
||||
// non-empty.
|
||||
if (utype != OutputUpdate)
|
||||
text().forOutliner(str, TOC_ENTRY_LENGTH);
|
||||
shared_ptr<TocBuilder> b = buffer().tocBackend().builder(caption_type_);
|
||||
b->pushItem(pit, str, output_active);
|
||||
TocBuilder & b = buffer().tocBackend().builder(caption_type_);
|
||||
b.pushItem(pit, str, output_active);
|
||||
// Proceed with the rest of the inset.
|
||||
InsetCollapsable::addToToc(cpit, output_active, utype);
|
||||
b->pop();
|
||||
b.pop();
|
||||
}
|
||||
|
||||
void InsetCaptionable::updateBuffer(ParIterator const & it, UpdateType utype)
|
||||
|
Loading…
Reference in New Issue
Block a user