From 95da270711de3c0d3705684e78b16091277b62ca Mon Sep 17 00:00:00 2001 From: Daniel Ramoeller Date: Sun, 29 May 2022 15:59:34 +0200 Subject: [PATCH] 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 Where every instance of will be replaced with . 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(-) create mode 100644 lib/images/icon.aliases diff --git a/lib/Makefile.am b/lib/Makefile.am index 664eaa419f..33120fec84 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 0000000000..820133be8c --- /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 +# +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 467c6f6b12..2e6663a02c 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" " []" adds an icon to the toolbar performing # " " @@ -37,9 +37,9 @@ # Item Emphasized set-emph # # BidiItem is like Item, but an alternative icon (with name ending -# with "+rtl") will be used 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 c15f2d7738..b277843574 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 > 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) -- 2.39.2