From: Juergen Spitzmueller Date: Sat, 20 Apr 2019 07:28:46 +0000 (+0200) Subject: Add system/local icon to available modules list X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=eb0da025cb0e099b4498aa4c761c4c155b3bde5f;p=features.git Add system/local icon to available modules list Also markup modules with missing requirements (like we do for layouts) --- diff --git a/lib/configure.py b/lib/configure.py index 1f962081eb..9247957948 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -1472,7 +1472,7 @@ def checkModulesConfig(): ## It has been automatically generated by configure ## Use "Options/Reconfigure" if you need to update it after a ## configuration change. -## "ModuleName" "filename" "Description" "Packages" "Requires" "Excludes" "Category" +## "ModuleName" "filename" "Description" "Packages" "Requires" "Excludes" "Category" "Local" ''') # build the list of available modules @@ -1587,8 +1587,11 @@ def processModuleFile(file, filename, bool_docbook): cm.write(line + '\n') cm.close() - return (b'"%s" "%s" "%s" "%s" "%s" "%s" "%s"\n' - % (modname, filename, desc, pkgs, req, excl, catgy)) + local = "true" + if (file.startswith(srcdir)): + local = "false" + return (b'"%s" "%s" "%s" "%s" "%s" "%s" "%s" "%s"\n' + % (modname, filename, desc, pkgs, req, excl, catgy, local)) def checkCiteEnginesConfig(): diff --git a/src/ModuleList.cpp b/src/ModuleList.cpp index 51a9427766..356bbe9379 100644 --- a/src/ModuleList.cpp +++ b/src/ModuleList.cpp @@ -37,10 +37,10 @@ ModuleList theModuleList; LyXModule::LyXModule(string const & n, string const & i, string const & d, vector const & p, vector const & r, vector const & e, - string const & c): + string const & c, bool const local): name_(n), id_(i), description_(d), package_list_(p), required_modules_(r), excluded_modules_(e), category_(c), - checked_(false), available_(false) + checked_(false), available_(false), local_(local) { filename_ = id_ + ".module"; } @@ -199,9 +199,13 @@ bool ModuleList::read() break; string const catgy = lex.getString(); LYXERR(Debug::TCLASS, "Category: " << catgy); + if (!lex.next()) + break; + bool const local = lex.getString() == "true"; + LYXERR(Debug::TCLASS, "Local: " << local); // This code is run when we have - // modName, fname, desc, pkgs, req, exc, and catgy - addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy); + // modName, fname, desc, pkgs, req, exc, catgy, and local + addLayoutModule(modname, fname, desc, pkgs, req, exc, catgy, local); } // end switch } //end while @@ -216,9 +220,9 @@ bool ModuleList::read() void ModuleList::addLayoutModule(string const & modname, string const & filename, string const & description, vector const & pkgs, vector const & req, - vector const & exc, string const & catgy) + vector const & exc, string const & catgy, bool const local) { - LyXModule lm(modname, filename, description, pkgs, req, exc, catgy); + LyXModule lm(modname, filename, description, pkgs, req, exc, catgy, local); modlist_.push_back(lm); } diff --git a/src/ModuleList.h b/src/ModuleList.h index 9194f031e0..fdc6639a12 100644 --- a/src/ModuleList.h +++ b/src/ModuleList.h @@ -54,7 +54,7 @@ public: std::vector const & packagelist, std::vector const & requires, std::vector const & excludes, - std::string const & catgy); + std::string const & catgy, bool const local); /// whether the required packages are available bool isAvailable() const; /// the missing prerequisites, if any @@ -78,6 +78,8 @@ public: { return excluded_modules_; } /// std::string category() const { return category_; } + /// Is this a local module (from the user directory)? + bool isLocal() const { return local_; } /// \return true if the module is compatible with this one, i.e., /// it does not exclude us and we do not exclude it. /// this will also return true if modname is unknown and we do not @@ -110,6 +112,8 @@ private: /// mutable bool available_; /// + mutable bool local_; + /// mutable std::vector prerequisites_; }; @@ -149,7 +153,7 @@ public: void addLayoutModule(std::string const &, std::string const &, std::string const &, std::vector const &, std::vector const &, std::vector const &, - std::string const &); + std::string const &, bool const); /// std::vector modlist_; }; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 85257b423b..744d0254c3 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #include #include #include @@ -1767,6 +1768,10 @@ void GuiDocument::filterModules(QString const & str) modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) { return 0 < b.name.localeAwareCompare(a.name); }); + + QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png")); + QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png")); + int i = 0; for (modInfoStruct const & m : modInfoList) { if (m.name.contains(str, Qt::CaseInsensitive) || contains(m.id, fromqstr(str))) { @@ -1774,6 +1779,10 @@ void GuiDocument::filterModules(QString const & str) item->setData(m.name, Qt::DisplayRole); item->setData(toqstr(m.id), Qt::UserRole); item->setData(m.description, Qt::ToolTipRole); + if (m.local) + item->setIcon(user_icon); + else + item->setIcon(system_icon); modules_av_model_.insertRow(i, item); ++i; } @@ -4239,9 +4248,13 @@ void GuiDocument::updateAvailableModules() modInfoList.sort([](modInfoStruct const & a, modInfoStruct const & b) { return 0 < b.name.localeAwareCompare(a.name); }); + QIcon user_icon(getPixmap("images/", "lyxfiles-user", "svgz,png")); + QIcon system_icon(getPixmap("images/", "lyxfiles-system", "svgz,png")); int i = 0; QFont catfont; catfont.setBold(true); + QBrush unavbrush; + unavbrush.setColor(Qt::gray); for (modInfoStruct const & m : modInfoList) { QStandardItem * item = new QStandardItem(); QStandardItem * catItem = new QStandardItem(); @@ -4258,8 +4271,14 @@ void GuiDocument::updateAvailableModules() item->setEditable(false); catItem->setEditable(false); item->setData(m.name, Qt::DisplayRole); + if (m.missingreqs) + item->setForeground(unavbrush); item->setData(toqstr(m.id), Qt::UserRole); item->setData(m.description, Qt::ToolTipRole); + if (m.local) + item->setIcon(user_icon); + else + item->setIcon(system_icon); catItem->appendRow(item); } modules_av_model_.sort(0); @@ -4612,6 +4631,8 @@ GuiDocument::makeModuleInfo(LayoutModuleList const & mods) else { m.id = name; m.name = toqstr(name + " (") + qt_("Not Found") + toqstr(")"); + m.local = false; + m.missingreqs = true; } mInfo.push_back(m); } @@ -4807,7 +4828,12 @@ GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod) // change requires a lot of others modInfoStruct m; m.id = mod.getID(); - m.name = toqstr(translateIfPossible(from_utf8(mod.getName()))); + QString const guiname = toqstr(translateIfPossible(from_utf8(mod.getName()))); + m.missingreqs = !isModuleAvailable(mod.getID()); + if (m.missingreqs) { + m.name = QString(qt_("%1 (missing req.)")).arg(guiname); + } else + m.name = guiname; m.category = mod.category().empty() ? qt_("Miscellaneous") : toqstr(translateIfPossible(from_utf8(mod.category()))); QString desc = toqstr(translateIfPossible(from_utf8(mod.getDescription()))); @@ -4816,11 +4842,15 @@ GuiDocument::modInfoStruct GuiDocument::modInfo(LyXModule const & mod) 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") + m.local = mod.isLocal(); + QString const mtype = m.local ? qt_("personal module") : qt_("distributed module"); + QString modulename = QString(qt_("Module name: %1 (%2)")).arg(toqstr(m.id)).arg(mtype); + // Tooltip is the desc followed by the module name and the type + m.description = QString("%1%2") .arg(desc.isEmpty() ? QString() : QString("

%1

").arg(desc), modulename); + if (m.missingreqs) + m.description += QString("

%1

").arg(qt_("Note: Some requirements for this module are missing!")); return m; } diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index 20883db1b9..7057140118 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -258,6 +258,8 @@ private: std::string id; QString description; QString category; + bool local; + bool missingreqs; }; /// static modInfoStruct modInfo(LyXModule const & mod);