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) : name_(name) {}
35 bool operator()(Branch const & branch) const
37 return branch.branch() == name_;
46 : selected_(false), filenameSuffix_(false)
48 // no theApp() with command line export
50 theApp()->getRgbColor(Color_background, color_);
52 frontend::Application::getRgbColorUncached(Color_background, color_);
56 docstring const & Branch::branch() const
62 void Branch::setBranch(docstring const & s)
68 bool Branch::isSelected() const
74 bool Branch::setSelected(bool b)
83 bool Branch::hasFileNameSuffix() const
85 return filenameSuffix_;
89 void Branch::setFileNameSuffix(bool b)
95 RGBColor const & Branch::color() const
101 void Branch::setColor(RGBColor const & c)
107 void Branch::setColor(string const & str)
109 if (str.size() == 7 && str[0] == '#')
110 color_ = rgbFromHexName(str);
112 // no color set or invalid color - use normal background
113 // no theApp() with command line export
115 theApp()->getRgbColor(Color_background, color_);
117 frontend::Application::getRgbColorUncached(Color_background, color_);
122 Branch * BranchList::find(docstring const & name)
125 find_if(list.begin(), list.end(), BranchNamesEqual(name));
126 return it == list.end() ? 0 : &*it;
130 Branch const * BranchList::find(docstring const & name) const
132 List::const_iterator it =
133 find_if(list.begin(), list.end(), BranchNamesEqual(name));
134 return it == list.end() ? 0 : &*it;
138 bool BranchList::add(docstring const & s)
143 size_t const j = s.find_first_of(separator_, i);
145 if (j == docstring::npos)
148 name = s.substr(i, j - i);
149 // Is this name already in the list?
151 find_if(list.begin(), list.end(),
152 BranchNamesEqual(name)) != list.end();
157 br.setSelected(false);
158 br.setFileNameSuffix(false);
161 if (j == docstring::npos)
169 bool BranchList::remove(docstring const & s)
171 size_t const size = list.size();
172 list.remove_if(BranchNamesEqual(s));
173 return size != list.size();
177 bool BranchList::rename(docstring const & oldname,
178 docstring const & newname, bool const merge)
182 if (find_if(list.begin(), list.end(),
183 BranchNamesEqual(newname)) != list.end()) {
184 // new name already taken
186 return remove(oldname);
190 Branch * branch = find(oldname);
193 branch->setBranch(newname);
198 docstring BranchList::getFileNameSuffix() const
201 List::const_iterator it = list.begin();
202 for (; it != list.end(); ++it) {
203 if (it->isSelected() && it->hasFileNameSuffix())
204 result += "-" + it->branch();
206 return support::subst(result, from_ascii("/"), from_ascii("_"));