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