commit 95da270711de3c0d3705684e78b16091277b62ca
Author: Daniel Ramoeller <[email protected]>
Date: Sun May 29 15:59:34 2022 +0200
Check for icon aliases
The aliases are defined by a file in the (system or user) image
directory. The format is pretty simple: each line is like
<str1> <str2>
Where every instance of <str1> will be replaced with <str2>.
Fixes bug #12509.
---
lib/Makefile.am | 2 +-
lib/images/icon.aliases | 6 +++++
lib/ui/stdtoolbars.inc | 21 +++++++++++--------
src/frontends/qt/GuiApplication.cpp | 38 +++++++++++++++++++++++++++++++++-
4 files changed, 55 insertions(+), 12 deletions(-)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 664eaa4..33120fe 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,7 +8,7 @@ EXTRA_DIST = examples/CMakeLists.txt scripts/CMakeLists.txt
examples/README.new_
dist_pkgdata_DATA = CREDITS autocorrect chkconfig.ltx \
encodings layouttranslations languages latexfonts RELEASE-NOTES \
- symbols syntax.default unicodesymbols
+ symbols syntax.default unicodesymbols images/icon.aliases
# We use DATA now instead of PYTHON because automake 1.11.2 complains.
# Note that we "chmod 755" manually this file in install-data-hook.
diff --git a/lib/images/icon.aliases b/lib/images/icon.aliases
new file mode 100644
index 0000000..820133b
--- /dev/null
+++ b/lib/images/icon.aliases
@@ -0,0 +1,6 @@
+# Aliases for icon names. This allows to avoid duplication of icons
+# Each line is of the form
+# <original substring> <replacement substring>
+dialog-toggle dialog-show
+layout_ layout-toggle_
+tabular-feature_set tabular-feature_toggle
diff --git a/lib/ui/stdtoolbars.inc b/lib/ui/stdtoolbars.inc
index 467c6f6..2e6663a 100644
--- a/lib/ui/stdtoolbars.inc
+++ b/lib/ui/stdtoolbars.inc
@@ -28,7 +28,7 @@
#
# Toolbar "name" "GUI Name"
#
-# Only seven commands are allowed inside the Toolbar and End
+# Only eight commands are allowed inside the Toolbar and End
# directives:
# Item "The tooltip" "<action> [<parameter>]" adds an icon to the toolbar
performing
# "<action> <parameter>"
@@ -37,9 +37,9 @@
# Item Emphasized set-emph
#
# BidiItem is like Item, but an alternative icon (with name ending
-# with "+rtl") will be used <hen the paragraph has a right-to-left
-# layout. If this alternative icon does not exist, the LtR icon will
-# be mirrored instead.
+# with "+rtl") will be used <hen the paragraph has a right-to-left
+# layout. If this alternative icon does not exist, the LtR icon will
+# be mirrored instead.
#
# Layouts adds the layouts combo-box to the toolbar
#
@@ -48,23 +48,26 @@
# Minibuffer adds the command buffer (only one may exist)
#
# TableInsert "The tooltip" adds a special widget for quick
-# insertion of tables
+# insertion of tables
#
# PopupMenu "name" "The tooltip"
#
-# ... inserts a button with a popup menu derived from Toolbar "name"
+# ... inserts a button with a popup menu derived from Toolbar "name"
#
# IconPalette "name" "The tooltip"
#
-# ... inserts a button with a popup iconpalette derived from Toolbar "name"
+# ... inserts a button with a popup icon palette derived from Toolbar
"name"
#
#
-# The icons are found in the lib/images/ direcory under the name
+# The icons are found in the lib/images/ directory under the name
# action.png or action_parameter.png, except for math-insert, which
# is e.g. lib/image/math/sum.png. Note that some characters are
# replaced (e.g. ')' -> rbracket).
#
-# All other lyx commands will get a "unknown" icon.
+# Note that the lib/images/icon.aliases file can be used to specify
+# fallback icons for some functions.
+#
+# All other LyX commands will get a "unknown" icon.
#
# This is the default toolbar:
diff --git a/src/frontends/qt/GuiApplication.cpp
b/src/frontends/qt/GuiApplication.cpp
index c15f2d7..b277843 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -525,6 +525,36 @@ QString themeIconName(QString const & action)
}
+namespace {
+
+QString getAlias(QString name) {
+ static bool has_aliases = false;
+ static vector <pair<QString,QString>> aliases;
+ // Initialize aliases list (once).
+ if (!has_aliases) {
+ FileName alfile = libFileSearch("images", "icon.aliases");
+ if (alfile.exists()) {
+ Lexer lex;
+ lex.setFile(alfile);
+ while(lex.isOK()) {
+ string from, to;
+ lex >> from >> to;
+ if (!from.empty())
+ aliases.push_back({toqstr(from),
toqstr(to)});
+ }
+ }
+ has_aliases = true;
+ }
+ // check for the following aliases
+ for (auto alias : aliases) {
+ if (name.contains(alias.first))
+ name.replace(alias.first, alias.second);
+ }
+ return name;
+}
+
+}
+
IconInfo iconInfo(FuncRequest const & f, bool unknown, bool rtl)
{
IconInfo res;
@@ -538,9 +568,10 @@ IconInfo iconInfo(FuncRequest const & f, bool unknown,
bool rtl)
name.replace(' ', '_');
name.replace(';', '_');
name.replace('\\', "backslash");
- // avoid duplication for these
- name.replace("dialog-toggle", "dialog-show");
names << name;
+ QString alias = getAlias(name);
+ if (alias != name)
+ names << alias;
// then special default icon for some lfuns
switch (f.action()) {
@@ -572,6 +603,9 @@ IconInfo iconInfo(FuncRequest const & f, bool unknown, bool
rtl)
// next thing to try is function name alone
names << lfunname;
+ QString alias = getAlias(lfunname);
+ if (alias != lfunname)
+ names << alias;
// and finally maybe the unknown icon
if (unknown)
--
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs