diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 643ce55f22..139bdb4366 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -72,6 +72,7 @@ #include #include #include +#include #include #include @@ -3527,12 +3528,16 @@ void GuiDocument::saveDocDefault() void GuiDocument::updateAvailableModules() { modules_av_model_.clear(); - list const & modInfoList = getModuleInfo(); - list::const_iterator mit = modInfoList.begin(); - list::const_iterator men = modInfoList.end(); - for (int i = 0; mit != men; ++mit, ++i) - modules_av_model_.insertRow(i, mit->name, mit->id, - mit->description); + list modInfoList = getModuleInfo(); + // Sort names according to the locale + modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) { + return 0 < b.name.localeAwareCompare(a.name); + }); + int i = 0; + for (modInfoStruct const & m : modInfoList) { + modules_av_model_.insertRow(i, m.name, m.id, m.description); + ++i; + } } @@ -3540,11 +3545,11 @@ void GuiDocument::updateSelectedModules() { modules_sel_model_.clear(); list const selModList = getSelectedModules(); - list::const_iterator mit = selModList.begin(); - list::const_iterator men = selModList.end(); - for (int i = 0; mit != men; ++mit, ++i) - modules_sel_model_.insertRow(i, mit->name, mit->id, - mit->description); + int i = 0; + for (modInfoStruct const & m : selModList) { + modules_sel_model_.insertRow(i, m.name, m.id, m.description); + ++i; + } } @@ -3706,20 +3711,18 @@ list const & GuiDocument::getModuleInfo() list const - GuiDocument::makeModuleInfo(LayoutModuleList const & mods) +GuiDocument::makeModuleInfo(LayoutModuleList const & mods) { - LayoutModuleList::const_iterator it = mods.begin(); - LayoutModuleList::const_iterator end = mods.end(); list mInfo; - for (; it != end; ++it) { + for (string const & name : mods) { modInfoStruct m; - m.id = *it; - LyXModule const * const mod = theModuleList[*it]; + LyXModule const * const mod = theModuleList[name]; if (mod) - // FIXME Unicode - m.name = toqstr(translateIfPossible(from_utf8(mod->getName()))); - else - m.name = toqstr(*it) + toqstr(" (") + qt_("Not Found") + toqstr(")"); + m = modInfo(*mod); + else { + m.id = name; + m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")"); + } mInfo.push_back(m); } return mInfo; @@ -3911,27 +3914,35 @@ bool GuiDocument::hasMonolithicExpertSet(QString const & font) const } +//static +GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod) +{ + // FIXME Unicode: docstrings would be better for these parameters but this + // change requires a lot of others + modInfoStruct m; + m.id = mod.getID(); + m.name = toqstr(translateIfPossible(from_utf8(mod.getName()))); + QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription()))); + // Find the first sentence of the description + QTextBoundaryFinder bf(QTextBoundaryFinder::Sentence, desc); + int pos = bf.toNextBoundary(); + if (pos > 0) + desc.truncate(pos); + QString modulename = QString(qt_("(Module name: %1)")).arg(toqstr(m.id)); + // Tooltip is the desc followed by the module name + m.description = QString("%1%2") + .arg(desc.isEmpty() ? QString() : QString("

%1

").arg(desc), + modulename); + return m; +} + + void GuiDocument::loadModuleInfo() { moduleNames_.clear(); - LyXModuleList::const_iterator it = theModuleList.begin(); - LyXModuleList::const_iterator end = theModuleList.end(); - for (; it != end; ++it) { - modInfoStruct m; - m.id = it->getID(); - // FIXME Unicode - m.name = toqstr(translateIfPossible(from_utf8(it->getName()))); - // this is supposed to give us the first sentence of the description - // FIXME Unicode - QString desc = - toqstr(translateIfPossible(from_utf8(it->getDescription()))); - int const pos = desc.indexOf("."); - if (pos > 0) - desc.truncate(pos + 1); - m.description = desc; - if (it->category().substr(0, 8) != "Citation") - moduleNames_.push_back(m); - } + for (LyXModule const & mod : theModuleList) + if (mod.category().substr(0, 8) != "Citation") + moduleNames_.push_back(modInfo(mod)); } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 5bf1340fc9..097abfff65 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -41,6 +41,7 @@ namespace lyx { class BufferParams; class LayoutModuleList; +class LyXModule; class TextClass; namespace frontend { @@ -217,6 +218,8 @@ private: std::string id; QString description; }; + /// + static modInfoStruct modInfo(LyXModule const & mod); /// List of available modules std::list const & getModuleInfo(); /// Modules in use in current buffer