[Xfce4-commits] <midori:master> Split location and search entry

Christian Dywan noreply at xfce.org
Tue Nov 15 23:46:02 CET 2011


Updating branch refs/heads/master
         to ccd0562d7d730fd78834e41c0c559ad2c32edd2c (commit)
       from 524a4bb0a7d658c32309b044b5fdd98205eb0769 (commit)

commit ccd0562d7d730fd78834e41c0c559ad2c32edd2c
Author: Peter Hatina <phatina at redhat.com>
Date:   Tue Nov 15 23:43:14 2011 +0100

    Split location and search entry
    
    Fixes: https://bugs.launchpad.net/midori/+bug/738422

 midori/midori-browser.c     |   92 +++++++++++++++++++++++++++++++++++++++++-
 midori/midori-websettings.c |   25 ++++++++++++
 2 files changed, 114 insertions(+), 3 deletions(-)

diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index ff10302..4aa01d7 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -19,6 +19,7 @@
 #include "midori-panel.h"
 #include "midori-locationaction.h"
 #include "midori-searchaction.h"
+#include "midori-panedaction.h"
 #include "midori-findbar.h"
 #include "midori-transferbar.h"
 #include "midori-platform.h"
@@ -2717,6 +2718,20 @@ _midori_browser_save_toolbar_items (MidoriBrowser* browser)
     g_free (items);
 }
 
+static void
+_midori_browser_save_search_item (MidoriBrowser* browser)
+{
+    MidoriPanedAction* paned_action = MIDORI_PANED_ACTION (_action_by_name (browser, "LocationSearch"));
+    GtkWidget* search = midori_paned_action_get_child_by_name (paned_action, "Search");
+    GtkAllocation allocation;
+    MidoriWebSettings* settings = browser->settings;
+    if (!search)
+        return;
+
+    gtk_widget_get_allocation (search, &allocation);
+    g_object_set (settings, "search-width", allocation.width, NULL);
+}
+
 /**
  * midori_browser_get_toolbar_actions:
  *
@@ -5523,6 +5538,8 @@ midori_browser_destroy_cb (MidoriBrowser* browser)
     if (G_UNLIKELY (browser->alloc_timeout))
         g_source_remove (browser->alloc_timeout);
 
+    _midori_browser_save_search_item (browser);
+
     /* Destroy panel first, so panels don't need special care */
     gtk_widget_destroy (browser->panel);
     /* Destroy tabs second, so child widgets don't need special care */
@@ -5953,6 +5970,12 @@ midori_browser_init (MidoriBrowser* browser)
         action, "<Ctrl>K");
     g_object_unref (action);
 
