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"
25 class BranchNamesEqual
: public std::unary_function
<Branch
, bool> {
27 BranchNamesEqual(docstring
const & name
)
29 bool operator()(Branch
const & branch
) const
31 return branch
.getBranch() == name_
;
39 Branch::Branch() : selected_(false)
41 // no theApp() with command line export
43 theApp()->getRgbColor(Color_background
, color_
);
47 docstring
const & Branch::getBranch() const
53 void Branch::setBranch(docstring
const & s
)
59 bool Branch::getSelected() const
65 bool Branch::setSelected(bool b
)
74 RGBColor
const & Branch::getColor() const
80 void Branch::setColor(RGBColor
const & c
)
86 void Branch::setColor(string
const & str
)
88 if (str
.size() == 7 && str
[0] == '#')
89 color_
= rgbFromHexName(str
);
91 // no color set or invalid color - use normal background
92 theApp()->getRgbColor(Color_background
, color_
);
96 Branch
* BranchList::find(docstring
const & name
)
99 find_if(list
.begin(), list
.end(), BranchNamesEqual(name
));
100 return it
== list
.end() ? 0 : &*it
;
104 Branch
const * BranchList::find(docstring
const & name
) const
106 List::const_iterator it
=
107 find_if(list
.begin(), list
.end(), BranchNamesEqual(name
));
108 return it
== list
.end() ? 0 : &*it
;
112 bool BranchList::add(docstring
const & s
)
115 docstring::size_type i
= 0;
117 docstring::size_type
const j
= s
.find_first_of(separator_
, i
);
119 if (j
== docstring::npos
)
122 name
= s
.substr(i
, j
- i
);
123 // Is this name already in the list?
125 find_if(list
.begin(), list
.end(),
126 BranchNamesEqual(name
)) != list
.end();
131 br
.setSelected(false);
134 if (j
== docstring::npos
)
142 bool BranchList::remove(docstring
const & s
)
144 size_t const size
= list
.size();
145 list
.remove_if(BranchNamesEqual(s
));
146 return size
!= list
.size();