3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Martin Vermeer
8 * Full author contact details are available in file CREDITS.
13 #include "BranchList.h"
16 #include "frontends/Application.h"
27 class BranchNamesEqual
: public std::unary_function
<Branch
, bool>
30 BranchNamesEqual(docstring
const & name
) : name_(name
) {}
32 bool operator()(Branch
const & branch
) const
34 return branch
.branch() == name_
;
42 Branch::Branch() : selected_(false)
44 // no theApp() with command line export
46 theApp()->getRgbColor(Color_background
, color_
);
50 docstring
const & Branch::branch() const
56 void Branch::setBranch(docstring
const & s
)
62 bool Branch::isSelected() const
68 bool Branch::setSelected(bool b
)
77 RGBColor
const & Branch::color() const
83 void Branch::setColor(RGBColor
const & c
)
89 void Branch::setColor(string
const & str
)
91 if (str
.size() == 7 && str
[0] == '#')
92 color_
= rgbFromHexName(str
);
94 // no color set or invalid color - use normal background
95 theApp()->getRgbColor(Color_background
, color_
);
99 Branch
* BranchList::find(docstring
const & name
)
102 find_if(list
.begin(), list
.end(), BranchNamesEqual(name
));
103 return it
== list
.end() ? 0 : &*it
;
107 Branch
const * BranchList::find(docstring
const & name
) const
109 List::const_iterator it
=
110 find_if(list
.begin(), list
.end(), BranchNamesEqual(name
));
111 return it
== list
.end() ? 0 : &*it
;
115 bool BranchList::add(docstring
const & s
)
120 size_t const j
= s
.find_first_of(separator_
, i
);
122 if (j
== docstring::npos
)
125 name
= s
.substr(i
, j
- i
);
126 // Is this name already in the list?
128 find_if(list
.begin(), list
.end(),
129 BranchNamesEqual(name
)) != list
.end();
134 br
.setSelected(false);
137 if (j
== docstring::npos
)
145 bool BranchList::remove(docstring
const & s
)
147 size_t const size
= list
.size();
148 list
.remove_if(BranchNamesEqual(s
));
149 return size
!= list
.size();