]> git.lyx.org Git - lyx.git/blob - src/BranchList.cpp
Fixed some lines that were too long. It compiled afterwards.
[lyx.git] / src / BranchList.cpp
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.
5  *
6  * \author Martin Vermeer
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "BranchList.h"
14 #include "Color.h"
15
16 #include "frontends/Application.h"
17
18 #include <algorithm>
19
20 using std::string;
21
22 namespace lyx {
23
24
25 Branch::Branch()
26 {
27         theApp()->getRgbColor(Color::background, color_);
28 }
29
30
31 docstring const & Branch::getBranch() const
32 {
33         return branch_;
34 }
35
36
37 void Branch::setBranch(docstring const & s)
38 {
39         branch_ = s;
40 }
41
42
43 bool Branch::getSelected() const
44 {
45         return selected_;
46 }
47
48
49 bool Branch::setSelected(bool b)
50 {
51         if (b == selected_)
52                 return false;
53         selected_ = b;
54         return true;
55 }
56
57
58 RGBColor const & Branch::getColor() const
59 {
60         return color_;
61 }
62
63
64 void Branch::setColor(RGBColor const & c)
65 {
66         color_ = c;
67 }
68
69
70 void Branch::setColor(string const & c)
71 {
72         if (c.size() == 7 && c[0] == '#')
73                 color_ = RGBColor(c);
74         else
75                 // no color set or invalid color - use normal background
76                 theApp()->getRgbColor(Color::background, color_);
77 }
78
79
80 Branch * BranchList::find(docstring const & name)
81 {
82         List::iterator it =
83                 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
84         return it == list.end() ? 0 : &*it;
85 }
86
87
88 Branch const * BranchList::find(docstring const & name) const
89 {
90         List::const_iterator it =
91                 std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
92         return it == list.end() ? 0 : &*it;
93 }
94
95
96 bool BranchList::add(docstring const & s)
97 {
98         bool added = false;
99         docstring::size_type i = 0;
100         while (true) {
101                 docstring::size_type const j = s.find_first_of(separator_, i);
102                 docstring name;
103                 if (j == docstring::npos)
104                         name = s.substr(i);
105                 else
106                         name = s.substr(i, j - i);
107                 // Is this name already in the list?
108                 bool const already =
109                         std::find_if(list.begin(), list.end(),
110                                      BranchNamesEqual(name)) != list.end();
111                 if (!already) {
112                         added = true;
113                         Branch br;
114                         br.setBranch(name);
115                         br.setSelected(false);
116                         list.push_back(br);
117                 }
118                 if (j == docstring::npos)
119                         break;
120                 i = j + 1;
121         }
122         return added;
123 }
124
125
126 bool BranchList::remove(docstring const & s)
127 {
128         size_t const size = list.size();
129         list.remove_if(BranchNamesEqual(s));
130         return size != list.size();
131 }
132
133
134 } // namespace lyx