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"
|
2017-01-09 22:15:16 +00:00
|
|
|
#include "TocBuilder.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
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
class Buffer;
|
|
|
|
|
2017-01-09 22:15:16 +00:00
|
|
|
/* Toc types are described by strings. They cannot be converted into an enum
|
|
|
|
* because of the user-configurable categories for index and the user-definable
|
|
|
|
* toc types provided in layout files.
|
|
|
|
*
|
|
|
|
* Here is a summary of built-in toc types
|
|
|
|
*
|
|
|
|
* Non-customizable (used without TocBuilder): "tableofcontents", "change",
|
|
|
|
* "citation", "label", "senseless".
|
|
|
|
*
|
|
|
|
* Built-in but customizable (used with TocBuilder): "child", "graphics",
|
|
|
|
* "equation", "index", "index:<user-str>", "nomencl", "listings", "math-macro",
|
|
|
|
* "external", any float type (as defined in the layouts).
|
2015-09-01 16:08:35 +00:00
|
|
|
*
|
2017-01-09 22:15:16 +00:00
|
|
|
* The following are used for XHTML output: "tableofcontents" (InsetText),
|
|
|
|
* "citation" (InsetCitation), any float type.
|
2015-09-01 16:08:35 +00:00
|
|
|
*
|
2017-01-09 22:15:16 +00:00
|
|
|
* Other types are defined in the layouts.
|
2015-09-01 16:08:35 +00:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
|
|
|
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,
|
2019-09-13 14:23:49 +00:00
|
|
|
FuncRequest const & action = FuncRequest(LFUN_UNKNOWN_ACTION)
|
2016-06-06 19:02:49 +00:00
|
|
|
);
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
2017-01-09 22:15:16 +00:00
|
|
|
DocIterator const & dit() const { return dit_; }
|
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; }
|
2013-03-08 21:18:26 +00:00
|
|
|
///
|
|
|
|
bool isOutput() const { return output_; }
|
2015-09-27 06:05:00 +00:00
|
|
|
///
|
2019-09-13 14:23:49 +00:00
|
|
|
void setAction(FuncRequest const & a) { action_ = a; }
|
2017-01-09 22:15:16 +00:00
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
/// custom action, or the default one (paragraph-goto) if not customised
|
2006-11-13 16:53:49 +00:00
|
|
|
FuncRequest action() const;
|
2017-01-09 22:15:16 +00:00
|
|
|
///
|
|
|
|
int id() const;
|
|
|
|
/// String for display, e.g. it has a mark if output is inactive
|
|
|
|
docstring const asString() const;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2017-01-09 22:15:16 +00:00
|
|
|
private:
|
2006-11-13 16:53:49 +00:00
|
|
|
/// Current position of item.
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator dit_;
|
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
|
|
|
|
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);
|
2019-05-27 04:06:10 +00:00
|
|
|
///
|
|
|
|
void reset();
|
2008-09-26 10:37:24 +00:00
|
|
|
/// \return true if the item was updated.
|
2020-10-21 08:35:40 +00:00
|
|
|
bool updateItem(DocIterator const & pit) const;
|
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;
|
2017-01-14 17:40:58 +00:00
|
|
|
/// Localised name for type
|
2015-11-03 16:47:25 +00:00
|
|
|
docstring outlinerName(std::string const & type) const;
|
2017-01-14 17:40:58 +00:00
|
|
|
/// Add a new (localised) name if yet unknown
|
|
|
|
void addName(std::string const & type, docstring const & name);
|
2015-11-30 15:27:43 +00:00
|
|
|
/// Whether a toc type is less important and appears in the "Other lists"
|
|
|
|
/// submenu
|
|
|
|
static bool isOther(std::string const & type);
|
2006-04-26 13:34:35 +00:00
|
|
|
|
|
|
|
private:
|
2017-01-14 17:40:58 +00:00
|
|
|
///
|
|
|
|
void resetOutlinerNames();
|
2007-05-28 22:27:45 +00:00
|
|
|
///
|
2006-04-26 13:34:35 +00:00
|
|
|
TocList tocs_;
|
|
|
|
///
|
2020-02-27 19:36:46 +00:00
|
|
|
std::map<std::string, std::unique_ptr<TocBuilder>> builders_;
|
2017-01-14 17:40:58 +00:00
|
|
|
/// Stores localised outliner names from this buffer and its children
|
|
|
|
std::map<std::string, docstring> outliner_names_;
|
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
|