Le 15/05/2020 à 12:09, Pavel Sanda a écrit :
On Fri, May 15, 2020 at 11:10:01AM +0200, Jean-Marc Lasgouttes wrote:
Try this one instead (do not worry, recompilation will be limited).

Patch missing... P


Indeed, thanks.

>From f311d844da8a515cae4abe96d7ce24e7737214c0 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Thu, 14 May 2020 16:35:51 +0200
Subject: [PATCH] WIP: rewite iconName

This is instrumented to see the effect of resources
---
 src/frontends/qt/GuiApplication.cpp | 125 +++++++++++++---------------
 1 file changed, 59 insertions(+), 66 deletions(-)

diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index 5c5c2a6739..4530f4f98e 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -75,6 +75,7 @@
 #include "support/os.h"
 #include "support/Package.h"
 #include "support/TempFile.h"
+#include "support/pmprof.h"
 
 #ifdef Q_OS_MAC
 #include "support/AppleScript.h"
@@ -489,83 +490,73 @@ QString themeIconName(QString const & action)
 QString iconName(FuncRequest const & f, bool unknown, QString const & suffix)
 {
 	initializeResources();
-	QString name1;
-	QString name2;
-	QString path;
-	switch (f.action()) {
-	case LFUN_MATH_INSERT:
-		if (!f.argument().empty()) {
-			path = "math/";
-			name1 = findImg(toqstr(f.argument()).mid(1));
-		}
-		break;
-	case LFUN_MATH_DELIM:
-	case LFUN_MATH_BIGDELIM:
-		path = "math/";
-		name1 = findImg(toqstr(f.argument()));
-		break;
-	case LFUN_CALL:
-		path = "commands/";
-		name1 = toqstr(f.argument());
-		break;
-	case LFUN_COMMAND_ALTERNATIVES: {
-		// use the first of the alternative commands
-		docstring firstcom;
-		docstring dummy = split(f.argument(), firstcom, ';');
-		name1 = toqstr(firstcom);
-		name1.replace(' ', '_');
-		break;
-	}
-	default:
-		name2 = toqstr(lyxaction.getActionName(f.action()));
-		name1 = name2;
-
-		if (!f.argument().empty()) {
-			name1 = name2 + ' ' + toqstr(f.argument());
+	QStringList names;
+
+	QString lfunname = toqstr(lyxaction.getActionName(f.action()));
+	if (!f.argument().empty()) {
+		// if there are arguments, first search an icon which name is the full thing
+		QString name = lfunname  + ' ' + toqstr(f.argument());
+		name.replace(' ', '_');
+		name.replace('\\', "backslash");
+		names << name;
+
+		// then special default icon for some lfuns
+		switch (f.action()) {
+		case LFUN_MATH_INSERT:
+			names <<  "math/" + findImg(toqstr(f.argument()).mid(1));
+			break;
+		case LFUN_MATH_DELIM:
+		case LFUN_MATH_BIGDELIM:
+			names << "math/" + findImg(toqstr(f.argument()));
+			break;
+		case LFUN_CALL:
+			names << "commands/" + toqstr(f.argument());
+			break;
+		case LFUN_COMMAND_ALTERNATIVES: {
+			// use the first of the alternative commands
+			docstring firstcom;
+			docstring dummy = split(f.argument(), firstcom, ';');
+			QString name1 = toqstr(firstcom);
 			name1.replace(' ', '_');
-			name1.replace('\\', "backslash");
+			names << name1;
+			break;
+		}
+		default:
+			break;
 		}
 	}
 
-	// maybe a suffix?
-	name1 += suffix;
-	name2 += suffix;
+	// last thing to try is function name
+	names << lfunname;
 
+	search_mode mode = theGuiApp()->imageSearchMode();
+#if 1
 	QStringList imagedirs;
 	imagedirs << "images/" << "images/ipa/";
-	search_mode mode = theGuiApp()->imageSearchMode();
-	for (int i = 0; i < imagedirs.size(); ++i) {
-		QString imagedir = imagedirs.at(i) + path;
-		FileName fname = imageLibFileSearch(imagedir, name1, "svgz,png", mode);
-		if (fname.exists())
-			return toqstr(fname.absFileName());
-
-		fname = imageLibFileSearch(imagedir, name2, "svgz,png", mode);
-		if (fname.exists())
-			return toqstr(fname.absFileName());
-	}
+	for (QString const & imagedir : imagedirs)
+		for (QString const & name : names) {
+			QString id = imagedir;
+			FileName fname = imageLibFileSearch(id, name + suffix, "svgz,png", mode);
+			if (fname.exists())
+				return toqstr(fname.absFileName());
+		}
+#endif
 
-	path = ":/images/" + path;
-	QDir res(path);
+	QString const resdir(":/images/");
+	QDir res(resdir);
 	if (!res.exists()) {
-		LYXERR0("Directory " << path << " not found in resource!");
+		LYXERR0("Directory :/images/ not found in resource!");
 		return QString();
 	}
-	if (res.exists(name1 + ".svgz"))
-		return path + name1 + ".svgz";
-	else if (res.exists(name1 + ".png"))
-		return path + name1 + ".png";
-
-	if (res.exists(name2 + ".svgz"))
-		return path + name2 + ".svgz";
-	else if (res.exists(name2 + ".png"))
-		return path + name2 + ".png";
-
-	LYXERR(Debug::GUI, "Cannot find icon with filename "
-			   << "\"" << name1 << ".{svgz,png}\""
-			   << " or filename "
-			   << "\"" << name2 << ".{svgz,png}\""
-			   << " for command \""
+
+	for (QString const & name : names) {
+		if (res.exists(name + suffix + ".svgz"))
+			return resdir + name + ".svgz";
+		if (res.exists(name + suffix + ".png"))
+			return resdir + name + ".png";
+	}
+
+	LYXERR(Debug::GUI, "Cannot find icon for command \""
 			   << lyxaction.getActionName(f.action())
 			   << '(' << to_utf8(f.argument()) << ")\"");
 
@@ -611,6 +602,8 @@ QPixmap getPixmap(QString const & path, QString const & name, QString const & ex
 
 QIcon getIcon(FuncRequest const & f, bool unknown, bool rtl)
 {
+	PROFILE_THIS_BLOCK(getIcon);
+
 #if (QT_VERSION >= 0x040600)
 	if (lyxrc.use_system_theme_icons) {
 		// use the icons from system theme that are available
-- 
2.25.1

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to