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