From 49070b4c004594c295b80c6612e368b62f5d44f3 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 3 Nov 2006 15:16:45 +0000 Subject: [PATCH] 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 --- src/BranchList.C | 22 +++++++++--------- src/BranchList.h | 25 +++++++++++---------- src/MenuBackend.C | 2 +- src/bufferparams.C | 7 +++--- src/factory.C | 4 ++-- src/frontends/controllers/ControlDocument.C | 5 +++-- src/frontends/qt4/QBranch.C | 8 +++---- src/frontends/qt4/QBranches.C | 9 ++++---- src/insets/insetbranch.C | 8 +++---- src/insets/insetbranch.h | 4 ++-- src/lyxlex.C | 10 +++++++++ src/lyxlex.h | 2 ++ 12 files changed, 59 insertions(+), 47 deletions(-) diff --git a/src/BranchList.C b/src/BranchList.C index 90aabdc035..44c98e4a70 100644 --- a/src/BranchList.C +++ b/src/BranchList.C @@ -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)); diff --git a/src/BranchList.h b/src/BranchList.h index 77b8d2be93..dd89a261d7 100644 --- a/src/BranchList.h +++ b/src/BranchList.h @@ -32,7 +32,8 @@ #include "Color.h" -#include +#include "support/docstring.h" + #include @@ -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 { 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_; }; diff --git a/src/MenuBackend.C b/src/MenuBackend.C index fddccfb6c8..734b1dd46f 100644 --- a/src/MenuBackend.C +++ b/src/MenuBackend.C @@ -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(ii) + ". " + label + char_type('|') + convert(ii); tomenu.addWithStatusCheck(MenuItem(MenuItem::Command, label, diff --git a/src/bufferparams.C b/src/bufferparams.C index 1af925829e..bd7167a3fb 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -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" diff --git a/src/factory.C b/src/factory.C index 43930ac8c5..86f6119bce 100644 --- a/src/factory.C +++ b/src/factory.C @@ -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)); } diff --git a/src/frontends/controllers/ControlDocument.C b/src/frontends/controllers/ControlDocument.C index 95d8e1ac4e..b42ef8fb31 100644 --- a/src/frontends/controllers/ControlDocument.C +++ b/src/frontends/controllers/ControlDocument.C @@ -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)); } diff --git a/src/frontends/qt4/QBranch.C b/src/frontends/qt4/QBranch.C index 002353cbcb..c37cc29e58 100644 --- a/src/frontends/qt4/QBranch.C +++ b/src/frontends/qt4/QBranch.C @@ -23,8 +23,6 @@ #include -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; } diff --git a/src/frontends/qt4/QBranches.C b/src/frontends/qt4/QBranches.C index f8a9a1362c..35f5c3ad77 100644 --- a/src/frontends/qt4/QBranches.C +++ b/src/frontends/qt4/QBranches.C @@ -29,7 +29,6 @@ #include #include -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) diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 9671ef86b5..21d77944c0 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -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'; } diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h index ca708e177c..2a8721860b 100644 --- a/src/insets/insetbranch.h +++ b/src/insets/insetbranch.h @@ -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; }; diff --git a/src/lyxlex.C b/src/lyxlex.C index 69a1003678..824173ed83 100644 --- a/src/lyxlex.C +++ b/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()) { diff --git a/src/lyxlex.h b/src/lyxlex.h index f33e077919..f1222d1a81 100644 --- a/src/lyxlex.h +++ b/src/lyxlex.h @@ -138,6 +138,8 @@ public: /// extract string LyXLex & operator>>(std::string &); + /// extract docstring + LyXLex & operator>>(docstring &); /// extract double LyXLex & operator>>(double &); /// extract integer -- 2.39.5