mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
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.
This commit is contained in:
parent
21eb2c4f74
commit
95da270711
@ -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.
|
||||
|
6
lib/images/icon.aliases
Normal file
6
lib/images/icon.aliases
Normal file
@ -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
|
@ -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:
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user