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?
154 find_if(list.begin(), list.end(),
155 BranchNamesEqual(name)) != list.end();
160 br.setSelected(false);
161 br.setFileNameSuffix(false);
164 if (j == docstring::npos)
172 bool BranchList::remove(docstring const & s)
174 size_t const size = list.size();
175 list.remove_if(BranchNamesEqual(s));
176 return size != list.size();
180 bool BranchList::rename(docstring const & oldname,
181 docstring const & newname, bool const merge)
185 if (find_if(list.begin(), list.end(),
186 BranchNamesEqual(newname)) != list.end()) {
187 // new name already taken
189 return remove(oldname);
193 Branch * branch = find(oldname);
196 branch->setBranch(newname);
201 docstring BranchList::getFileNameSuffix() const
204 List::const_iterator it = list.begin();
205 for (; it != list.end(); ++it) {
206 if (it->isSelected() && it->hasFileNameSuffix())
207 result += "-" + it->branch();
209 return support::subst(result, from_ascii("/"), from_ascii("_"));