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"
17 #include "frontends/Application.h"
19 #include "support/lstrings.h"
30 class BranchNamesEqual : public std::unary_function<Branch, bool>
33 BranchNamesEqual(docstring const & name)
37 bool operator()(Branch const & branch) const
39 return branch.branch() == name_;
49 : selected_(false), filenameSuffix_(false)
51 // no theApp() with command line export
53 theApp()->getRgbColor(Color_background, color_);
55 frontend::Application::getRgbColorUncached(Color_background, color_);
59 docstring const & Branch::branch() const
65 void Branch::setBranch(docstring const & s)
71 bool Branch::isSelected() const
77 bool Branch::setSelected(bool b)
86 bool Branch::hasFileNameSuffix() const
88 return filenameSuffix_;
92 void Branch::setFileNameSuffix(bool b)
98 RGBColor const & Branch::color() const
104 void Branch::setColor(RGBColor const & c)
110 void Branch::setColor(string const & str)
112 if (str.size() == 7 && str[0] == '#')
113 color_ = rgbFromHexName(str);
115 // no color set or invalid color - use normal background
116 // no theApp() with command line export
118 theApp()->getRgbColor(Color_background, color_);
120 frontend::Application::getRgbColorUncached(Color_background, color_);
125 Branch * BranchList::find(docstring const & name)
128 find_if(list_.begin(), list_.end(), BranchNamesEqual(name));
129 return it == list_.end() ? 0 : &*it;
133 Branch const * BranchList::find(docstring const & name) const
135 List::const_iterator it =
136 find_if(list_.begin(), list_.end(), BranchNamesEqual(name));
137 return it == list_.end() ? 0 : &*it;
141 bool BranchList::add(docstring const & s)
146 size_t const j = s.find_first_of(separator_, i);
148 if (j == docstring::npos)
151 name = s.substr(i, j - i);
152 // Is this name already in the list?
153 bool const already = find(name) != nullptr;
158 br.setSelected(false);
159 br.setFileNameSuffix(false);
162 if (j == docstring::npos)
170 bool BranchList::remove(docstring const & s)
172 size_t const size = list_.size();
173 list_.remove_if(BranchNamesEqual(s));
174 return size != list_.size();
178 bool BranchList::rename(docstring const & oldname,
179 docstring const & newname, bool const merge)
184 // new name already taken
186 return remove(oldname);
190 Branch * branch = find(oldname);
193 branch->setBranch(newname);
198 docstring BranchList::getFileNameSuffix() const
201 for (auto const & br : list_) {
202 if (br.isSelected() && br.hasFileNameSuffix())
203 result += "-" + br.branch();
205 return support::subst(result, from_ascii("/"), from_ascii("_"));