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