4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Martin Vermeer
9 * Full author contact details are available in file CREDITS.
15 #include "ColorCode.h"
17 #include "support/docstring.h"
19 #include <cstdlib> // rand()
28 * A class describing a 'branch', i.e., a named alternative for
29 * selectively outputting some parts of a document while suppressing
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
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.
49 docstring const & branch() const;
51 void setBranch(docstring const &);
53 bool isSelected() const;
54 /** Select/deselect the branch.
55 * \return true if the selection status changes.
57 bool setSelected(bool);
58 /** If true, the branch name will be appended
59 * to the output file name.
61 bool hasFileNameSuffix() const;
62 /// Select/deselect filename suffix property.
63 void setFileNameSuffix(bool);
65 void setListID(int const id) { branch_list_id_ = id; }
67 std::string const & color() const;
69 std::string const & lightModeColor() const;
71 std::string const & darkModeColor() const;
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.
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());
84 int listID() const { return branch_list_id_; }
90 bool selected_ = false;
92 bool filenameSuffix_ = false;
93 /// light mode background color
94 std::string lmcolor_ = "background";
95 /// dark mode background color
96 std::string dmcolor_ = "background";
98 int branch_list_id_ = 0;
104 typedef std::list<Branch> List;
106 typedef List::const_iterator const_iterator;
109 BranchList() : separator_(from_ascii("|")), id_(rand()) {}
112 docstring separator() const { return separator_; }
115 int id() const { return id_; }
118 bool empty() const { return list_.empty(); }
120 void clear() { list_.clear(); }
122 const_iterator begin() const { return list_.begin(); }
123 const_iterator end() const { return list_.end(); }
125 /** \returns the Branch with \c name. If not found, returns 0.
127 Branch * find(docstring const & name);
128 Branch const * find(docstring const & name) const;
130 /** Add (possibly multiple (separated by separator())) branches to list
131 * \returns true if a branch is added.
133 bool add(docstring const &);
134 /** remove a branch from list by name
135 * \returns true if a branch is removed.
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.
143 bool rename(docstring const &, docstring const &, bool const merge = false);
144 /// get the complete filename suffix
145 docstring getFileNameSuffix() const;
151 docstring separator_;
158 #endif // BRANCHLIST_H