From 741bd1221aa56a6e278d6f8280a0dd7e2e901cac Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Wed, 16 Jul 2008 15:29:00 +0000 Subject: [PATCH] Fix for bug 5053. There are still some serious problems here, though, as (a) "unknown" cannot be translated and (b) the way the code was re-written, it will fail if unknown and translated layout names are used. This is because it completely subverts the use of a multicolumn model. I'll try to fix that, too. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25670 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/GuiToolbar.cpp | 8 ++++---- src/support/lstrings.cpp | 11 ++++++++++- src/support/lstrings.h | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/frontends/qt4/GuiToolbar.cpp b/src/frontends/qt4/GuiToolbar.cpp index 119ebba01e..060cd40c70 100644 --- a/src/frontends/qt4/GuiToolbar.cpp +++ b/src/frontends/qt4/GuiToolbar.cpp @@ -635,9 +635,9 @@ void GuiLayoutBox::selected(int index) { // get selection QModelIndex mindex = filterModel_->mapToSource(filterModel_->index(index, 1)); - docstring const layoutName = rtrim( - qstring_to_ucs4(model_->itemFromIndex(mindex)->text()), " (unknown)"); - + docstring layoutName = qstring_to_ucs4(model_->itemFromIndex(mindex)->text()); + if (suffixIs(layoutName, from_ascii(" (unknown)"))) + layoutName = layoutName.substr(0, layoutName.size() - 10); // = len(" (unknown)") owner_.setFocus(); if (!text_class_) { @@ -655,7 +655,7 @@ void GuiLayoutBox::selected(int index) resetFilter(); return; } - LYXERR0("ERROR (layoutSelected): layout not found!"); + LYXERR0("ERROR (layoutSelected): layout " << layoutName << " not found!"); } diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index 6792cf6bcd..2bd5f4ea95 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -495,7 +495,8 @@ bool prefixIs(docstring const & a, docstring const & pre) bool suffixIs(string const & a, char c) { - if (a.empty()) return false; + if (a.empty()) + return false; return a[a.length() - 1] == c; } @@ -516,6 +517,14 @@ bool suffixIs(string const & a, string const & suf) } +bool suffixIs(docstring const & a, docstring const & suf) +{ + size_t const suflen = suf.length(); + size_t const alen = a.length(); + return suflen <= alen && a.compare(alen - suflen, suflen, suf) == 0; +} + + bool containsOnly(string const & s, string const & cset) { return s.find_first_not_of(cset) == string::npos; diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 3b86053ace..9130f687c8 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -103,8 +103,9 @@ bool prefixIs(docstring const & str, docstring const & pre); bool suffixIs(std::string const &, char); bool suffixIs(docstring const &, char_type); -/// Does the std::string end with this suffix? +/// Does the string end with this suffix? bool suffixIs(std::string const &, std::string const &); +bool suffixIs(docstring const &, docstring const &); /// inline bool contains(std::string const & a, std::string const & b) -- 2.39.2