Strip underscores from action labels in shortcuts extension
This commit is contained in:
parent
40564d69cb
commit
7a6686ef71
2 changed files with 54 additions and 2 deletions
1
AUTHORS
1
AUTHORS
|
@ -67,6 +67,7 @@ Translations:
|
||||||
Code from other projects:
|
Code from other projects:
|
||||||
GTK+/ GdkPixbuf, Matthias Clasen <mclasen@redhat.com>
|
GTK+/ GdkPixbuf, Matthias Clasen <mclasen@redhat.com>
|
||||||
GTK+/ GtkEntry, Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
GTK+/ GtkEntry, Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||||
|
GTK+/ GtkToolbar, Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||||
Modified by the GTK+ Team and others 1997-2000
|
Modified by the GTK+ Team and others 1997-2000
|
||||||
libSoup/ CookieJarText, Copyright (C) 2008 Xan Lopez <xan@gnome.org>, Dan Winship <danw@gnome.org>
|
libSoup/ CookieJarText, Copyright (C) 2008 Xan Lopez <xan@gnome.org>, Dan Winship <danw@gnome.org>
|
||||||
libSylph, Copyright 1999-2008 Hiroyuki Yamamoto, Copyright 2006-2009 Enrico Tröger <enrico.troeger@uvena.de>
|
libSylph, Copyright 1999-2008 Hiroyuki Yamamoto, Copyright 2006-2009 Enrico Tröger <enrico.troeger@uvena.de>
|
||||||
|
|
|
@ -32,6 +32,52 @@ shortcuts_deactivate_cb (MidoriExtension* extension,
|
||||||
app, shortcuts_app_add_browser_cb, extension);
|
app, shortcuts_app_add_browser_cb, extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A copy of _gtk_toolbar_elide_underscores
|
||||||
|
Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||||
|
Copied from GTK+ 2.17.1 */
|
||||||
|
static gchar *
|
||||||
|
elide_underscores (const gchar *original)
|
||||||
|
{
|
||||||
|
gchar *q, *result;
|
||||||
|
const gchar *p, *end;
|
||||||
|
gsize len;
|
||||||
|
gboolean last_underscore;
|
||||||
|
|
||||||
|
if (!original)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
len = strlen (original);
|
||||||
|
q = result = g_malloc (len + 1);
|
||||||
|
last_underscore = FALSE;
|
||||||
|
|
||||||
|
end = original + len;
|
||||||
|
for (p = original; p < end; p++)
|
||||||
|
{
|
||||||
|
if (!last_underscore && *p == '_')
|
||||||
|
last_underscore = TRUE;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
last_underscore = FALSE;
|
||||||
|
if (original + 2 <= p && p + 1 <= end &&
|
||||||
|
p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
|
||||||
|
{
|
||||||
|
q--;
|
||||||
|
*q = '\0';
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*q++ = *p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_underscore)
|
||||||
|
*q++ = '_';
|
||||||
|
|
||||||
|
*q = '\0';
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shortcuts_preferences_render_text (GtkTreeViewColumn* column,
|
shortcuts_preferences_render_text (GtkTreeViewColumn* column,
|
||||||
GtkCellRenderer* renderer,
|
GtkCellRenderer* renderer,
|
||||||
|
@ -41,18 +87,23 @@ shortcuts_preferences_render_text (GtkTreeViewColumn* column,
|
||||||
{
|
{
|
||||||
GtkAction* action;
|
GtkAction* action;
|
||||||
gchar* label;
|
gchar* label;
|
||||||
|
gchar* stripped;
|
||||||
|
|
||||||
gtk_tree_model_get (model, iter, 0, &action, -1);
|
gtk_tree_model_get (model, iter, 0, &action, -1);
|
||||||
if ((label = katze_object_get_string (action, "label")))
|
if ((label = katze_object_get_string (action, "label")))
|
||||||
g_object_set (renderer, "text", label, NULL);
|
stripped = elide_underscores (label);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GtkStockItem item;
|
GtkStockItem item;
|
||||||
g_object_get (action, "stock-id", &label, NULL);
|
g_object_get (action, "stock-id", &label, NULL);
|
||||||
if (gtk_stock_lookup (label, &item))
|
if (gtk_stock_lookup (label, &item))
|
||||||
g_object_set (renderer, "text", item.label, NULL);
|
stripped = elide_underscores (item.label);
|
||||||
|
else
|
||||||
|
stripped = g_strdup ("");
|
||||||
}
|
}
|
||||||
g_free (label);
|
g_free (label);
|
||||||
|
g_object_set (renderer, "text", stripped, NULL);
|
||||||
|
g_free (stripped);
|
||||||
g_object_unref (action);
|
g_object_unref (action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue