2003-08-17 11:28:23 +00:00
|
|
|
/**
|
2003-09-09 17:25:35 +00:00
|
|
|
* \file BranchList.C
|
2003-08-17 11:28:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2003-08-23 00:17:00 +00:00
|
|
|
*
|
2003-08-17 11:28:23 +00:00
|
|
|
* \author Martin Vermeer
|
2003-09-09 17:25:35 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-08-17 11:28:23 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-23 00:17:00 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2003-08-17 11:28:23 +00:00
|
|
|
#include "BranchList.h"
|
2006-03-23 20:04:05 +00:00
|
|
|
#include "LColor.h"
|
2006-10-12 14:10:13 +00:00
|
|
|
|
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2005-01-18 14:15:57 +00:00
|
|
|
#include <algorithm>
|
2003-09-09 17:25:35 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2004-01-05 15:49:40 +00:00
|
|
|
using std::string;
|
2003-08-17 11:28:23 +00:00
|
|
|
|
|
|
|
|
2006-03-23 20:04:05 +00:00
|
|
|
Branch::Branch()
|
|
|
|
{
|
2006-11-30 00:04:51 +00:00
|
|
|
theApp()->getRgbColor(LColor::background, color_);
|
2006-03-23 20:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring const & Branch::getBranch() const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
return branch_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:16:45 +00:00
|
|
|
void Branch::setBranch(docstring const & s)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
branch_ = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Branch::getSelected() const
|
|
|
|
{
|
|
|
|
return selected_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-14 16:33:56 +00:00
|
|
|
bool Branch::setSelected(bool b)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
if (b == selected_)
|
|
|
|
return false;
|
2003-08-17 11:28:23 +00:00
|
|
|
selected_ = b;
|
2003-12-14 16:33:56 +00:00
|
|
|
return true;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
RGBColor const & Branch::getColor() const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
return color_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
void Branch::setColor(RGBColor const & c)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
|
|
|
color_ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-23 20:04:05 +00:00
|
|
|
void Branch::setColor(string const & c)
|
|
|
|
{
|
|
|
|
if (c.size() == 7 && c[0] == '#')
|
2006-10-21 00:16:43 +00:00
|
|
|
color_ = RGBColor(c);
|
2006-03-23 20:04:05 +00:00
|
|
|
else
|
|
|
|
// no color set or invalid color - use normal background
|
2006-11-30 00:04:51 +00:00
|
|
|
theApp()->getRgbColor(LColor::background, color_);
|
2006-03-23 20:04:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:16:45 +00:00
|
|
|
Branch * BranchList::find(docstring const & name)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
List::iterator it =
|
2004-01-05 15:49:40 +00:00
|
|
|
std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
|
2003-12-14 16:33:56 +00:00
|
|
|
return it == list.end() ? 0 : &*it;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 15:49:40 +00:00
|
|
|
|
2006-11-03 15:16:45 +00:00
|
|
|
Branch const * BranchList::find(docstring const & name) const
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
List::const_iterator it =
|
2004-01-05 15:49:40 +00:00
|
|
|
std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
|
2003-12-14 16:33:56 +00:00
|
|
|
return it == list.end() ? 0 : &*it;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
2004-01-05 15:49:40 +00:00
|
|
|
|
2006-11-03 15:16:45 +00:00
|
|
|
bool BranchList::add(docstring const & s)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2003-12-14 16:33:56 +00:00
|
|
|
bool added = false;
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring::size_type i = 0;
|
2003-08-17 11:28:23 +00:00
|
|
|
while (true) {
|
2006-11-03 15:16:45 +00:00
|
|
|
docstring::size_type const j = s.find_first_of(separator_, i);
|
|
|
|
docstring name;
|
|
|
|
if (j == docstring::npos)
|
2003-08-17 11:28:23 +00:00
|
|
|
name = s.substr(i);
|
|
|
|
else
|
|
|
|
name = s.substr(i, j - i);
|
|
|
|
// Is this name already in the list?
|
2004-01-05 15:49:40 +00:00
|
|
|
bool const already =
|
|
|
|
std::find_if(list.begin(), list.end(),
|
|
|
|
BranchNamesEqual(name)) != list.end();
|
2003-08-17 11:28:23 +00:00
|
|
|
if (!already) {
|
2003-12-14 16:33:56 +00:00
|
|
|
added = true;
|
2003-08-17 11:28:23 +00:00
|
|
|
Branch br;
|
|
|
|
br.setBranch(name);
|
|
|
|
br.setSelected(false);
|
|
|
|
list.push_back(br);
|
|
|
|
}
|
2006-11-03 15:16:45 +00:00
|
|
|
if (j == docstring::npos)
|
2003-08-17 11:28:23 +00:00
|
|
|
break;
|
2003-09-09 17:25:35 +00:00
|
|
|
i = j + 1;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
2003-12-14 16:33:56 +00:00
|
|
|
return added;
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:16:45 +00:00
|
|
|
bool BranchList::remove(docstring const & s)
|
2003-08-17 11:28:23 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
size_t const size = list.size();
|
2004-01-05 15:49:40 +00:00
|
|
|
list.remove_if(BranchNamesEqual(s));
|
2003-12-14 16:33:56 +00:00
|
|
|
return size != list.size();
|
2003-08-17 11:28:23 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|