2006-04-26 13:34:35 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file TocBackend.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Abdelrazak Younes
|
2015-09-01 16:08:35 +00:00
|
|
|
* \author Guillaume Munch
|
2006-04-26 13:34:35 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TOC_BACKEND_H
|
|
|
|
#define TOC_BACKEND_H
|
|
|
|
|
2008-05-13 08:23:44 +00:00
|
|
|
#include "DocIterator.h"
|
2015-09-27 06:05:00 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "OutputEnums.h"
|
2016-01-08 19:06:50 +00:00
|
|
|
#include "Toc.h"
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/strfwd.h"
|
2016-06-02 20:40:11 +00:00
|
|
|
#include "support/unique_ptr.h"
|
2006-11-11 00:35:14 +00:00
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
#include <stack>
|
2008-02-09 09:08:59 +00:00
|
|
|
|
2006-11-11 00:35:14 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
class Buffer;
|
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
|
|
|
|
/* FIXME: toc types are currently identified by strings. It cannot be converted
|
|
|
|
* into an enum because of the user-configurable indexing categories and
|
|
|
|
* the user-definable float types provided by layout files.
|
|
|
|
*
|
|
|
|
* I leave this for documentation purposes for the moment.
|
|
|
|
*
|
|
|
|
enum TocType {
|
|
|
|
TABLE_OF_CONTENTS,//"tableofcontents"
|
|
|
|
CHILD,//"child"
|
|
|
|
GRAPHICS,//"graphics"
|
|
|
|
NOTE,//"note"
|
|
|
|
BRANCH,//"branch"
|
|
|
|
CHANGE,//"change"
|
|
|
|
LABEL,//"label"
|
|
|
|
CITATION,//"citation"
|
|
|
|
EQUATION,//"equation"
|
|
|
|
FOOTNOTE,//"footnote"
|
|
|
|
MARGINAL_NOTE,//"marginalnote"
|
|
|
|
INDEX,//"index", "index:<user-str>" (from interface)
|
|
|
|
NOMENCL,//"nomencl"
|
|
|
|
LISTING,//"listings"
|
|
|
|
FLOAT,//"figure", "table", "algorithm", user-defined (from layout?)
|
2015-10-02 18:44:36 +00:00
|
|
|
MATH_MACRO,//"math-macro"
|
2015-10-04 18:48:31 +00:00
|
|
|
EXTERNAL,//"external"
|
2015-09-01 16:08:35 +00:00
|
|
|
SENSELESS,//"senseless"
|
|
|
|
TOC_TYPE_COUNT
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
|
|
|
/**
|
|
|
|
*/
|
2006-11-13 16:53:49 +00:00
|
|
|
class TocItem
|
2006-04-26 13:34:35 +00:00
|
|
|
{
|
2006-11-13 16:53:49 +00:00
|
|
|
friend class TocBackend;
|
2015-09-27 06:05:00 +00:00
|
|
|
friend class TocBuilder;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
2007-06-12 12:29:19 +00:00
|
|
|
/// Default constructor for STL containers.
|
2015-09-13 17:47:21 +00:00
|
|
|
TocItem() : dit_(0), depth_(0), output_(false) {}
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-05-13 08:23:44 +00:00
|
|
|
TocItem(DocIterator const & dit,
|
2016-06-06 19:02:49 +00:00
|
|
|
int depth,
|
|
|
|
docstring const & s,
|
|
|
|
bool output_active,
|
|
|
|
FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
|
|
|
|
);
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
|
|
|
~TocItem() {}
|
|
|
|
///
|
2007-09-16 10:36:57 +00:00
|
|
|
int id() const;
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
2015-09-01 16:08:35 +00:00
|
|
|
int depth() const { return depth_; }
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
2015-09-01 16:08:35 +00:00
|
|
|
docstring const & str() const { return str_; }
|
|
|
|
///
|
|
|
|
void str(docstring const & s) { str_ = s; }
|
2015-09-27 06:05:00 +00:00
|
|
|
/// String for display, e.g. it has a mark if output is inactive
|
2006-11-13 16:53:49 +00:00
|
|
|
docstring const asString() const;
|
2009-04-09 18:42:59 +00:00
|
|
|
///
|
2015-09-01 16:08:35 +00:00
|
|
|
DocIterator const & dit() const { return dit_; }
|
2013-03-08 21:18:26 +00:00
|
|
|
///
|
|
|
|
bool isOutput() const { return output_; }
|
2015-09-27 06:05:00 +00:00
|
|
|
///
|
|
|
|
void setAction(FuncRequest a) { action_ = a; }
|
|
|
|
/// custom action, or the default one (paragraph-goto) if not customised
|
2006-11-13 16:53:49 +00:00
|
|
|
FuncRequest action() const;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
protected:
|
|
|
|
/// Current position of item.
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator dit_;
|
2015-09-27 06:05:00 +00:00
|
|
|
|
|
|
|
private:
|
2006-11-13 16:53:49 +00:00
|
|
|
/// nesting depth
|
|
|
|
int depth_;
|
|
|
|
/// Full item string
|
|
|
|
docstring str_;
|
2013-03-08 21:18:26 +00:00
|
|
|
/// Is this item in a note, inactive branch, etc?
|
|
|
|
bool output_;
|
2015-09-27 06:05:00 +00:00
|
|
|
/// Custom action
|
|
|
|
FuncRequest action_;
|
2006-11-13 16:53:49 +00:00
|
|
|
};
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
/// Caption-enabled TOC builders
|
|
|
|
class TocBuilder
|
|
|
|
{
|
|
|
|
public:
|
2016-06-26 16:22:59 +00:00
|
|
|
TocBuilder(std::shared_ptr<Toc> const toc);
|
2015-09-01 16:08:35 +00:00
|
|
|
/// When entering a float
|
|
|
|
void pushItem(DocIterator const & dit, docstring const & s,
|
2016-06-02 20:40:11 +00:00
|
|
|
bool output_active, bool is_captioned = false);
|
2015-09-01 16:08:35 +00:00
|
|
|
/// When encountering a caption
|
|
|
|
void captionItem(DocIterator const & dit, docstring const & s,
|
2016-06-02 20:40:11 +00:00
|
|
|
bool output_active);
|
2015-09-01 16:08:35 +00:00
|
|
|
/// When exiting a float
|
|
|
|
void pop();
|
|
|
|
private:
|
|
|
|
TocBuilder(){}
|
|
|
|
///
|
|
|
|
struct frame {
|
2015-09-20 17:24:45 +00:00
|
|
|
Toc::size_type pos;
|
2015-09-01 16:08:35 +00:00
|
|
|
bool is_captioned;
|
|
|
|
};
|
|
|
|
///
|
2016-06-26 16:22:59 +00:00
|
|
|
std::shared_ptr<Toc> const toc_;
|
2015-09-01 16:08:35 +00:00
|
|
|
///
|
|
|
|
std::stack<frame> stack_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-02 20:40:11 +00:00
|
|
|
/// Class to build and access the Tocs of a particular buffer.
|
2006-11-13 16:53:49 +00:00
|
|
|
class TocBackend
|
|
|
|
{
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
2016-01-08 19:06:50 +00:00
|
|
|
static Toc::const_iterator findItem(Toc const & toc,
|
|
|
|
DocIterator const & dit);
|
|
|
|
/// Look for a TocItem given its depth and string.
|
|
|
|
/// \return The first matching item.
|
|
|
|
/// \retval end() if no item was found.
|
|
|
|
static Toc::iterator findItem(Toc & toc, int depth, docstring const & str);
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-02-27 22:33:10 +00:00
|
|
|
TocBackend(Buffer const * buffer) : buffer_(buffer) {}
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-02-09 09:08:59 +00:00
|
|
|
void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2015-09-27 06:05:00 +00:00
|
|
|
void update(bool output_active, UpdateType utype);
|
2008-09-26 10:37:24 +00:00
|
|
|
/// \return true if the item was updated.
|
|
|
|
bool updateItem(DocIterator const & pit);
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-02-09 09:08:59 +00:00
|
|
|
TocList const & tocs() const { return tocs_; }
|
2015-09-01 16:08:35 +00:00
|
|
|
/// never null
|
2016-06-26 16:22:59 +00:00
|
|
|
std::shared_ptr<Toc const> toc(std::string const & type) const;
|
2016-06-02 20:40:11 +00:00
|
|
|
/// never null
|
2016-06-26 16:22:59 +00:00
|
|
|
std::shared_ptr<Toc> toc(std::string const & type);
|
2016-06-02 20:40:11 +00:00
|
|
|
/// \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;
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2008-02-09 09:08:59 +00:00
|
|
|
///
|
2013-03-08 19:52:18 +00:00
|
|
|
void writePlaintextTocList(std::string const & type,
|
|
|
|
odocstringstream & os, size_t max_length) const;
|
2015-11-03 16:47:25 +00:00
|
|
|
///
|
|
|
|
docstring outlinerName(std::string const & type) const;
|
2006-04-26 13:34:35 +00:00
|
|
|
|
|
|
|
private:
|
2007-05-28 22:27:45 +00:00
|
|
|
///
|
2006-04-26 13:34:35 +00:00
|
|
|
TocList tocs_;
|
|
|
|
///
|
2016-06-02 20:40:11 +00:00
|
|
|
std::map<std::string, unique_ptr<TocBuilder>> builders_;
|
2015-09-01 16:08:35 +00:00
|
|
|
///
|
2006-04-26 13:34:35 +00:00
|
|
|
Buffer const * buffer_;
|
|
|
|
}; // TocBackend
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // TOC_BACKEND_H
|