+    action = g_object_new (MIDORI_TYPE_PANED_ACTION,
+        "name", "LocationSearch",
+        NULL);
+    gtk_action_group_add_action (browser->action_group, action);
+    g_object_unref (action);
+
     action = g_object_new (KATZE_TYPE_ARRAY_ACTION,
         "name", "Trash",
         "stock-id", STOCK_USER_TRASH,
@@ -6377,18 +6400,73 @@ _midori_browser_set_toolbar_items (MidoriBrowser* browser,
     gchar** name;
     GtkAction* action;
     GtkWidget* toolitem;
+    const char* token_location = g_intern_static_string ("Location");
+    const char* token_search = g_intern_static_string ("Search");
+    const char* token_dontcare = g_intern_static_string ("Dontcare");
+    const char* token_current = token_dontcare;
+    const char* token_last = token_dontcare;
 
     gtk_container_foreach (GTK_CONTAINER (browser->navigationbar),
         (GtkCallback)gtk_widget_destroy, NULL);
 
     names = g_strsplit (items ? items : "", ",", 0);
     name = names;
-    while (*name)
+    for (; *name; ++name)
     {
         action = _action_by_name (browser, *name);
         if (action)
         {
-            toolitem = gtk_action_create_tool_item (action);
+            token_last = token_current;
+
+            /* Decide, what kind of token (item) we got now */
+            if (name && !g_strcmp0 (*name, "Location"))
+                token_current = token_location;
+            else if (name && !g_strcmp0 (*name, "Search"))
+                token_current = token_search;
+            else
+                token_current = token_dontcare;
+
+            if ((token_current == token_location || token_current == token_search) &&
+                 (token_last == token_location || token_last == token_search))
+            {
+                GtkWidget* toolitem_first = gtk_action_create_tool_item (
+                    _action_by_name (browser, token_last));
+                GtkWidget* toolitem_second = gtk_action_create_tool_item (
+                    _action_by_name (browser, token_current));
+                MidoriPanedAction* paned_action = MIDORI_PANED_ACTION (
+                    _action_by_name (browser, "LocationSearch"));
+                MidoriWebSettings* midori_settings = browser->settings;
+                midori_paned_action_set_child1 (paned_action, toolitem_first, token_last,
+                    token_last == token_search ? FALSE : TRUE, TRUE);
+                midori_paned_action_set_child2 (paned_action, toolitem_second, token_current,
+                    token_current == token_search ? FALSE : TRUE, TRUE);
+
+                gtk_widget_set_size_request (
+                    token_last == token_search ? toolitem_first : toolitem_second,
+                    katze_object_get_int ((gpointer) midori_settings,
+                    "search-width"),
+                    -1);
+
+                toolitem = gtk_action_create_tool_item (GTK_ACTION (paned_action));
+                token_current = token_dontcare;
+                token_last = token_dontcare;
+            }
+            else if (token_current == token_dontcare && token_last != token_dontcare)
+            {
+                /* There was a location or search item, but was not followed by
+                   the other one, that form a couple */
+                gtk_toolbar_insert (GTK_TOOLBAR (browser->navigationbar),
+                    GTK_TOOL_ITEM (gtk_action_create_tool_item (
+                    _action_by_name (browser, token_last))),
+                    -1);
+
+                toolitem = gtk_action_create_tool_item (action);
+            }
+            else if (token_current != token_dontcare && token_last == token_dontcare)
+                continue;
+            else
+                toolitem = gtk_action_create_tool_item (action);
+
             if (gtk_bin_get_child (GTK_BIN (toolitem)))
                 g_signal_connect (gtk_bin_get_child (GTK_BIN (toolitem)),
                     "button-press-event",
@@ -6405,9 +6483,17 @@ _midori_browser_set_toolbar_items (MidoriBrowser* browser,
             gtk_toolbar_insert (GTK_TOOLBAR (browser->navigationbar),
                                 GTK_TOOL_ITEM (toolitem), -1);
         }
-        name++;
     }
     g_strfreev (names);
+
+    /* There was a last item, which could have formed a couple, but
+       there is no item left, we add that last item to toolbar as is */
+    if (token_current != token_dontcare)
+    {
+        gtk_toolbar_insert (GTK_TOOLBAR (browser->navigationbar),
+            GTK_TOOL_ITEM (gtk_action_create_tool_item (
+            _action_by_name (browser, token_current))), -1);
+    }
 }
 
 static void
diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c
index 285652d..837c3ce 100644
--- a/midori/midori-websettings.c
+++ b/midori/midori-websettings.c
@@ -67,6 +67,7 @@ struct _MidoriWebSettings
     gint last_web_search;
     gint maximum_cookie_age;
     gint maximum_history_age;
+    gint search_width;
 
     gchar* toolbar_items;
     gchar* homepage;
@@ -176,6 +177,8 @@ enum
     PROP_STRIP_REFERER,
     PROP_ENFORCE_FONT_FAMILY,
     PROP_USER_STYLESHEET_URI,
+
+    PROP_SEARCH_WIDTH,
 };
 
 GType
@@ -1077,6 +1080,22 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class)
                                      "Load stylesheets from a local URI",
                                      NULL,
                                      flags));
+
+    /**
+     * MidoriWebSettings:search-entry-width:
+     *
+     * Search action width in pixels
+     *
+     * Since: 0.4.3
+     **/
+    g_object_class_install_property (gobject_class,
+                                     PROP_SEARCH_WIDTH,
+                                     g_param_spec_int (
+                                     "search-width",
+                                     "Search action width",
+                                     "Search action width in pixels",
+                                     10, G_MAXINT, 200,
+                                     flags));
 }
 
 static void
@@ -1565,6 +1584,9 @@ midori_web_settings_set_property (GObject*      object,
             midori_web_settings_process_stylesheets (web_settings, new_len - old_len);
         }
         break;
+    case PROP_SEARCH_WIDTH:
+        web_settings->search_width = g_value_get_int (value);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;
@@ -1830,6 +1852,9 @@ midori_web_settings_get_property (GObject*    object,
         g_value_take_string (value, katze_object_get_string (web_settings,
             "WebKitWebSettings::user-stylesheet-uri"));
         break;
+    case PROP_SEARCH_WIDTH:
+        g_value_set_int (value, web_settings->search_width);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
         break;


More information about the Xfce4-commits mailing list