Commit f77c10b0 authored by Matthias Clasen's avatar Matthias Clasen Committed by Tristan Van Berkom

Add accessible alternatives to entry icon functionality

Inspired by the complaint in bug 611051.
parent e566c961
......@@ -77,43 +77,11 @@ stop_search (GtkButton *button,
}
static void
icon_press_cb (GtkEntry *entry,
gint position,
GdkEventButton *event,
gpointer data)
clear_entry (GtkEntry *entry)
{
if (position == GTK_ENTRY_ICON_PRIMARY)
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button, event->time);
else
gtk_entry_set_text (entry, "");
}
static void
text_changed_cb (GtkEntry *entry,
GParamSpec *pspec,
GtkWidget *button)
{
gboolean has_text;
has_text = gtk_entry_get_text_length (entry) > 0;
gtk_entry_set_icon_sensitive (entry,
GTK_ENTRY_ICON_SECONDARY,
has_text);
gtk_widget_set_sensitive (button, has_text);
}
static void
activate_cb (GtkEntry *entry,
GtkButton *button)
{
if (search_progress_id != 0)
return;
start_search (button, entry);
}
static void
search_by_name (GtkWidget *item,
GtkEntry *entry)
......@@ -153,6 +121,82 @@ search_by_file (GtkWidget *item,
"Click here to change the search type");
}
GtkWidget *
create_search_menu (GtkWidget *entry)
{
GtkWidget *menu;
GtkWidget *item;
GtkWidget *image;
menu = gtk_menu_new ();
item = gtk_image_menu_item_new_with_mnemonic ("Search by _name");
image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
g_signal_connect (item, "activate",
G_CALLBACK (search_by_name), entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_with_mnemonic ("Search by _description");
image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
g_signal_connect (item, "activate",
G_CALLBACK (search_by_description), entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_with_mnemonic ("Search by _file name");
image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
g_signal_connect (item, "activate",
G_CALLBACK (search_by_file), entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show_all (menu);
return menu;
}
static void
icon_press_cb (GtkEntry *entry,
gint position,
GdkEventButton *event,
gpointer data)
{
if (position == GTK_ENTRY_ICON_PRIMARY)
gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
event->button, event->time);
else
clear_entry (entry);
}
static void
text_changed_cb (GtkEntry *entry,
GParamSpec *pspec,
GtkWidget *button)
{
gboolean has_text;
has_text = gtk_entry_get_text_length (entry) > 0;
gtk_entry_set_icon_sensitive (entry,
GTK_ENTRY_ICON_SECONDARY,
has_text);
gtk_widget_set_sensitive (button, has_text);
}
static void
activate_cb (GtkEntry *entry,
GtkButton *button)
{
if (search_progress_id != 0)
return;
start_search (button, entry);
}
static void
search_entry_destroyed (GtkWidget *widget)
{
......@@ -165,6 +209,34 @@ search_entry_destroyed (GtkWidget *widget)
window = NULL;
}
static void
entry_populate_popup (GtkEntry *entry,
GtkMenu *menu,
gpointer user_data)
{
GtkWidget *item;
GtkWidget *search_menu;
gboolean has_text;
has_text = gtk_entry_get_text_length (entry) > 0;
item = gtk_separator_menu_item_new ();
gtk_widget_show (item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_menu_item_new_with_mnemonic ("C_lear");
gtk_widget_show (item);
g_signal_connect_swapped (item, "activate",
G_CALLBACK (clear_entry), entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_set_sensitive (item, has_text);
search_menu = create_search_menu (GTK_WIDGET (entry));
item = gtk_menu_item_new_with_label ("Search by");
gtk_widget_show (item);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), search_menu);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
GtkWidget *
do_search_entry (GtkWidget *do_widget)
......@@ -173,8 +245,6 @@ do_search_entry (GtkWidget *do_widget)
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *item;
GtkWidget *image;
GtkWidget *find_button;
GtkWidget *cancel_button;
......@@ -244,30 +314,14 @@ do_search_entry (GtkWidget *do_widget)
G_CALLBACK (activate_cb), NULL);
/* Create the menu */
menu = gtk_menu_new ();
menu = create_search_menu (entry);
gtk_menu_attach_to_widget (GTK_MENU (menu), entry, NULL);
item = gtk_image_menu_item_new_with_label ("Search by name");
image = gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
g_signal_connect (item, "activate", G_CALLBACK (search_by_name), entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_with_label ("Search by description");
image = gtk_image_new_from_stock (GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
g_signal_connect (item, "activate", G_CALLBACK (search_by_description), entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
item = gtk_image_menu_item_new_with_label ("Search by file name");
image = gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
g_signal_connect (item, "activate", G_CALLBACK (search_by_file), entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show_all (menu);
}
/* add accessible alternatives for icon functionality */
g_signal_connect (entry, "populate-popup",
G_CALLBACK (entry_populate_popup), NULL);
if (!gtk_widget_get_visible (window))
gtk_widget_show_all (window);
else
......@@ -279,5 +333,3 @@ do_search_entry (GtkWidget *do_widget)
return window;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment