/pidgin/main: 3f84738fbc15: Finch: better UI for menus
Tomasz Wasilczyk
twasilczyk at pidgin.im
Sat Apr 26 14:39:44 EDT 2014
Changeset: 3f84738fbc1528255bd57075c9f1f2dfa193ffeb
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-26 20:39 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/3f84738fbc15
Description:
Finch: better UI for menus
diffstat:
finch/gntconv.c | 3 +++
finch/gntmenuutil.c | 13 +++++++++++--
finch/libgnt/gntmenu.c | 37 +++++++++++++++++++++++++++----------
libpurple/e2ee.h | 4 ++--
4 files changed, 43 insertions(+), 14 deletions(-)
diffs (138 lines):
diff --git a/finch/gntconv.c b/finch/gntconv.c
--- a/finch/gntconv.c
+++ b/finch/gntconv.c
@@ -400,6 +400,7 @@ gg_extended_menu(FinchConv *ggc)
{
GntMenu *sub;
GList *list;
+ gboolean is_empty = TRUE;
g_return_if_fail(ggc != NULL);
@@ -410,7 +411,9 @@ gg_extended_menu(FinchConv *ggc)
list; list = g_list_delete_link(list, list))
{
finch_append_menu_action(sub, list->data, ggc->active_conv);
+ is_empty = FALSE;
}
+ gnt_menuitem_set_visible(ggc->plugins, !is_empty);
}
static void
diff --git a/finch/gntmenuutil.c b/finch/gntmenuutil.c
--- a/finch/gntmenuutil.c
+++ b/finch/gntmenuutil.c
@@ -47,11 +47,21 @@ finch_append_menu_action(GntMenu *menu,
{
GList *list;
GntMenuItem *item;
+ const gchar *label;
+ gchar *clean_label = NULL;
if (action == NULL)
return;
+ label = purple_menu_action_get_label(action);
- item = gnt_menuitem_new(purple_menu_action_get_label(action));
+ if (strchr(label, '_') != NULL) {
+ clean_label = g_strdup(label);
+ purple_str_strip_char(clean_label, '_');
+ label = clean_label;
+ }
+ item = gnt_menuitem_new(label);
+ g_free(clean_label);
+
if (purple_menu_action_get_callback(action)) {
gnt_menuitem_set_callback(item, context_menu_callback, action);
g_object_set_data(G_OBJECT(item), "menuctx", ctx);
@@ -71,4 +81,3 @@ finch_append_menu_action(GntMenu *menu,
g_signal_connect_swapped(G_OBJECT(menu), "destroy",
G_CALLBACK(purple_menu_action_free), action);
}
-
diff --git a/finch/libgnt/gntmenu.c b/finch/libgnt/gntmenu.c
--- a/finch/libgnt/gntmenu.c
+++ b/finch/libgnt/gntmenu.c
@@ -89,7 +89,11 @@ gnt_menu_draw(GntWidget *widget)
GntMenuItem *item = GNT_MENU_ITEM(iter->data);
if (!gnt_menuitem_is_visible(item))
continue;
- type = ' ' | gnt_color_pair(GNT_COLOR_HIGHLIGHT);
+ type = ' ';
+ if (item->callback || item->submenu)
+ type |= gnt_color_pair(GNT_COLOR_HIGHLIGHT);
+ else
+ type |= gnt_color_pair(GNT_COLOR_DISABLED);
if (i == menu->selected)
type |= A_REVERSE;
item->priv.x = getcurx(widget->window) + widget->priv.x;
@@ -121,7 +125,7 @@ gnt_menu_size_request(GntWidget *widget)
static void
menu_tree_add(GntMenu *menu, GntMenuItem *item, GntMenuItem *parent)
{
- char trigger[4] = "\0 )\0";
+ char trigger[] = "\0 )\0";
g_return_if_fail(item != NULL);
@@ -132,9 +136,12 @@ menu_tree_add(GntMenu *menu, GntMenuItem
gnt_tree_add_choice(GNT_TREE(menu), item,
gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, " "), parent, NULL);
gnt_tree_set_choice(GNT_TREE(menu), item, gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item)));
- } else
+ } else {
gnt_tree_add_row_last(GNT_TREE(menu), item,
gnt_tree_create_row(GNT_TREE(menu), item->text, trigger, item->submenu ? ">" : " "), parent);
+ if (!item->callback && !item->submenu)
+ gnt_tree_set_row_color(GNT_TREE(menu), item, GNT_COLOR_DISABLED);
+ }
if (0 && item->submenu) {
GntMenu *sub = GNT_MENU(item->submenu);
@@ -307,15 +314,25 @@ gnt_menu_key_pressed(GntWidget *widget,
}
if (menu->type == GNT_MENU_TOPLEVEL) {
+ GntMenuItem *item;
+ GList *it;
if (strcmp(text, GNT_KEY_LEFT) == 0) {
- if (menu->selected == 0)
- menu->selected = g_list_length(menu->list) - 1;
- else
- menu->selected--;
+ do {
+ if (menu->selected == 0)
+ menu->selected = g_list_length(menu->list) - 1;
+ else
+ menu->selected--;
+ it = g_list_nth(menu->list, menu->selected);
+ item = it ? it->data : NULL;
+ } while (!gnt_menuitem_is_visible(item));
} else if (strcmp(text, GNT_KEY_RIGHT) == 0) {
- menu->selected++;
- if (menu->selected >= g_list_length(menu->list))
- menu->selected = 0;
+ do {
+ menu->selected++;
+ if (menu->selected >= g_list_length(menu->list))
+ menu->selected = 0;
+ it = g_list_nth(menu->list, menu->selected);
+ item = it ? it->data : NULL;
+ } while (!gnt_menuitem_is_visible(item));
} else if (strcmp(text, GNT_KEY_ENTER) == 0 ||
strcmp(text, GNT_KEY_DOWN) == 0) {
gnt_widget_activate(widget);
diff --git a/libpurple/e2ee.h b/libpurple/e2ee.h
--- a/libpurple/e2ee.h
+++ b/libpurple/e2ee.h
@@ -247,8 +247,8 @@ purple_e2ee_provider_get_conv_menu_cb(Pu
*
* Returns the list of actions for an E2EE menu.
*
- * Returns: (transfer container): the #GList of #PurpleMenuAction's. Should be
- * #g_list_free'd when done using it.
+ * Returns: (transfer full): the #GList of #PurpleMenuAction's. Should be
+ * #g_list_free or #g_list_free_full'd when done using it.
*/
GList *
purple_e2ee_provider_get_conv_menu_actions(PurpleE2eeProvider *provider,
More information about the Commits
mailing list