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