Unify toolbar rebuilding in _action_menubar_activate
And merge _midori_browser_save_toolbar_items into it, which was already not used anywhere else. CompactMenu is now always skipped and automatically added if the menubar is hidden. So it can no longer be duplicated or appear in the toolbar editor. Fixes: https://bugs.launchpad.net/midori/+bug/903003
This commit is contained in:
parent
c522706d63
commit
00d8621fe7
2 changed files with 51 additions and 70 deletions
|
@ -2233,6 +2233,7 @@ main (int argc,
|
||||||
{
|
{
|
||||||
gchar* tmp_uri = midori_prepare_uri (webapp);
|
gchar* tmp_uri = midori_prepare_uri (webapp);
|
||||||
midori_browser_set_action_visible (browser, "Menubar", FALSE);
|
midori_browser_set_action_visible (browser, "Menubar", FALSE);
|
||||||
|
midori_browser_set_action_visible (browser, "CompactMenu", FALSE);
|
||||||
midori_browser_add_uri (browser, tmp_uri ? tmp_uri : webapp);
|
midori_browser_add_uri (browser, tmp_uri ? tmp_uri : webapp);
|
||||||
g_object_set (settings, "homepage", tmp_uri, NULL);
|
g_object_set (settings, "homepage", tmp_uri, NULL);
|
||||||
g_free (tmp_uri);
|
g_free (tmp_uri);
|
||||||
|
|
|
@ -2691,44 +2691,6 @@ midori_browser_toolbar_item_button_press_event_cb (GtkWidget* toolitem,
|
||||||
GdkEventButton* event,
|
GdkEventButton* event,
|
||||||
MidoriBrowser* browser);
|
MidoriBrowser* browser);
|
||||||
|
|
||||||
static void
|
|
||||||
_midori_browser_save_toolbar_items (MidoriBrowser* browser)
|
|
||||||
{
|
|
||||||
GString* toolbar_items;
|
|
||||||
GList* children;
|
|
||||||
gchar* items;
|
|
||||||
|
|
||||||
toolbar_items = g_string_new (NULL);
|
|
||||||
children = gtk_container_get_children (GTK_CONTAINER (browser->navigationbar));
|
|
||||||
for (; children != NULL; children = g_list_next (children))
|
|
||||||
{
|
|
||||||
GtkAction* action;
|
|
||||||
|
|
||||||
action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (children->data));
|
|
||||||
/* If a widget has no action that is actually a bug, so warn about it */
|
|
||||||
g_warn_if_fail (action != NULL);
|
|
||||||
if (action)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
g_object_set (browser->settings, "toolbar-items", items, NULL);
|
|
||||||
g_free (items);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* midori_browser_get_toolbar_actions:
|
* midori_browser_get_toolbar_actions:
|
||||||
*
|
*
|
||||||
|
@ -3162,46 +3124,53 @@ _action_preferences_activate (GtkAction* action,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_action_menubar_activate (GtkToggleAction* action,
|
_action_menubar_activate (GtkToggleAction* menubar_action,
|
||||||
MidoriBrowser* browser)
|
MidoriBrowser* browser)
|
||||||
{
|
{
|
||||||
gboolean active = gtk_toggle_action_get_active (action);
|
gboolean active = gtk_toggle_action_get_active (menubar_action);
|
||||||
if (active)
|
|
||||||
{
|
|
||||||
GtkContainer* navigationbar = GTK_CONTAINER (browser->navigationbar);
|
|
||||||
GList* children = gtk_container_get_children (navigationbar);
|
|
||||||
GtkAction* menu_action = _action_by_name (browser, "CompactMenu");
|
GtkAction* menu_action = _action_by_name (browser, "CompactMenu");
|
||||||
|
GString* toolbar_items;
|
||||||
|
GList* children;
|
||||||
|
gchar* items;
|
||||||
|
|
||||||
|
toolbar_items = g_string_new (NULL);
|
||||||
|
children = gtk_container_get_children (GTK_CONTAINER (browser->navigationbar));
|
||||||
for (; children != NULL; children = g_list_next (children))
|
for (; children != NULL; children = g_list_next (children))
|
||||||
{
|
{
|
||||||
GtkAction* action_;
|
GtkAction* action = gtk_activatable_get_related_action (
|
||||||
|
GTK_ACTIVATABLE (children->data));
|
||||||
action_ = gtk_activatable_get_related_action (GTK_ACTIVATABLE (children->data));
|
if (!action)
|
||||||
if (action_ == menu_action)
|
continue;
|
||||||
|
if (action == ((GtkAction*)menu_action))
|
||||||
{
|
{
|
||||||
gtk_container_remove (navigationbar,
|
if (active)
|
||||||
|
{
|
||||||
|
gtk_container_remove (GTK_CONTAINER (browser->navigationbar),
|
||||||
GTK_WIDGET (children->data));
|
GTK_WIDGET (children->data));
|
||||||
_midori_browser_save_toolbar_items (browser);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
else if (MIDORI_IS_PANED_ACTION (action))
|
||||||
|
{
|
||||||
|
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
|
else
|
||||||
{
|
g_string_append (toolbar_items, gtk_action_get_name (action));
|
||||||
GtkAction* widget_action = _action_by_name (browser, "CompactMenu");
|
g_string_append_c (toolbar_items, ',');
|
||||||
GtkWidget* toolitem = gtk_action_create_tool_item (widget_action);
|
|
||||||
gtk_toolbar_insert (GTK_TOOLBAR (browser->navigationbar),
|
|
||||||
GTK_TOOL_ITEM (toolitem), -1);
|
|
||||||
g_signal_connect (gtk_bin_get_child (GTK_BIN (toolitem)),
|
|
||||||
"button-press-event",
|
|
||||||
G_CALLBACK (midori_browser_toolbar_item_button_press_event_cb),
|
|
||||||
browser);
|
|
||||||
_midori_browser_save_toolbar_items (browser);
|
|
||||||
}
|
}
|
||||||
|
g_list_free (children);
|
||||||
|
|
||||||
|
if (katze_object_get_boolean (browser->settings, "show-menubar") != active)
|
||||||
g_object_set (browser->settings, "show-menubar", active, NULL);
|
g_object_set (browser->settings, "show-menubar", active, NULL);
|
||||||
/* Make sure the menubar is uptodate in case no settings are set */
|
|
||||||
sokoke_widget_set_visible (browser->menubar, active);
|
|
||||||
|
|
||||||
|
items = g_string_free (toolbar_items, FALSE);
|
||||||
|
g_object_set (browser->settings, "toolbar-items", items, NULL);
|
||||||
|
g_free (items);
|
||||||
|
|
||||||
|
sokoke_widget_set_visible (browser->menubar, active);
|
||||||
g_object_set_data (G_OBJECT (browser), "midori-toolbars-visible",
|
g_object_set_data (G_OBJECT (browser), "midori-toolbars-visible",
|
||||||
gtk_widget_get_visible (browser->menubar)
|
gtk_widget_get_visible (browser->menubar)
|
||||||
|| gtk_widget_get_visible (browser->navigationbar)
|
|| gtk_widget_get_visible (browser->navigationbar)
|
||||||
|
@ -6450,7 +6419,7 @@ _midori_browser_set_toolbar_items (MidoriBrowser* browser,
|
||||||
for (; *name; ++name)
|
for (; *name; ++name)
|
||||||
{
|
{
|
||||||
action = _action_by_name (browser, *name);
|
action = _action_by_name (browser, *name);
|
||||||
if (action)
|
if (action && strstr (*name, "CompactMenu") == NULL)
|
||||||
{
|
{
|
||||||
token_last = token_current;
|
token_last = token_current;
|
||||||
|
|
||||||
|
@ -6532,6 +6501,18 @@ _midori_browser_set_toolbar_items (MidoriBrowser* browser,
|
||||||
GTK_TOOL_ITEM (gtk_action_create_tool_item (
|
GTK_TOOL_ITEM (gtk_action_create_tool_item (
|
||||||
_action_by_name (browser, token_current))), -1);
|
_action_by_name (browser, token_current))), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!katze_object_get_boolean (browser->settings, "show-menubar"))
|
||||||
|
{
|
||||||
|
toolitem = gtk_action_create_tool_item (
|
||||||
|
GTK_ACTION (_action_by_name (browser, "CompactMenu")));
|
||||||
|
gtk_toolbar_insert (GTK_TOOLBAR (browser->navigationbar),
|
||||||
|
GTK_TOOL_ITEM (toolitem), -1);
|
||||||
|
g_signal_connect (gtk_bin_get_child (GTK_BIN (toolitem)),
|
||||||
|
"button-press-event",
|
||||||
|
G_CALLBACK (midori_browser_toolbar_item_button_press_event_cb),
|
||||||
|
browser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -6688,7 +6669,6 @@ midori_browser_settings_notify (MidoriWebSettings* web_settings,
|
||||||
_toggle_tabbar_smartly (browser, FALSE);
|
_toggle_tabbar_smartly (browser, FALSE);
|
||||||
else if (name == g_intern_string ("show-menubar"))
|
else if (name == g_intern_string ("show-menubar"))
|
||||||
{
|
{
|
||||||
sokoke_widget_set_visible (browser->menubar, g_value_get_boolean (&value));
|
|
||||||
gtk_toggle_action_set_active (
|
gtk_toggle_action_set_active (
|
||||||
GTK_TOGGLE_ACTION (_action_by_name (browser, "Menubar")),
|
GTK_TOGGLE_ACTION (_action_by_name (browser, "Menubar")),
|
||||||
g_value_get_boolean (&value));
|
g_value_get_boolean (&value));
|
||||||
|
|
Loading…
Reference in a new issue