4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
9 * \author Abdelrazak Younes
10 * \author Guillaume Munch
12 * Full author contact details are available in file CREDITS.
18 #include "DocIterator.h"
19 #include "FuncRequest.h"
20 #include "OutputEnums.h"
22 #include "TocBuilder.h"
24 #include "support/strfwd.h"
25 #include "support/unique_ptr.h"
32 /* Toc types are described by strings. They cannot be converted into an enum
33 * because of the user-configurable categories for index and the user-definable
34 * toc types provided in layout files.
36 * Here is a summary of built-in toc types
38 * Non-customizable (used without TocBuilder): "tableofcontents", "change",
39 * "citation", "label", "senseless".
41 * Built-in but customizable (used with TocBuilder): "child", "graphics",
42 * "equation", "index", "index:<user-str>", "nomencl", "listings", "math-macro",
43 * "external", any float type (as defined in the layouts).
45 * The following are used for XHTML output: "tableofcontents" (InsetText),
46 * "citation" (InsetCitation), any float type.
48 * Other types are defined in the layouts.
57 /// Default constructor for STL containers.
58 TocItem() : dit_(0), depth_(0), output_(false) {}
60 TocItem(DocIterator const & dit,
64 FuncRequest const & action = FuncRequest(LFUN_UNKNOWN_ACTION)
67 DocIterator const & dit() const { return dit_; }
69 int depth() const { return depth_; }
71 docstring const & str() const { return str_; }
73 void str(docstring const & s) { str_ = s; }
75 bool isOutput() const { return output_; }
77 void setAction(FuncRequest const & a) { action_ = a; }
79 /// custom action, or the default one (paragraph-goto) if not customised
80 FuncRequest action() const;
83 /// String for display, e.g. it has a mark if output is inactive
84 docstring const asString() const;
87 /// Current position of item.
93 /// Is this item in a note, inactive branch, etc?
100 /// Class to build and access the Tocs of a particular buffer.
104 static Toc::const_iterator findItem(Toc const & toc,
105 DocIterator const & dit);
106 /// Look for a TocItem given its depth and string.
107 /// \return The first matching item.
108 /// \retval end() if no item was found.
109 static Toc::iterator findItem(Toc & toc, int depth, docstring const & str);
111 TocBackend(Buffer const * buffer) : buffer_(buffer) {}
113 void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
115 void update(bool output_active, UpdateType utype);
118 /// \return true if the item was updated.
119 bool updateItem(DocIterator const & pit) const;
121 TocList const & tocs() const { return tocs_; }
123 std::shared_ptr<Toc const> toc(std::string const & type) const;
125 std::shared_ptr<Toc> toc(std::string const & type);
126 /// \return the current TocBuilder for the Toc of type \param type, or
127 /// creates one if it does not already exist.
128 TocBuilder & builder(std::string const & type);
129 /// \return the first Toc Item before the cursor.
130 /// \param type: Type of Toc.
131 /// \param dit: The cursor location in the document.
133 item(std::string const & type, DocIterator const & dit) const;
136 void writePlaintextTocList(std::string const & type,
137 odocstringstream & os, size_t max_length) const;
138 /// Localised name for type
139 docstring outlinerName(std::string const & type) const;
140 /// Add a new (localised) name if yet unknown
141 void addName(std::string const & type, docstring const & name);
142 /// Whether a toc type is less important and appears in the "Other lists"
144 static bool isOther(std::string const & type);
148 void resetOutlinerNames();
152 std::map<std::string, std::unique_ptr<TocBuilder>> builders_;
153 /// Stores localised outliner names from this buffer and its children
154 std::map<std::string, docstring> outliner_names_;
156 Buffer const * buffer_;
162 #endif // TOC_BACKEND_H