commit 9a36ffd1e3f55660eb22690e126f97faae2b0ccb
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Wed Aug 9 16:09:50 2017 +0200

    Sort external templates locale-aware
    
    Fixes: #10738
---
 src/frontends/qt4/GuiExternal.cpp |   12 +++++++++---
 src/frontends/qt4/qt_helpers.cpp  |    6 ++++++
 src/frontends/qt4/qt_helpers.h    |    3 +++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/frontends/qt4/GuiExternal.cpp 
b/src/frontends/qt4/GuiExternal.cpp
index 07eb8fc..f994aaf 100644
--- a/src/frontends/qt4/GuiExternal.cpp
+++ b/src/frontends/qt4/GuiExternal.cpp
@@ -202,10 +202,16 @@ GuiExternal::GuiExternal(GuiView & lv)
        external::TemplateManager::Templates::const_iterator i1, i2;
        i1 = external::TemplateManager::get().getTemplates().begin();
        i2 = external::TemplateManager::get().getTemplates().end();
+       QMap<QString, QString> localizedTemplates;
        for (; i1 != i2; ++i1)
-               externalCO->addItem(qt_(i1->second.guiName), 
toqstr(i1->second.lyxName));
-       // Sort alphabetically by(localized) GUI name
-       externalCO->model()->sort(0);
+               localizedTemplates.insert(qt_(i1->second.guiName), 
toqstr(i1->second.lyxName));
+       // Sort alphabetically by (localized) GUI name
+       QStringList keys = localizedTemplates.keys();
+       qSort(keys.begin(), keys.end(), SortLocaleAware);
+       for (QString & key : keys) {
+               QString const value = localizedTemplates[key];
+               externalCO->addItem(key, value);
+       }
 
        // Fill the origins combo
        for (size_t i = 0; i != sizeof(origins) / sizeof(origins[0]); ++i)
diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp
index 63125d8..d228510 100644
--- a/src/frontends/qt4/qt_helpers.cpp
+++ b/src/frontends/qt4/qt_helpers.cpp
@@ -214,6 +214,12 @@ QString formatLocFPNumber(double d)
 }
 
 
+bool SortLocaleAware(QString const & lhs, QString const & rhs)
+{
+       return QString::localeAwareCompare(lhs, rhs) < 0;
+}
+
+
 bool ColorSorter(ColorCode lhs, ColorCode rhs)
 {
        return compare_no_case(lcolor.getGUIName(lhs), lcolor.getGUIName(rhs)) 
< 0;
diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h
index 023e86a..52057fc 100644
--- a/src/frontends/qt4/qt_helpers.h
+++ b/src/frontends/qt4/qt_helpers.h
@@ -76,6 +76,9 @@ void doubleToWidget(QLineEdit * input, std::string const & 
value,
  */
 QString formatLocFPNumber(double d);
 
+/// Method to sort QStrings locale-aware (e.g. in combo widgets)
+bool SortLocaleAware(QString const & lhs, QString const & rhs);
+
 /// Method to sort colors by GUI name in combo widgets
 bool ColorSorter(ColorCode lhs, ColorCode rhs);
 

Reply via email to