mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
GuiDocument: some polishing of the list of modules.
* The tooltips in the list of modules now include the names of the modules. * The tooltips of modules more consistent across the widgets. * Sort the list of modules according to the locale (i.e. "É" comes before "F"). * Replace a hand-made sentence boundary finder by Qt's.
This commit is contained in:
parent
ee72e9520a
commit
8cf138e173
@ -72,6 +72,7 @@
|
||||
#include <QCloseEvent>
|
||||
#include <QFontDatabase>
|
||||
#include <QScrollBar>
|
||||
#include <QTextBoundaryFinder>
|
||||
#include <QTextCursor>
|
||||
|
||||
#include <sstream>
|
||||
@ -3527,12 +3528,16 @@ void GuiDocument::saveDocDefault()
|
||||
void GuiDocument::updateAvailableModules()
|
||||
{
|
||||
modules_av_model_.clear();
|
||||
list<modInfoStruct> const & modInfoList = getModuleInfo();
|
||||
list<modInfoStruct>::const_iterator mit = modInfoList.begin();
|
||||
list<modInfoStruct>::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<modInfoStruct> 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<modInfoStruct> const selModList = getSelectedModules();
|
||||
list<modInfoStruct>::const_iterator mit = selModList.begin();
|
||||
list<modInfoStruct>::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<GuiDocument::modInfoStruct> const & GuiDocument::getModuleInfo()
|
||||
|
||||
|
||||
list<GuiDocument::modInfoStruct> const
|
||||
GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
|
||||
GuiDocument::makeModuleInfo(LayoutModuleList const & mods)
|
||||
{
|
||||
LayoutModuleList::const_iterator it = mods.begin();
|
||||
LayoutModuleList::const_iterator end = mods.end();
|
||||
list<modInfoStruct> 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<i>%2</i>")
|
||||
.arg(desc.isEmpty() ? QString() : QString("<p>%1</p>").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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<modInfoStruct> const & getModuleInfo();
|
||||
/// Modules in use in current buffer
|
||||
|
Loading…
Reference in New Issue
Block a user