]> git.lyx.org Git - lyx.git/blob - src/BranchList.h
* Add possibility to append active branch names to the output file name (#3105).
[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  * \author Martin Vermeer
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  *
11  * \class Branch
12  *
13  * A class describing a 'branch', i.e., a named alternative for
14  * selectively outputting some parts of a document while suppressing
15  * other parts.
16  *
17  * A branch has a name, can either be selected or not, and uses a
18  * user-specifyable background colour. All these can be set and
19  * queried.
20  *
21  * \class BranchList
22  *
23  * A class containing a vector of all defined branches within a
24  * document. Has methods for selecting or deselecting branches by
25  * name, for outputting a '|'-separated string of all elements or only
26  * the selected ones, and for adding and removing elements.
27  */
28
29
30 #ifndef BRANCHLIST_H
31 #define BRANCHLIST_H
32
33 #include "ColorCode.h"
34
35 #include "support/docstring.h"
36
37 #include <list>
38
39
40 namespace lyx {
41
42 class Branch {
43 public:
44         ///
45         Branch();
46         ///
47         docstring const & branch() const;
48         ///
49         void setBranch(docstring const &);
50         ///
51         bool isSelected() const;
52         /** Select/deselect the branch.
53          *  \return true if the selection status changes.
54          */
55         bool setSelected(bool);
56         /** If true, the branch name will be appended
57          *  to the output file name.
58          */
59         bool hasFilenameSuffix() const;
60         /// Select/deselect filename suffix property.
61         void setFilenameSuffix(bool);
62         ///
63         RGBColor const & color() const;
64         ///
65         void setColor(RGBColor const &);
66         /**
67          * Set color from a string "#rrggbb".
68          * Use Color:background if the string is no valid color.
69          * This ensures compatibility with LyX 1.4.0 that had the symbolic
70          * color "none" that was displayed as Color:background.
71          */
72         void setColor(std::string const &);
73
74 private:
75         ///
76         docstring branch_;
77         ///
78         bool selected_;
79         ///
80         bool filenameSuffix_;
81         ///
82         RGBColor color_;
83 };
84
85
86 class BranchList {
87         ///
88         typedef std::list<Branch> List;
89 public:
90         typedef List::const_iterator const_iterator;
91
92         ///
93         BranchList() : separator_(from_ascii("|")) {}
94
95         ///
96         bool empty() const { return list.empty(); }
97         ///
98         void clear() { list.clear(); }
99         ///
100         const_iterator begin() const { return list.begin(); }
101         const_iterator end() const { return list.end(); }
102
103         /** \returns the Branch with \c name. If not found, returns 0.
104          */
105         Branch * find(docstring const & name);
106         Branch const * find(docstring const & name) const;
107
108         /** Add (possibly multiple (separated by separator())) branches to list
109          *  \returns true if a branch is added.
110          */
111         bool add(docstring const &);
112         /** remove a branch from list by name
113          *  \returns true if a branch is removed.
114          */
115         bool remove(docstring const &);
116         /** rename an branch in list
117          *  \returns true if renaming succeeded.
118          * if \p merge is true, the branch will be removed
119          * if a branch with the newname already exists.
120          */
121         bool rename(docstring const &, docstring const &, bool const merge = false);
122         /// get the complete filename suffix
123         docstring getFilenameSuffix() const;
124
125 private:
126         ///
127         List list;
128         ///
129         docstring separator_;
130 };
131
132 } // namespace lyx
133
134 #endif // BRANCHLIST_H