3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Martin Vermeer
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "BranchList.h"
18 #include "frontends/Application.h"
20 #include "support/lstrings.h"
30 : selected_(false), filenameSuffix_(false)
32 color_ = "background";
36 docstring const & Branch::branch() const
42 void Branch::setBranch(docstring const & s)
48 bool Branch::isSelected() const
54 bool Branch::setSelected(bool b)
63 bool Branch::hasFileNameSuffix() const
65 return filenameSuffix_;
69 void Branch::setFileNameSuffix(bool b)
75 string const & Branch::color() const
81 void Branch::setColor(string const & str)
89 std::function<bool (Branch const &)> BranchNameIs(docstring const & d)
91 return [d](Branch const & b){ return b.branch() == d; };
97 Branch * BranchList::find(docstring const & name)
100 find_if(list_.begin(), list_.end(), BranchNameIs(name));
101 return it == list_.end() ? nullptr : &*it;
105 Branch const * BranchList::find(docstring const & name) const
107 List::const_iterator it =
108 find_if(list_.begin(), list_.end(), BranchNameIs(name));
109 return it == list_.end() ? nullptr : &*it;
113 bool BranchList::add(docstring const & s)
118 size_t const j = s.find_first_of(separator_, i);
120 if (j == docstring::npos)
123 name = s.substr(i, j - i);
124 // Is this name already in the list?
125 bool const already = find(name);
130 br.setSelected(false);
131 br.setFileNameSuffix(false);
134 if (j == docstring::npos)
142 bool BranchList::remove(docstring const & s)
144 size_t const size = list_.size();
145 list_.remove_if(BranchNameIs(s));
146 return size != list_.size();
150 bool BranchList::rename(docstring const & oldname,
151 docstring const & newname, bool const merge)
156 // new name already taken
158 return remove(oldname);
162 Branch * branch = find(oldname);
165 branch->setBranch(newname);
170 docstring BranchList::getFileNameSuffix() const
173 for (auto const & br : list_) {
174 if (br.isSelected() && br.hasFileNameSuffix())
175 result += "-" + br.branch();
177 return support::subst(result, from_ascii("/"), from_ascii("_"));