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"
29 : selected_(false), filenameSuffix_(false)
31 // no theApp() with command line export
33 theApp()->getRgbColor(Color_background, color_);
35 frontend::Application::getRgbColorUncached(Color_background, color_);
39 docstring const & Branch::branch() const
45 void Branch::setBranch(docstring const & s)
51 bool Branch::isSelected() const
57 bool Branch::setSelected(bool b)
66 bool Branch::hasFileNameSuffix() const
68 return filenameSuffix_;
72 void Branch::setFileNameSuffix(bool b)
78 RGBColor const & Branch::color() const
84 void Branch::setColor(RGBColor const & c)
90 void Branch::setColor(string const & str)
92 if (str.size() == 7 && str[0] == '#')
93 color_ = rgbFromHexName(str);
95 // no color set or invalid color - use normal background
96 // no theApp() with command line export
98 theApp()->getRgbColor(Color_background, color_);
100 frontend::Application::getRgbColorUncached(Color_background, color_);
107 std::function<bool (Branch const &)> BranchNameIs(docstring const & d)
109 return [d](Branch const & b){ return b.branch() == d; };
115 Branch * BranchList::find(docstring const & name)
118 find_if(list_.begin(), list_.end(), BranchNameIs(name));
119 return it == list_.end() ? nullptr : &*it;
123 Branch const * BranchList::find(docstring const & name) const
125 List::const_iterator it =
126 find_if(list_.begin(), list_.end(), BranchNameIs(name));
127 return it == list_.end() ? nullptr : &*it;
131 bool BranchList::add(docstring const & s)
136 size_t const j = s.find_first_of(separator_, i);
138 if (j == docstring::npos)
141 name = s.substr(i, j - i);
142 // Is this name already in the list?
143 bool const already = find(name);
148 br.setSelected(false);
149 br.setFileNameSuffix(false);
152 if (j == docstring::npos)
160 bool BranchList::remove(docstring const & s)
162 size_t const size = list_.size();
163 list_.remove_if(BranchNameIs(s));
164 return size != list_.size();
168 bool BranchList::rename(docstring const & oldname,
169 docstring const & newname, bool const merge)
174 // new name already taken
176 return remove(oldname);
180 Branch * branch = find(oldname);
183 branch->setBranch(newname);
188 docstring BranchList::getFileNameSuffix() const
191 for (auto const & br : list_) {
192 if (br.isSelected() && br.hasFileNameSuffix())
193 result += "-" + br.branch();
195 return support::subst(result, from_ascii("/"), from_ascii("_"));