]> git.lyx.org Git - lyx.git/blob - src/IndicesList.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / IndicesList.h
1 // -*- C++ -*-
2 /**
3  * \file IndicesList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INDICESLIST_H
13 #define INDICESLIST_H
14
15 #include "ColorCode.h"
16
17 #include "support/docstring.h"
18
19 #include <list>
20
21
22 namespace lyx {
23
24 /**
25  * \class Index
26  *
27  * A class describing an Index type, such as "Index of Names".
28  * Different Index types are used in split Indices
29  *
30  * An Index has a name and a shortcut notation. It uses a
31  * user-specifiable GUI colour. All these can be set and
32  * queried.
33  *
34  * \class IndicesList
35  *
36  * A class containing a vector of all defined indices within a
37  * document. It has methods for outputting a '|'-separated string
38  * of all elements, and for adding, removing and renaming elements.
39  */
40
41 class Index {
42 public:
43         ///
44         Index();
45         ///
46         docstring const & index() const;
47         ///
48         void setIndex(docstring const &);
49         ///
50         docstring const & shortcut() const;
51         ///
52         void setShortcut(docstring const &);
53         ///
54         RGBColor const & color() const;
55         ///
56         void setColor(RGBColor const &);
57         /**
58          * Set color from a string "#rrggbb".
59          * Use Color:background if the string is no valid color.
60          * This ensures compatibility with LyX 1.4.0 that had the symbolic
61          * color "none" that was displayed as Color:background.
62          */
63         void setColor(std::string const &);
64
65 private:
66         ///
67         docstring index_;
68         ///
69         docstring shortcut_;
70         ///
71         RGBColor color_;
72 };
73
74
75 class IndicesList {
76         ///
77         typedef std::list<Index> List;
78 public:
79         typedef List::const_iterator const_iterator;
80
81         ///
82         IndicesList() : separator_(from_ascii("|")) {}
83
84         ///
85         bool empty() const { return list.empty(); }
86         ///
87         void clear() { list.clear(); }
88         ///
89         const_iterator begin() const { return list.begin(); }
90         const_iterator end() const { return list.end(); }
91
92         /** \returns the Index with \c name. If not found, returns 0.
93          */
94         Index * find(docstring const & name);
95         Index const * find(docstring const & name) const;
96
97         /** \returns the Index with the shortcut \c shortcut.
98          *  If not found, returns 0.
99          */
100         Index * findShortcut(docstring const & shortcut);
101         Index const * findShortcut(docstring const & shortcut) const;
102
103         /** Add (possibly multiple (separated by separator())) indices to list
104          *  \returns true if an index is added.
105          */
106         bool add(docstring const & n, docstring const & s = docstring());
107         /** Add the default index (if not already there)
108          *  \returns true if an index is added.
109          */
110         bool addDefault(docstring const & n);
111         /** remove an index from list by name
112          *  \returns true if an index is removed.
113          */
114         bool remove(docstring const &);
115         /** rename an index in list
116          *  \returns true if renaming succeeded.
117          */
118         bool rename(docstring const &, docstring const &);
119
120 private:
121         ///
122         List list;
123         ///
124         docstring separator_;
125 };
126
127 } // namespace lyx
128
129 #endif // INDICESLIST_H