Implement a small Go button next to the location entry
This commit is contained in:
parent
696a592e82
commit
87e712f51c
1 changed files with 56 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2008 Christian Dywan <christian@twotoasts.de>
|
Copyright (C) 2008-2009 Christian Dywan <christian@twotoasts.de>
|
||||||
Copyright (C) 2008 Dale Whittaker <dayul@users.sf.net>
|
Copyright (C) 2008 Dale Whittaker <dayul@users.sf.net>
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
This library is free software; you can redistribute it and/or
|
||||||
|
@ -189,12 +189,22 @@ midori_location_action_class_init (MidoriLocationActionClass* class)
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GtkWidget*
|
||||||
|
midori_location_action_entry_for_proxy (GtkWidget* proxy)
|
||||||
|
{
|
||||||
|
GtkWidget* alignment = gtk_bin_get_child (GTK_BIN (proxy));
|
||||||
|
GtkWidget* hbox = gtk_bin_get_child (GTK_BIN (alignment));
|
||||||
|
GList* children = gtk_container_get_children (GTK_CONTAINER (hbox));
|
||||||
|
GtkWidget* entry = g_list_nth_data (children, 0);
|
||||||
|
g_list_free (children);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_location_action_set_model (MidoriLocationAction* location_action,
|
midori_location_action_set_model (MidoriLocationAction* location_action,
|
||||||
GtkTreeModel* model)
|
GtkTreeModel* model)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* location_entry;
|
GtkWidget* location_entry;
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
|
|
||||||
|
@ -203,8 +213,7 @@ midori_location_action_set_model (MidoriLocationAction* location_action,
|
||||||
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data))
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
location_entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
||||||
|
|
||||||
g_object_set (location_entry, "model", model, NULL);
|
g_object_set (location_entry, "model", model, NULL);
|
||||||
|
@ -379,7 +388,6 @@ static void
|
||||||
midori_location_action_activate (GtkAction* action)
|
midori_location_action_activate (GtkAction* action)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
|
|
||||||
proxies = gtk_action_get_proxies (action);
|
proxies = gtk_action_get_proxies (action);
|
||||||
|
@ -387,8 +395,7 @@ midori_location_action_activate (GtkAction* action)
|
||||||
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data))
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
|
|
||||||
/* Obviously only one widget can end up with the focus.
|
/* Obviously only one widget can end up with the focus.
|
||||||
Yet we can't predict which one that is, can we? */
|
Yet we can't predict which one that is, can we? */
|
||||||
|
@ -399,22 +406,51 @@ midori_location_action_activate (GtkAction* action)
|
||||||
GTK_ACTION_CLASS (midori_location_action_parent_class)->activate (action);
|
GTK_ACTION_CLASS (midori_location_action_parent_class)->activate (action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_location_action_go_clicked_cb (GtkWidget* button,
|
||||||
|
GtkAction* action)
|
||||||
|
{
|
||||||
|
GtkWidget* hbox = gtk_widget_get_parent (button);
|
||||||
|
GList* children = gtk_container_get_children (GTK_CONTAINER (hbox));
|
||||||
|
GtkWidget* location_entry = g_list_nth_data (children, 0);
|
||||||
|
g_list_free (children);
|
||||||
|
GtkWidget* entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
||||||
|
const gchar* uri = gtk_entry_get_text (GTK_ENTRY (entry));
|
||||||
|
if (uri && *uri)
|
||||||
|
g_signal_emit (action, signals[SUBMIT_URI], 0, uri, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
midori_location_action_create_tool_item (GtkAction* action)
|
midori_location_action_create_tool_item (GtkAction* action)
|
||||||
{
|
{
|
||||||
GtkWidget* toolitem;
|
GtkWidget* toolitem;
|
||||||
GtkWidget* location_entry;
|
|
||||||
GtkWidget* alignment;
|
GtkWidget* alignment;
|
||||||
|
GtkWidget* hbox;
|
||||||
|
GtkWidget* location_entry;
|
||||||
|
GtkWidget* go_button;
|
||||||
|
GtkWidget* go_icon;
|
||||||
|
|
||||||
toolitem = GTK_WIDGET (gtk_tool_item_new ());
|
toolitem = GTK_WIDGET (gtk_tool_item_new ());
|
||||||
gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
|
gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
|
||||||
location_entry = midori_location_entry_new ();
|
|
||||||
|
|
||||||
alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
|
alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
|
||||||
gtk_container_add (GTK_CONTAINER (alignment), location_entry);
|
|
||||||
gtk_widget_show (location_entry);
|
|
||||||
gtk_container_add (GTK_CONTAINER (toolitem), alignment);
|
|
||||||
gtk_widget_show (alignment);
|
gtk_widget_show (alignment);
|
||||||
|
gtk_container_add (GTK_CONTAINER (toolitem), alignment);
|
||||||
|
hbox = gtk_hbox_new (FALSE, 0);
|
||||||
|
gtk_widget_show (hbox);
|
||||||
|
gtk_container_add (GTK_CONTAINER (alignment), hbox);
|
||||||
|
location_entry = midori_location_entry_new ();
|
||||||
|
gtk_widget_show (location_entry);
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), location_entry, TRUE, TRUE, 0);
|
||||||
|
go_button = gtk_button_new ();
|
||||||
|
gtk_button_set_focus_on_click (GTK_BUTTON (go_button), FALSE);
|
||||||
|
gtk_button_set_relief (GTK_BUTTON (go_button), GTK_RELIEF_NONE);
|
||||||
|
go_icon = gtk_image_new_from_stock (GTK_STOCK_JUMP_TO, GTK_ICON_SIZE_MENU);
|
||||||
|
gtk_button_set_image (GTK_BUTTON (go_button), go_icon);
|
||||||
|
gtk_widget_show (go_button);
|
||||||
|
gtk_box_pack_start (GTK_BOX (hbox), go_button, FALSE, FALSE, 0);
|
||||||
|
g_signal_connect (go_button, "clicked",
|
||||||
|
G_CALLBACK (midori_location_action_go_clicked_cb), action);
|
||||||
|
|
||||||
return toolitem;
|
return toolitem;
|
||||||
}
|
}
|
||||||
|
@ -859,7 +895,6 @@ static void
|
||||||
midori_location_action_connect_proxy (GtkAction* action,
|
midori_location_action_connect_proxy (GtkAction* action,
|
||||||
GtkWidget* proxy)
|
GtkWidget* proxy)
|
||||||
{
|
{
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
MidoriLocationAction* location_action;
|
MidoriLocationAction* location_action;
|
||||||
GtkCellRenderer* renderer;
|
GtkCellRenderer* renderer;
|
||||||
|
@ -874,8 +909,7 @@ midori_location_action_connect_proxy (GtkAction* action,
|
||||||
|
|
||||||
if (GTK_IS_TOOL_ITEM (proxy))
|
if (GTK_IS_TOOL_ITEM (proxy))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxy));
|
entry = midori_location_action_entry_for_proxy (proxy);
|
||||||
entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
|
|
||||||
midori_location_entry_set_progress (MIDORI_LOCATION_ENTRY (entry),
|
midori_location_entry_set_progress (MIDORI_LOCATION_ENTRY (entry),
|
||||||
MIDORI_LOCATION_ACTION (action)->progress);
|
MIDORI_LOCATION_ACTION (action)->progress);
|
||||||
|
@ -943,7 +977,6 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
|
||||||
const gchar* text)
|
const gchar* text)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* location_entry;
|
GtkWidget* location_entry;
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
@ -961,8 +994,7 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
|
||||||
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data))
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
location_entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
||||||
|
|
||||||
gtk_entry_set_text (GTK_ENTRY (entry), text);
|
gtk_entry_set_text (GTK_ENTRY (entry), text);
|
||||||
|
@ -991,7 +1023,6 @@ midori_location_action_set_icon (MidoriLocationAction* location_action,
|
||||||
GdkPixbuf* icon)
|
GdkPixbuf* icon)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* location_entry;
|
GtkWidget* location_entry;
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
|
|
||||||
|
@ -1003,8 +1034,7 @@ midori_location_action_set_icon (MidoriLocationAction* location_action,
|
||||||
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data))
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
location_entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
||||||
|
|
||||||
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
||||||
|
@ -1122,7 +1152,6 @@ midori_location_action_add_item (MidoriLocationAction* location_action,
|
||||||
const gchar* title)
|
const gchar* title)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* location_entry;
|
GtkWidget* location_entry;
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
MidoriLocationEntryItem item;
|
MidoriLocationEntryItem item;
|
||||||
|
@ -1148,8 +1177,7 @@ midori_location_action_add_item (MidoriLocationAction* location_action,
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data) &&
|
if (GTK_IS_TOOL_ITEM (proxies->data) &&
|
||||||
!strcmp (location_action->uri, uri))
|
!strcmp (location_action->uri, uri))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
location_entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
||||||
|
|
||||||
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
||||||
|
@ -1163,7 +1191,6 @@ midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action,
|
||||||
const gchar* uri)
|
const gchar* uri)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* location_entry;
|
GtkWidget* location_entry;
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
MidoriLocationEntryItem item;
|
MidoriLocationEntryItem item;
|
||||||
|
@ -1183,8 +1210,7 @@ midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action,
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data) &&
|
if (GTK_IS_TOOL_ITEM (proxies->data) &&
|
||||||
!g_strcmp0 (location_action->uri, uri))
|
!g_strcmp0 (location_action->uri, uri))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
location_entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
location_entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
||||||
|
|
||||||
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
||||||
|
@ -1224,7 +1250,6 @@ midori_location_action_set_search_engines (MidoriLocationAction* location_action
|
||||||
KatzeArray* search_engines)
|
KatzeArray* search_engines)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
GtkWidget* child;
|
GtkWidget* child;
|
||||||
GtkEntryCompletion* completion;
|
GtkEntryCompletion* completion;
|
||||||
|
@ -1242,8 +1267,7 @@ midori_location_action_set_search_engines (MidoriLocationAction* location_action
|
||||||
KatzeItem* item;
|
KatzeItem* item;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
child = gtk_bin_get_child (GTK_BIN (entry));
|
child = gtk_bin_get_child (GTK_BIN (entry));
|
||||||
|
|
||||||
completion = gtk_entry_get_completion (GTK_ENTRY (child));
|
completion = gtk_entry_get_completion (GTK_ENTRY (child));
|
||||||
|
@ -1271,7 +1295,6 @@ midori_location_action_set_progress (MidoriLocationAction* location_action,
|
||||||
gdouble progress)
|
gdouble progress)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
|
|
||||||
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action));
|
||||||
|
@ -1283,8 +1306,7 @@ midori_location_action_set_progress (MidoriLocationAction* location_action,
|
||||||
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data))
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
|
|
||||||
midori_location_entry_set_progress (MIDORI_LOCATION_ENTRY (entry),
|
midori_location_entry_set_progress (MIDORI_LOCATION_ENTRY (entry),
|
||||||
location_action->progress);
|
location_action->progress);
|
||||||
|
@ -1296,7 +1318,6 @@ midori_location_action_set_secondary_icon (MidoriLocationAction* location_action
|
||||||
const gchar* stock_id)
|
const gchar* stock_id)
|
||||||
{
|
{
|
||||||
GSList* proxies;
|
GSList* proxies;
|
||||||
GtkWidget* alignment;
|
|
||||||
GtkWidget* entry;
|
GtkWidget* entry;
|
||||||
GtkWidget* child;
|
GtkWidget* child;
|
||||||
GtkStockItem stock_item;
|
GtkStockItem stock_item;
|
||||||
|
@ -1311,8 +1332,7 @@ midori_location_action_set_secondary_icon (MidoriLocationAction* location_action
|
||||||
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
for (; proxies != NULL; proxies = g_slist_next (proxies))
|
||||||
if (GTK_IS_TOOL_ITEM (proxies->data))
|
if (GTK_IS_TOOL_ITEM (proxies->data))
|
||||||
{
|
{
|
||||||
alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
|
entry = midori_location_action_entry_for_proxy (proxies->data);
|
||||||
entry = gtk_bin_get_child (GTK_BIN (alignment));
|
|
||||||
child = gtk_bin_get_child (GTK_BIN (entry));
|
child = gtk_bin_get_child (GTK_BIN (entry));
|
||||||
|
|
||||||
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (child),
|
gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (child),
|
||||||
|
|
Loading…
Reference in a new issue