Update NEWS preparing for alpha1
[lyx.git] / src / BranchList.cpp
blob5ca0fd58fc62cba233dbeff99a590c311bb559a2
1 /**
2 * \file BranchList.cpp
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.
9 */
11 #include <config.h>
13 #include "BranchList.h"
14 #include "Color.h"
16 #include "frontends/Application.h"
18 #include <algorithm>
20 using namespace std;
22 namespace lyx {
25 Branch::Branch() : selected_(false)
27 // no theApp() with command line export
28 if (theApp())
29 theApp()->getRgbColor(Color_background, color_);
33 docstring const & Branch::getBranch() const
35 return branch_;
39 void Branch::setBranch(docstring const & s)
41 branch_ = s;
45 bool Branch::getSelected() const
47 return selected_;
51 bool Branch::setSelected(bool b)
53 if (b == selected_)
54 return false;
55 selected_ = b;
56 return true;
60 RGBColor const & Branch::getColor() const
62 return color_;
66 void Branch::setColor(RGBColor const & c)
68 color_ = c;
72 void Branch::setColor(string const & str)
74 if (str.size() == 7 && str[0] == '#')
75 color_ = rgbFromHexName(str);
76 else
77 // no color set or invalid color - use normal background
78 theApp()->getRgbColor(Color_background, color_);
82 Branch * BranchList::find(docstring const & name)
84 List::iterator it =
85 find_if(list.begin(), list.end(), BranchNamesEqual(name));
86 return it == list.end() ? 0 : &*it;
90 Branch const * BranchList::find(docstring const & name) const
92 List::const_iterator it =
93 find_if(list.begin(), list.end(), BranchNamesEqual(name));
94 return it == list.end() ? 0 : &*it;
98 bool BranchList::add(docstring const & s)
100 bool added = false;
101 docstring::size_type i = 0;
102 while (true) {
103 docstring::size_type const j = s.find_first_of(separator_, i);
104 docstring name;
105 if (j == docstring::npos)
106 name = s.substr(i);
107 else
108 name = s.substr(i, j - i);
109 // Is this name already in the list?
110 bool const already =
111 find_if(list.begin(), list.end(),
112 BranchNamesEqual(name)) != list.end();
113 if (!already) {
114 added = true;
115 Branch br;
116 br.setBranch(name);
117 br.setSelected(false);
118 list.push_back(br);
120 if (j == docstring::npos)
121 break;
122 i = j + 1;
124 return added;
128 bool BranchList::remove(docstring const & s)
130 size_t const size = list.size();
131 list.remove_if(BranchNamesEqual(s));
132 return size != list.size();
136 } // namespace lyx