]> spindle.queued.net Git - midori/commitdiff
Implement a small Go button next to the location entry
authorChristian Dywan <christian@twotoasts.de>
Sun, 17 May 2009 14:26:31 +0000 (16:26 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 17 May 2009 14:26:31 +0000 (16:26 +0200)
midori/midori-locationaction.c

index 5d3ee8abbe27f2c711885d6a63cdee42d49cad50..37fc30d32c1e8cf11a47f72058a0560437f4b710 100644 (file)
@@ -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>
 
  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));
 }
 
+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
 midori_location_action_set_model (MidoriLocationAction* location_action,
                                   GtkTreeModel*         model)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* location_entry;
     GtkWidget* entry;
 
@@ -203,8 +213,7 @@ midori_location_action_set_model (MidoriLocationAction* location_action,
     for (; proxies != NULL; proxies = g_slist_next (proxies))
     if (GTK_IS_TOOL_ITEM (proxies->data))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        location_entry = gtk_bin_get_child (GTK_BIN (alignment));
+        location_entry = midori_location_action_entry_for_proxy (proxies->data);
         entry = gtk_bin_get_child (GTK_BIN (location_entry));
 
         g_object_set (location_entry, "model", model, NULL);
@@ -379,7 +388,6 @@ static void
 midori_location_action_activate (GtkAction* action)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* entry;
 
     proxies = gtk_action_get_proxies (action);
@@ -387,8 +395,7 @@ midori_location_action_activate (GtkAction* action)
     for (; proxies != NULL; proxies = g_slist_next (proxies))
     if (GTK_IS_TOOL_ITEM (proxies->data))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        entry = gtk_bin_get_child (GTK_BIN (alignment));
+        entry = midori_location_action_entry_for_proxy (proxies->data);
 
         /* Obviously only one widget can end up with the focus.
         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);
 }
 
+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* location_entry;
     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);
-    location_entry = midori_location_entry_new ();
 
     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_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;
 }
@@ -859,7 +895,6 @@ static void
 midori_location_action_connect_proxy (GtkAction* action,
                                       GtkWidget* proxy)
 {
-    GtkWidget* alignment;
     GtkWidget* entry;
     MidoriLocationAction* location_action;
     GtkCellRenderer* renderer;
@@ -874,8 +909,7 @@ midori_location_action_connect_proxy (GtkAction* action,
 
     if (GTK_IS_TOOL_ITEM (proxy))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxy));
-        entry = gtk_bin_get_child (GTK_BIN (alignment));
+        entry = midori_location_action_entry_for_proxy (proxy);
 
         midori_location_entry_set_progress (MIDORI_LOCATION_ENTRY (entry),
             MIDORI_LOCATION_ACTION (action)->progress);
@@ -943,7 +977,6 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
                                  const gchar*          text)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* location_entry;
     GtkWidget* entry;
     GtkTreeIter iter;
@@ -961,8 +994,7 @@ midori_location_action_set_text (MidoriLocationAction* location_action,
     for (; proxies != NULL; proxies = g_slist_next (proxies))
     if (GTK_IS_TOOL_ITEM (proxies->data))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        location_entry = gtk_bin_get_child (GTK_BIN (alignment));
+        location_entry = midori_location_action_entry_for_proxy (proxies->data);
         entry = gtk_bin_get_child (GTK_BIN (location_entry));
 
         gtk_entry_set_text (GTK_ENTRY (entry), text);
@@ -991,7 +1023,6 @@ midori_location_action_set_icon (MidoriLocationAction* location_action,
                                  GdkPixbuf*            icon)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* location_entry;
     GtkWidget* entry;
 
@@ -1003,8 +1034,7 @@ midori_location_action_set_icon (MidoriLocationAction* location_action,
     for (; proxies != NULL; proxies = g_slist_next (proxies))
     if (GTK_IS_TOOL_ITEM (proxies->data))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        location_entry = gtk_bin_get_child (GTK_BIN (alignment));
+        location_entry = midori_location_action_entry_for_proxy (proxies->data);
         entry = gtk_bin_get_child (GTK_BIN (location_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)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* location_entry;
     GtkWidget* entry;
     MidoriLocationEntryItem item;
@@ -1148,8 +1177,7 @@ midori_location_action_add_item (MidoriLocationAction* location_action,
     if (GTK_IS_TOOL_ITEM (proxies->data) &&
         !strcmp (location_action->uri, uri))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        location_entry = gtk_bin_get_child (GTK_BIN (alignment));
+        location_entry = midori_location_action_entry_for_proxy (proxies->data);
         entry = gtk_bin_get_child (GTK_BIN (location_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)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* location_entry;
     GtkWidget* entry;
     MidoriLocationEntryItem item;
@@ -1183,8 +1210,7 @@ midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action,
     if (GTK_IS_TOOL_ITEM (proxies->data) &&
         !g_strcmp0 (location_action->uri, uri))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        location_entry = gtk_bin_get_child (GTK_BIN (alignment));
+        location_entry = midori_location_action_entry_for_proxy (proxies->data);
         entry = gtk_bin_get_child (GTK_BIN (location_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)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* entry;
     GtkWidget* child;
     GtkEntryCompletion* completion;
@@ -1242,8 +1267,7 @@ midori_location_action_set_search_engines (MidoriLocationAction* location_action
         KatzeItem* item;
         guint i;
 
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        entry = gtk_bin_get_child (GTK_BIN (alignment));
+        entry = midori_location_action_entry_for_proxy (proxies->data);
         child = gtk_bin_get_child (GTK_BIN (entry));
 
         completion = gtk_entry_get_completion (GTK_ENTRY (child));
@@ -1271,7 +1295,6 @@ midori_location_action_set_progress (MidoriLocationAction* location_action,
                                      gdouble               progress)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* entry;
 
     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))
     if (GTK_IS_TOOL_ITEM (proxies->data))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        entry = gtk_bin_get_child (GTK_BIN (alignment));
+        entry = midori_location_action_entry_for_proxy (proxies->data);
 
         midori_location_entry_set_progress (MIDORI_LOCATION_ENTRY (entry),
                                             location_action->progress);
@@ -1296,7 +1318,6 @@ midori_location_action_set_secondary_icon (MidoriLocationAction* location_action
                                            const gchar*          stock_id)
 {
     GSList* proxies;
-    GtkWidget* alignment;
     GtkWidget* entry;
     GtkWidget* child;
     GtkStockItem stock_item;
@@ -1311,8 +1332,7 @@ midori_location_action_set_secondary_icon (MidoriLocationAction* location_action
     for (; proxies != NULL; proxies = g_slist_next (proxies))
     if (GTK_IS_TOOL_ITEM (proxies->data))
     {
-        alignment = gtk_bin_get_child (GTK_BIN (proxies->data));
-        entry = gtk_bin_get_child (GTK_BIN (alignment));
+        entry = midori_location_action_entry_for_proxy (proxies->data);
         child = gtk_bin_get_child (GTK_BIN (entry));
 
         gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (child),