Replace Go button with a Go icon inside the address entry

The icon is displayed by default, takes a little less space, but
replaced with the news feed icon as appropriate. If the address
entry is focussed, the Go icon takes precedence.

We also introduce the focus-in signal on MidoriLocationAction.
This commit is contained in:
Christian Dywan 2009-06-13 03:45:11 +02:00
parent 2834db080b
commit 4822eaf4c4
2 changed files with 57 additions and 39 deletions

View file

@ -321,13 +321,12 @@ _midori_browser_update_interface (MidoriBrowser* browser)
katze_throbber_set_animated (KATZE_THROBBER (browser->throbber), loading);
action = _action_by_name (browser, "Location");
if (browser->news_aggregator && *browser->news_aggregator
&& g_object_get_data (G_OBJECT (view), "news-feeds"))
if (g_object_get_data (G_OBJECT (view), "news-feeds"))
midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), STOCK_NEWS_FEED);
else
midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), NULL);
MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
}
static void
@ -435,7 +434,7 @@ midori_view_notify_load_status_cb (GtkWidget* view,
midori_location_action_set_uri (
MIDORI_LOCATION_ACTION (action), uri);
midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), NULL);
MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
g_object_notify (G_OBJECT (browser), "uri");
}
@ -2967,12 +2966,29 @@ _action_location_active_changed (GtkAction* action,
}
}
static void
_action_location_focus_in (GtkAction* action,
MidoriBrowser* browser)
{
midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
}
static void
_action_location_focus_out (GtkAction* action,
MidoriBrowser* browser)
{
GtkWidget* view = midori_browser_get_current_tab (browser);
if (!browser->show_navigationbar)
gtk_widget_hide (browser->navigationbar);
if (g_object_get_data (G_OBJECT (view), "news-feeds"))
midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), STOCK_NEWS_FEED);
else
midori_location_action_set_secondary_icon (
MIDORI_LOCATION_ACTION (action), GTK_STOCK_JUMP_TO);
}
static void
@ -3023,8 +3039,12 @@ _action_location_secondary_icon_released (GtkAction* action,
if ((view = midori_browser_get_current_tab (browser)))
{
const gchar* uri = midori_view_get_display_uri (MIDORI_VIEW (view));
if (browser->news_aggregator && *browser->news_aggregator)
if (gtk_window_get_focus (GTK_WINDOW (browser)) == widget)
_action_location_submit_uri (action, uri, FALSE, browser);
else if (g_object_get_data (G_OBJECT (view), "news-feeds"))
sokoke_spawn_program (browser->news_aggregator, uri, TRUE);
else
_action_location_submit_uri (action, uri, FALSE, browser);
}
}
@ -4574,6 +4594,8 @@ midori_browser_init (MidoriBrowser* browser)
_action_location_activate, browser,
"signal::active-changed",
_action_location_active_changed, browser,
"signal::focus-in",
_action_location_focus_in, browser,
"signal::focus-out",
_action_location_focus_out, browser,
"signal::reset-uri",

View file

@ -59,6 +59,7 @@ enum
enum
{
ACTIVE_CHANGED,
FOCUS_IN,
FOCUS_OUT,
SECONDARY_ICON_RELEASED,
RESET_URI,
@ -127,6 +128,22 @@ midori_location_action_class_init (MidoriLocationActionClass* class)
G_TYPE_NONE, 1,
G_TYPE_INT);
/**
* MidoriLocationAction:focus-in:
*
* The focus-in signal is emitted when the entry obtains the focus.
*
* Since 0.1.8
*/
signals[FOCUS_IN] = g_signal_new ("focus-in",
G_TYPE_FROM_CLASS (class),
(GSignalFlags) (G_SIGNAL_RUN_LAST),
0,
0,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[FOCUS_OUT] = g_signal_new ("focus-out",
G_TYPE_FROM_CLASS (class),
(GSignalFlags) (G_SIGNAL_RUN_LAST),
@ -219,10 +236,7 @@ midori_location_action_class_init (MidoriLocationActionClass* class)
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);
GtkWidget* entry = gtk_bin_get_child (GTK_BIN (alignment));
return entry;
}
@ -514,29 +528,12 @@ midori_location_action_activate (GtkAction* 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*
midori_location_action_create_tool_item (GtkAction* action)
{
GtkWidget* toolitem;
GtkWidget* alignment;
GtkWidget* hbox;
GtkWidget* location_entry;
GtkWidget* go_button;
GtkWidget* go_icon;
toolitem = GTK_WIDGET (gtk_tool_item_new ());
gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
@ -544,21 +541,9 @@ midori_location_action_create_tool_item (GtkAction* action)
alignment = gtk_alignment_new (0.0f, 0.5f, 1.0f, 0.1f);
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);
gtk_container_add (GTK_CONTAINER (alignment), location_entry);
return toolitem;
}
@ -592,6 +577,15 @@ midori_location_action_key_press_event_cb (GtkWidget* widget,
return FALSE;
}
static gboolean
midori_location_action_focus_in_event_cb (GtkWidget* widget,
GdkEventKey* event,
GtkAction* action)
{
g_signal_emit (action, signals[FOCUS_IN], 0);
return FALSE;
}
static gboolean
midori_location_action_focus_out_event_cb (GtkWidget* widget,
GdkEventKey* event,
@ -1054,6 +1048,8 @@ midori_location_action_connect_proxy (GtkAction* action,
g_object_connect (gtk_bin_get_child (GTK_BIN (entry)),
"signal::key-press-event",
midori_location_action_key_press_event_cb, action,
"signal::focus-in-event",
midori_location_action_focus_in_event_cb, action,
"signal::focus-out-event",
midori_location_action_focus_out_event_cb, action,
"signal::icon-release",