mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-26 06:15:16 +00:00
Fix problem with non-ascii branch names by converting more stuff to
docstring. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15713 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4689b5eea3
commit
49070b4c00
@ -29,13 +29,13 @@ Branch::Branch()
|
||||
}
|
||||
|
||||
|
||||
string const & Branch::getBranch() const
|
||||
docstring const & Branch::getBranch() const
|
||||
{
|
||||
return branch_;
|
||||
}
|
||||
|
||||
|
||||
void Branch::setBranch(string const & s)
|
||||
void Branch::setBranch(docstring const & s)
|
||||
{
|
||||
branch_ = s;
|
||||
}
|
||||
@ -78,7 +78,7 @@ void Branch::setColor(string const & c)
|
||||
}
|
||||
|
||||
|
||||
Branch * BranchList::find(std::string const & name)
|
||||
Branch * BranchList::find(docstring const & name)
|
||||
{
|
||||
List::iterator it =
|
||||
std::find_if(list.begin(), list.end(), BranchNamesEqual(name));
|
||||
@ -86,7 +86,7 @@ Branch * BranchList::find(std::string const & name)
|
||||
}
|
||||
|
||||
|
||||
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(), BranchNamesEqual(name));
|
||||
@ -94,14 +94,14 @@ Branch const * BranchList::find(std::string const & name) const
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -116,7 +116,7 @@ bool BranchList::add(string const & s)
|
||||
br.setSelected(false);
|
||||
list.push_back(br);
|
||||
}
|
||||
if (j == string::npos)
|
||||
if (j == docstring::npos)
|
||||
break;
|
||||
i = j + 1;
|
||||
}
|
||||
@ -124,7 +124,7 @@ bool BranchList::add(string const & s)
|
||||
}
|
||||
|
||||
|
||||
bool BranchList::remove(string const & s)
|
||||
bool BranchList::remove(docstring const & s)
|
||||
{
|
||||
size_t const size = list.size();
|
||||
list.remove_if(BranchNamesEqual(s));
|
||||
|
@ -32,7 +32,8 @@
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
#include <string>
|
||||
#include "support/docstring.h"
|
||||
|
||||
#include <list>
|
||||
|
||||
|
||||
@ -44,9 +45,9 @@ public:
|
||||
///
|
||||
Branch();
|
||||
///
|
||||
std::string const & getBranch() const;
|
||||
docstring const & getBranch() const;
|
||||
///
|
||||
void setBranch(std::string const &);
|
||||
void setBranch(docstring const &);
|
||||
///
|
||||
bool getSelected() const;
|
||||
/** Select/deselect the branch.
|
||||
@ -67,7 +68,7 @@ public:
|
||||
|
||||
private:
|
||||
///
|
||||
std::string branch_;
|
||||
docstring branch_;
|
||||
///
|
||||
bool selected_;
|
||||
///
|
||||
@ -82,7 +83,7 @@ public:
|
||||
typedef List::const_iterator const_iterator;
|
||||
|
||||
///
|
||||
BranchList() : separator_("|") {}
|
||||
BranchList() : separator_(from_ascii("|")) {}
|
||||
|
||||
///
|
||||
bool empty() const { return list.empty(); }
|
||||
@ -94,36 +95,36 @@ public:
|
||||
|
||||
/** \returns the Branch with \c name. If not found, returns 0.
|
||||
*/
|
||||
Branch * find(std::string const & name);
|
||||
Branch const * find(std::string const & name) const;
|
||||
Branch * find(docstring const & name);
|
||||
Branch const * find(docstring const & name) const;
|
||||
|
||||
/** Add (possibly multiple (separated by separator())) branches to list
|
||||
* \returns true if a branch is added.
|
||||
*/
|
||||
bool add(std::string const &);
|
||||
bool add(docstring const &);
|
||||
/** remove a branch from list by name
|
||||
* \returns true if a branch is removed.
|
||||
*/
|
||||
bool remove(std::string const &);
|
||||
bool remove(docstring const &);
|
||||
|
||||
private:
|
||||
///
|
||||
List list;
|
||||
///
|
||||
std::string separator_;
|
||||
docstring separator_;
|
||||
};
|
||||
|
||||
|
||||
class BranchNamesEqual : public std::unary_function<Branch, bool> {
|
||||
public:
|
||||
BranchNamesEqual(std::string const & name)
|
||||
BranchNamesEqual(docstring const & name)
|
||||
: name_(name) {}
|
||||
bool operator()(Branch const & branch) const
|
||||
{
|
||||
return branch.getBranch() == name_;
|
||||
}
|
||||
private:
|
||||
std::string name_;
|
||||
docstring name_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -797,7 +797,7 @@ void expandBranches(Menu & tomenu, Buffer const * buf)
|
||||
BranchList::const_iterator end = params.branchlist().end();
|
||||
|
||||
for (int ii = 1; cit != end; ++cit, ++ii) {
|
||||
docstring label = from_utf8(cit->getBranch());
|
||||
docstring label = cit->getBranch();
|
||||
if (ii < 10)
|
||||
label = convert<docstring>(ii) + ". " + label + char_type('|') + convert<docstring>(ii);
|
||||
tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label,
|
||||
|
@ -495,7 +495,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
|
||||
lex >> outputChanges;
|
||||
} else if (token == "\\branch") {
|
||||
lex.next();
|
||||
string branch = lex.getString();
|
||||
docstring branch = lex.getDocString();
|
||||
branchlist().add(branch);
|
||||
while (true) {
|
||||
lex.next();
|
||||
@ -517,7 +517,8 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
|
||||
// Update also the LColor table:
|
||||
if (color == "none")
|
||||
color = lcolor.getX11Name(LColor::background);
|
||||
lcolor.setColor(branch, color);
|
||||
// FIXME UNICODE
|
||||
lcolor.setColor(to_utf8(branch), color);
|
||||
|
||||
}
|
||||
}
|
||||
@ -639,7 +640,7 @@ void BufferParams::writeFile(ostream & os) const
|
||||
BranchList::const_iterator it = branchlist().begin();
|
||||
BranchList::const_iterator end = branchlist().end();
|
||||
for (; it != end; ++it) {
|
||||
os << "\\branch " << it->getBranch()
|
||||
os << "\\branch " << to_utf8(it->getBranch())
|
||||
<< "\n\\selected " << it->getSelected()
|
||||
<< "\n\\color " << lyx::X11hexname(it->getColor())
|
||||
<< "\n\\end_branch"
|
||||
|
@ -112,9 +112,9 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
|
||||
}
|
||||
|
||||
case LFUN_BRANCH_INSERT: {
|
||||
string arg = cmd.getArg(0);
|
||||
docstring arg = cmd.argument();
|
||||
if (arg.empty())
|
||||
arg = "none";
|
||||
arg = from_ascii("none");
|
||||
return new InsetBranch(params, InsetBranchParams(arg));
|
||||
}
|
||||
|
||||
|
@ -126,12 +126,13 @@ void ControlDocument::dispatchParams()
|
||||
BranchList::const_iterator it = branchlist.begin();
|
||||
BranchList::const_iterator const end = branchlist.end();
|
||||
for (; it != end; ++it) {
|
||||
string const & current_branch = it->getBranch();
|
||||
docstring const & current_branch = it->getBranch();
|
||||
Branch const * branch = branchlist.find(current_branch);
|
||||
string const x11hexname =
|
||||
lyx::X11hexname(branch->getColor());
|
||||
// display the new color
|
||||
string const str = current_branch + ' ' + x11hexname;
|
||||
// FIXME UNICODE
|
||||
string const str = to_utf8(current_branch) + ' ' + x11hexname;
|
||||
kernel().dispatch(FuncRequest(LFUN_SET_COLOR, str));
|
||||
}
|
||||
|
||||
|
@ -23,8 +23,6 @@
|
||||
|
||||
#include <QPushButton>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
|
||||
@ -50,7 +48,7 @@ void QBranch::update_contents()
|
||||
typedef BranchList::const_iterator const_iterator;
|
||||
|
||||
BranchList const & branchlist = controller().branchlist();
|
||||
string const cur_branch = controller().params().branch;
|
||||
docstring const cur_branch = controller().params().branch;
|
||||
|
||||
dialog_->branchCO->clear();
|
||||
|
||||
@ -59,7 +57,7 @@ void QBranch::update_contents()
|
||||
int id = 0;
|
||||
int count = 0;
|
||||
for (const_iterator it = begin; it != end; ++it, ++count) {
|
||||
string const & branch = it->getBranch();
|
||||
docstring const & branch = it->getBranch();
|
||||
dialog_->branchCO->addItem(toqstr(branch));
|
||||
|
||||
if (cur_branch == branch)
|
||||
@ -71,7 +69,7 @@ void QBranch::update_contents()
|
||||
|
||||
void QBranch::apply()
|
||||
{
|
||||
string const type = fromqstr(dialog_->branchCO->currentText());
|
||||
docstring const type = qstring_to_ucs4(dialog_->branchCO->currentText());
|
||||
controller().params().branch = type;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include <QColor>
|
||||
#include <QColorDialog>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace lyx {
|
||||
namespace frontend {
|
||||
@ -95,7 +94,7 @@ void QBranches::on_addBranchPB_pressed()
|
||||
{
|
||||
QString const new_branch = newBranchLE->text();
|
||||
if (!new_branch.isEmpty()) {
|
||||
branchlist_.add(fromqstr(new_branch));
|
||||
branchlist_.add(qstring_to_ucs4(new_branch));
|
||||
newBranchLE->clear();
|
||||
update();
|
||||
}
|
||||
@ -110,7 +109,7 @@ void QBranches::on_removePB_pressed()
|
||||
if (selItem != 0)
|
||||
sel_branch = selItem->text(0);
|
||||
if (!sel_branch.isEmpty()) {
|
||||
branchlist_.remove(fromqstr(sel_branch));
|
||||
branchlist_.remove(qstring_to_ucs4(sel_branch));
|
||||
newBranchLE->clear();
|
||||
update();
|
||||
}
|
||||
@ -137,7 +136,7 @@ void QBranches::toggleBranch(QTreeWidgetItem * item)
|
||||
QString sel_branch = item->text(0);
|
||||
if (!sel_branch.isEmpty()) {
|
||||
bool const selected = item->text(1) == qt_("Yes");
|
||||
Branch * branch = branchlist_.find(fromqstr(sel_branch));
|
||||
Branch * branch = branchlist_.find(qstring_to_ucs4(sel_branch));
|
||||
if (branch && branch->setSelected(!selected)) {
|
||||
newBranchLE->clear();
|
||||
update();
|
||||
@ -154,7 +153,7 @@ void QBranches::on_colorPB_clicked()
|
||||
if (selItem != 0)
|
||||
sel_branch = selItem->text(0);
|
||||
if (!sel_branch.isEmpty()) {
|
||||
string current_branch = fromqstr(sel_branch);
|
||||
docstring current_branch = qstring_to_ucs4(sel_branch);
|
||||
Branch * branch =
|
||||
branchlist_.find(current_branch);
|
||||
if (!branch)
|
||||
|
@ -97,11 +97,11 @@ void InsetBranch::setButtonLabel()
|
||||
font.decSize();
|
||||
font.decSize();
|
||||
|
||||
// FIXME UNICODE
|
||||
docstring s = _("Branch: ") + from_utf8(params_.branch);
|
||||
docstring s = _("Branch: ") + params_.branch;
|
||||
font.setColor(LColor::foreground);
|
||||
if (!params_.branch.empty()) {
|
||||
LColor_color c = lcolor.getFromLyXName(params_.branch);
|
||||
// FIXME UNICODE
|
||||
LColor_color c = lcolor.getFromLyXName(to_utf8(params_.branch));
|
||||
if (c == LColor::none) {
|
||||
c = LColor::error;
|
||||
s = _("Undef: ") + s;
|
||||
@ -303,7 +303,7 @@ void InsetBranchMailer::string2params(string const & in,
|
||||
|
||||
void InsetBranchParams::write(ostream & os) const
|
||||
{
|
||||
os << "Branch " << branch << '\n';
|
||||
os << "Branch " << to_utf8(branch) << '\n';
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,14 +22,14 @@ class Buffer;
|
||||
|
||||
class InsetBranchParams {
|
||||
public:
|
||||
explicit InsetBranchParams(std::string const & b = std::string())
|
||||
explicit InsetBranchParams(docstring const & b = docstring())
|
||||
: branch(b) {}
|
||||
///
|
||||
void write(std::ostream & os) const;
|
||||
///
|
||||
void read(LyXLex & lex);
|
||||
///
|
||||
std::string branch;
|
||||
docstring branch;
|
||||
};
|
||||
|
||||
|
||||
|
10
src/lyxlex.C
10
src/lyxlex.C
@ -266,6 +266,16 @@ LyXLex & LyXLex::operator>>(std::string & s)
|
||||
}
|
||||
|
||||
|
||||
LyXLex & LyXLex::operator>>(docstring & s)
|
||||
{
|
||||
if (isOK()) {
|
||||
next();
|
||||
s = getDocString();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
LyXLex & LyXLex::operator>>(double & s)
|
||||
{
|
||||
if (isOK()) {
|
||||
|
@ -138,6 +138,8 @@ public:
|
||||
|
||||
/// extract string
|
||||
LyXLex & operator>>(std::string &);
|
||||
/// extract docstring
|
||||
LyXLex & operator>>(docstring &);
|
||||
/// extract double
|
||||
LyXLex & operator>>(double &);
|
||||
/// extract integer
|
||||
|
Loading…
Reference in New Issue
Block a user