From d809cd6040c370fef61ac731fbaba782d2d6e271 Mon Sep 17 00:00:00 2001 From: Peter Hatina Date: Wed, 16 Nov 2011 23:54:27 +0100 Subject: [PATCH] Save paned actions as separate toolbar items --- midori/main.c | 1 + midori/midori-browser.c | 43 +++++++++++++++++++++---------------- midori/midori-panedaction.c | 28 ++++++++++++++++++++++++ midori/midori-panedaction.h | 6 ++++++ 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/midori/main.c b/midori/main.c index ccfe3532..69a32106 100644 --- a/midori/main.c +++ b/midori/main.c @@ -617,6 +617,7 @@ settings_notify_cb (MidoriWebSettings* settings, /* Skip state related properties to avoid disk IO */ if ((pspec && g_str_has_prefix (pspec->name, "last-window-")) || (pspec && g_str_has_prefix (pspec->name, "user-stylesheet-uri")) + || (pspec && g_str_equal (pspec->name, "search-width")) || (pspec && g_str_has_prefix (pspec->name, "last-panel-"))) return; diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 4aa01d7d..4604c975 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -2709,8 +2709,19 @@ _midori_browser_save_toolbar_items (MidoriBrowser* browser) g_warn_if_fail (action != NULL); if (action) { - g_string_append (toolbar_items, gtk_action_get_name (action)); - g_string_append (toolbar_items, ","); + const char* action_name = gtk_action_get_name (action); + if (g_str_equal (action_name, "LocationSearch")) + { + MidoriPanedAction* paned_action = MIDORI_PANED_ACTION (action); + g_string_append_printf (toolbar_items, "%s,%s,", + midori_paned_action_get_child1_name (paned_action), + midori_paned_action_get_child2_name (paned_action)); + } + else + { + g_string_append (toolbar_items, action_name); + g_string_append (toolbar_items, ","); + } } } items = g_string_free (toolbar_items, FALSE); @@ -2718,20 +2729,6 @@ _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: * @@ -5538,8 +5535,6 @@ 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 */ @@ -6392,6 +6387,16 @@ midori_browser_toolbar_item_button_press_event_cb (GtkWidget* toolitem, return FALSE; } +static void +_midori_browser_search_item_allocate_cb (GtkWidget* widget, + GdkRectangle* allocation, + gpointer user_data) +{ + MidoriBrowser* browser = MIDORI_BROWSER (user_data); + MidoriWebSettings* settings = browser->settings; + g_object_set (settings, "search-width", allocation->width, NULL); +} + static void _midori_browser_set_toolbar_items (MidoriBrowser* browser, const gchar* items) @@ -6440,6 +6445,8 @@ _midori_browser_set_toolbar_items (MidoriBrowser* browser, 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); + g_signal_connect (G_OBJECT (token_current == token_search ? toolitem_second : toolitem_first), + "size-allocate", G_CALLBACK (_midori_browser_search_item_allocate_cb), (gpointer) browser); gtk_widget_set_size_request ( token_last == token_search ? toolitem_first : toolitem_second, diff --git a/midori/midori-panedaction.c b/midori/midori-panedaction.c index b6f615a7..e858b8a5 100644 --- a/midori/midori-panedaction.c +++ b/midori/midori-panedaction.c @@ -197,3 +197,31 @@ midori_paned_action_get_child_by_name (MidoriPanedAction* paned_action, return NULL; } + +/** + * midori_paned_action_get_child1_name: + * @paned_action a #MidoriPanedAction + * + * Returns: The name of the first child + **/ +const gchar* +midori_paned_action_get_child1_name (MidoriPanedAction* paned_action) +{ + g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL); + + return paned_action->child1.name; +} + +/** + * midori_paned_action_get_child2_name: + * @paned_action a #MidoriPanedAction + * + * Returns: The name of the second child + **/ +const gchar* +midori_paned_action_get_child2_name (MidoriPanedAction* paned_action) +{ + g_return_val_if_fail (MIDORI_IS_PANED_ACTION (paned_action), NULL); + + return paned_action->child2.name; +} diff --git a/midori/midori-panedaction.h b/midori/midori-panedaction.h index 384529bd..58444735 100644 --- a/midori/midori-panedaction.h +++ b/midori/midori-panedaction.h @@ -59,6 +59,12 @@ GtkWidget* midori_paned_action_get_child_by_name (MidoriPanedAction* paned_action, const gchar* name); +const gchar* +midori_paned_action_get_child1_name (MidoriPanedAction* paned_action); + +const gchar* +midori_paned_action_get_child2_name (MidoriPanedAction* paned_action); + G_END_DECLS #endif // __MIDORI_PANED_ACTION_H__