]> git.lyx.org Git - lyx.git/blob - src/BranchList.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / BranchList.h
1 // -*- C++ -*-
2 /**
3  * \file BranchList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Martin Vermeer
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef BRANCHLIST_H
13 #define BRANCHLIST_H
14
15 #include "ColorCode.h"
16
17 #include "support/docstring.h"
18
19 #include <cstdlib> // rand()
20 #include <list>
21
22
23 namespace lyx {
24
25 /**
26  * \class Branch
27  *
28  * A class describing a 'branch', i.e., a named alternative for
29  * selectively outputting some parts of a document while suppressing
30  * other parts.
31  *
32  * A branch has a name, can either be selected or not, and uses a
33  * user-specifiable background colour. All these can be set and
34  * queried.
35  *
36  * \class BranchList
37  *
38  * A class containing a vector of all defined branches within a
39  * document. It has methods for selecting or deselecting branches by
40  * name, for outputting a '|'-separated string of all elements or only
41  * the selected ones, and for adding and removing elements.
42  */
43
44 class Branch {
45 public:
46         ///
47         Branch() {}
48         ///
49         docstring const & branch() const;
50         ///
51         void setBranch(docstring const &);
52         ///
53         bool isSelected() const;
54         /** Select/deselect the branch.
55          *  \return true if the selection status changes.
56          */
57         bool setSelected(bool);
58         /** If true, the branch name will be appended
59          *  to the output file name.
60          */
61         bool hasFileNameSuffix() const;
62         /// Select/deselect filename suffix property.
63         void setFileNameSuffix(bool);
64         ///
65         void setListID(int const id) { branch_list_id_ = id; }
66         ///
67         std::string const & color() const;
68         ///
69         std::string const & lightModeColor() const;
70         ///
71         std::string const & darkModeColor() const;
72         /**
73          * Set background color from a hexcolor string "#rrggbb" or a lyx color name.
74          * Use Color:background if the string is no valid color.
75          * This ensures compatibility with LyX 1.4.0 that had the symbolic
76          * color "none" that was displayed as Color:background.
77          * This sets the dark color if in dark mode, else the light color.
78          */
79         void setColor(std::string const & color);
80         /// Set dark and light background colors
81         void setColors(std::string const & color,
82                       std::string const & dmcolor = std::string());
83         ///
84         int listID() const { return branch_list_id_; }
85
86 private:
87         ///
88         docstring branch_;
89         ///
90         bool selected_ = false;
91         ///
92         bool filenameSuffix_ = false;
93         /// light mode background color
94         std::string lmcolor_ = "background";
95         /// dark mode background color
96         std::string dmcolor_ = "background";
97         ///
98         int branch_list_id_ = 0;
99 };
100
101
102 class BranchList {
103         ///
104         typedef std::list<Branch> List;
105 public:
106         typedef List::const_iterator const_iterator;
107
108         ///
109         BranchList() : separator_(from_ascii("|")), id_(rand()) {}
110
111         ///
112         docstring separator() const { return separator_; }
113
114         ///
115         int id() const { return id_; }
116
117         ///
118         bool empty() const { return list_.empty(); }
119         ///
120         void clear() { list_.clear(); }
121         ///
122         const_iterator begin() const { return list_.begin(); }
123         const_iterator end() const { return list_.end(); }
124
125         /** \returns the Branch with \c name. If not found, returns 0.
126          */
127         Branch * find(docstring const & name);
128         Branch const * find(docstring const & name) const;
129
130         /** Add (possibly multiple (separated by separator())) branches to list
131          *  \returns true if a branch is added.
132          */
133         bool add(docstring const &);
134         /** remove a branch from list by name
135          *  \returns true if a branch is removed.
136          */
137         bool remove(docstring const &);
138         /** rename an branch in list
139          *  \returns true if renaming succeeded.
140          * if \p merge is true, the branch will be removed
141          * if a branch with the newname already exists.
142          */
143         bool rename(docstring const &, docstring const &, bool const merge = false);
144         /// get the complete filename suffix
145         docstring getFileNameSuffix() const;
146
147 private:
148         ///
149         List list_;
150         ///
151         docstring separator_;
152         ///
153         int id_;
154 };
155
156 } // namespace lyx
157
158 #endif // BRANCHLIST_H