]> git.lyx.org Git - lyx.git/blob - src/insets/InsetIndex.h
InsetIndex: revamp IndexEntry to handle both legacy and modern index insets; simplify...
[lyx.git] / src / insets / InsetIndex.h
1 // -*- C++ -*-
2 /**
3  * \file InsetIndex.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSET_INDEX_H
13 #define INSET_INDEX_H
14
15
16 #include "InsetCollapsible.h"
17 #include "InsetCommand.h"
18
19
20 namespace lyx {
21
22 class IndexEntry;
23
24 class InsetIndexParams {
25 public:
26         enum PageRange {
27                 None,
28                 Start,
29                 End
30         };
31         ///
32         explicit InsetIndexParams(docstring const & b = docstring())
33                 : index(b), range(None), pagefmt("default") {}
34         ///
35         void write(std::ostream & os) const;
36         ///
37         void read(Lexer & lex);
38         ///
39         docstring index;
40         ///
41         PageRange range;
42         ///
43         std::string pagefmt;
44 };
45
46
47 /** Used to insert index labels
48   */
49 class InsetIndex : public InsetCollapsible {
50 public:
51         ///
52         InsetIndex(Buffer *, InsetIndexParams const &);
53         ///
54         static std::string params2string(InsetIndexParams const &);
55         ///
56         static void string2params(std::string const &, InsetIndexParams &);
57 private:
58         ///
59         bool hasSettings() const override;
60         ///
61         InsetCode lyxCode() const override { return INDEX_CODE; }
62         ///
63         docstring layoutName() const override { return from_ascii("Index"); }
64         ///
65         ColorCode labelColor() const override;
66         ///
67         void write(std::ostream & os) const override;
68         ///
69         void read(Lexer & lex) override;
70         ///
71         void docbook(XMLStream &, OutputParams const &) const override;
72         ///
73         docstring xhtml(XMLStream &, OutputParams const &) const override;
74         ///
75         void latex(otexstream &, OutputParams const &) const override;
76         ///
77         void processLatexSorting(otexstream &, OutputParams const &,
78                                  docstring const, docstring const) const;
79         ///
80         bool showInsetDialog(BufferView *) const override;
81         ///
82         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
83         ///
84         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
85         /// should paragraph indentation be omitted in any case?
86         bool neverIndent() const override { return true; }
87         ///
88         void addToToc(DocIterator const & di, bool output_active,
89                                   UpdateType utype, TocBackend & backend) const override;
90         ///
91         docstring toolTip(BufferView const & bv, int x, int y) const override;
92         ///
93         docstring const buttonLabel(BufferView const & bv) const override;
94         /// Updates needed features for this inset.
95         void validate(LaTeXFeatures & features) const override;
96         ///
97         void getSortkey(otexstream &, OutputParams const &) const;
98         ///
99         docstring getSortkeyAsText(OutputParams const &) const;
100         ///
101         void getSubentries(otexstream &, OutputParams const &) const;
102         ///
103         std::vector<docstring> getSubentriesAsText(OutputParams const &) const;
104         ///
105         docstring getMainSubentryAsText(OutputParams const & runparams) const;
106         ///
107         void getSeeRefs(otexstream &, OutputParams const &) const;
108         ///
109         docstring getSeeAsText(OutputParams const & runparams) const;
110         ///
111         std::vector<docstring> getSeeAlsoesAsText(OutputParams const & runparams) const;
112         ///
113         bool hasSubentries() const;
114         ///
115         bool hasSeeRef() const;
116         ///
117         bool hasSortKey() const;
118         ///
119         bool macrosPossible(std::string const type) const;
120         ///
121         std::string contextMenuName() const override;
122         ///
123         std::string contextMenu(BufferView const &, int, int) const override;
124         ///
125         Inset * clone() const override { return new InsetIndex(*this); }
126         /// Is the content of this inset part of the immediate text sequence?
127         bool isPartOfTextSequence() const override { return false; }
128         ///
129         bool insetAllowed(InsetCode code) const override;
130
131         ///
132         friend class InsetIndexParams;
133         ///
134         friend class IndexEntry;
135         ///
136         InsetIndexParams params_;
137 };
138
139
140 class InsetPrintIndex : public InsetCommand {
141 public:
142         ///
143         InsetPrintIndex(Buffer * buf, InsetCommandParams const &);
144
145         /// \name Public functions inherited from Inset class
146         //@{
147         ///
148         InsetCode lyxCode() const override { return INDEX_PRINT_CODE; }
149         ///
150         void latex(otexstream &, OutputParams const &) const override;
151         ///
152         docstring xhtml(XMLStream &, OutputParams const &) const override;
153         ///
154         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
155         ///
156         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
157         ///
158         void updateBuffer(ParIterator const & it, UpdateType, bool const deleted = false) override;
159         ///
160         std::string contextMenuName() const override;
161         /// Updates needed features for this inset.
162         void validate(LaTeXFeatures & features) const override;
163         ///
164         bool hasSettings() const override;
165         ///
166         int rowFlags() const override { return Display; }
167         //@}
168
169         /// \name Static public methods obligated for InsetCommand derived classes
170         //@{
171         ///
172         static ParamInfo const & findInfo(std::string const &);
173         ///
174         static std::string defaultCommand() { return "printindex"; }
175         ///
176         static bool isCompatibleCommand(std::string const & s);
177         //@}
178
179 private:
180         /// \name Private functions inherited from Inset class
181         //@{
182         ///
183         Inset * clone() const override { return new InsetPrintIndex(*this); }
184         //@}
185
186         /// \name Private functions inherited from InsetCommand class
187         //@{
188         ///
189         docstring screenLabel() const override;
190         //@}
191 };
192
193
194 } // namespace lyx
195
196 #endif