]> git.lyx.org Git - lyx.git/blobdiff - src/BranchList.C
* src/LaTeX.C: beautification: use identical user messages
[lyx.git] / src / BranchList.C
index 93f117a20ece33a206aeee25338ea89abfd8ca1c..44c98e4a7007beac6d81e9f8fcc9e564b62445cb 100644 (file)
 #include <config.h>
 
 #include "BranchList.h"
+#include "LColor.h"
 
-#include <boost/assert.hpp>
+#include "frontends/Application.h"
 
-#include <functional>
+#include <algorithm>
 
 
+namespace lyx {
+
 using std::string;
-using std::bind2nd;
-using std::binary_function;
 
 
-string const & Branch::getBranch() const
+Branch::Branch()
+{
+       theApp->getRgbColor(LColor::background, color_);
+}
+
+
+docstring const & Branch::getBranch() const
 {
        return branch_;
 }
 
 
-void Branch::setBranch(string const & s)
+void Branch::setBranch(docstring const & s)
 {
        branch_ = s;
 }
@@ -49,77 +56,67 @@ bool Branch::setSelected(bool b)
 }
 
 
-string const & Branch::getColor() const
+RGBColor const & Branch::getColor() const
 {
        return color_;
 }
 
 
-void Branch::setColor(string const & c)
+void Branch::setColor(RGBColor const & c)
 {
        color_ = c;
 }
 
 
-namespace {
-
-struct SameName {
-       SameName(string const & name) : name_(name) {}
-       bool operator()(Branch const & branch) const
-               { return branch.getBranch() == name_; }
-private:
-       string name_;
-};
-
-}// namespace anon
+void Branch::setColor(string const & c)
+{
+       if (c.size() == 7 && c[0] == '#')
+               color_ = RGBColor(c);
+       else
+               // no color set or invalid color - use normal background
+               theApp->getRgbColor(LColor::background, color_);
+}
 
 
-Branch * BranchList::find(std::string const & name)
+Branch * BranchList::find(docstring const & name)
 {
        List::iterator it =
-               std::find_if(list.begin(), list.end(), SameName(name));
+               std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
        return it == list.end() ? 0 : &*it;
 }
 
-       
-Branch const * BranchList::find(std::string const & name) const
+
+Branch const * BranchList::find(docstring const & name) const
 {
        List::const_iterator it =
-               std::find_if(list.begin(), list.end(), SameName(name));
+               std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
        return it == list.end() ? 0 : &*it;
 }
 
-       
-bool BranchList::add(string const & s)
+
+bool BranchList::add(docstring const & s)
 {
        bool added = false;
-       string::size_type i = 0;
+       docstring::size_type i = 0;
        while (true) {
-               string::size_type const j = s.find_first_of(separator_, i);
-               string name;
-               if (j == string::npos)
+               docstring::size_type const j = s.find_first_of(separator_, i);
+               docstring name;
+               if (j == docstring::npos)
                        name = s.substr(i);
                else
                        name = s.substr(i, j - i);
                // Is this name already in the list?
-               List::const_iterator it = list.begin();
-               List::const_iterator end = list.end();
-               bool already = false;
-               for (; it != end; ++it) {
-                       if (it->getBranch() == name) {
-                               already = true;
-                               break;
-                       }
-               }
+               bool const already =
+                       std::find_if(list.begin(), list.end(),
+                                    BranchNamesEqual(name)) != list.end();
                if (!already) {
                        added = true;
                        Branch br;
                        br.setBranch(name);
                        br.setSelected(false);
-                       br.setColor("none");
                        list.push_back(br);
                }
-               if (j == string::npos)
+               if (j == docstring::npos)
                        break;
                i = j + 1;
        }
@@ -127,20 +124,12 @@ bool BranchList::add(string const & s)
 }
 
 
-namespace {
-
-struct match : public binary_function<Branch, string, bool> {
-       bool operator()(Branch const & br, string const & s) const {
-       return (br.getBranch() == s);
-       }
-};
-
-} // namespace anon.
-
-
-bool BranchList::remove(string const & s)
+bool BranchList::remove(docstring const & s)
 {
-       List::size_type const size = list.size();
-       list.remove_if(bind2nd(match(), s));
+       size_t const size = list.size();
+       list.remove_if(BranchNamesEqual(s));
        return size != list.size();
 }
+
+
+} // namespace lyx