[geany/geany] 99fbe0: Fix plugin_add_toolbar_item insertion order

Dimitar Zhekov git-noreply at xxxxx
Fri Feb 22 16:14:53 UTC 2013


Branch:      refs/heads/master
Author:      Dimitar Zhekov <dimitar.zhekov at gmail.com>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Fri, 22 Feb 2013 16:14:53 UTC
Commit:      99fbe0bd8ca3882fc4c2c96b4e241301def74ca1
             https://github.com/geany/geany/commit/99fbe0bd8ca3882fc4c2c96b4e241301def74ca1

Log Message:
-----------
Fix plugin_add_toolbar_item insertion order


Modified Paths:
--------------
    src/pluginutils.c
    src/ui_utils.c
    src/ui_utils.h

Modified: src/pluginutils.c
9 files changed, 4 insertions(+), 5 deletions(-)
===================================================================
@@ -62,18 +62,17 @@ void plugin_add_toolbar_item(GeanyPlugin *plugin, GtkToolItem *item)
 		gtk_toolbar_insert(toolbar, sep, pos);
 		autosep->widget = GTK_WIDGET(sep);
 
-		gtk_toolbar_insert(toolbar, item, pos + 1);
-
 		toolbar_item_ref(sep);
-		toolbar_item_ref(item);
 	}
 	else
 	{
 		pos = gtk_toolbar_get_item_index(toolbar, GTK_TOOL_ITEM(autosep->widget));
 		g_return_if_fail(pos >= 0);
-		gtk_toolbar_insert(toolbar, item, pos);
-		toolbar_item_ref(item);
 	}
+
+	gtk_toolbar_insert(toolbar, item, pos + autosep->item_count + 1);
+	toolbar_item_ref(item);
+
 	/* hide the separator widget if there are no toolbar items showing for the plugin */
 	ui_auto_separator_add_ref(autosep, GTK_WIDGET(item));
 }


Modified: src/ui_utils.c
30 files changed, 19 insertions(+), 11 deletions(-)
===================================================================
@@ -2247,10 +2247,15 @@ void ui_finalize(void)
 
 static void auto_separator_update(GeanyAutoSeparator *autosep)
 {
-	g_return_if_fail(autosep->ref_count >= 0);
+	g_return_if_fail(autosep->item_count >= 0);
 
 	if (autosep->widget)
-		ui_widget_show_hide(autosep->widget, autosep->ref_count > 0);
+	{
+		if (autosep->item_count > 0)
+			ui_widget_show_hide(autosep->widget, autosep->show_count > 0);
+		else
+			gtk_widget_destroy(autosep->widget);
+	}
 }
 
 
@@ -2259,9 +2264,9 @@ static void on_auto_separator_item_show_hide(GtkWidget *widget, gpointer user_da
 	GeanyAutoSeparator *autosep = user_data;
 
 	if (GTK_WIDGET_VISIBLE(widget))
-		autosep->ref_count++;
+		autosep->show_count++;
 	else
-		autosep->ref_count--;
+		autosep->show_count--;
 	auto_separator_update(autosep);
 }
 
@@ -2270,10 +2275,12 @@ static void on_auto_separator_item_destroy(GtkWidget *widget, gpointer user_data
 {
 	GeanyAutoSeparator *autosep = user_data;
 
+	autosep->item_count--;
+	autosep->item_count = MAX(autosep->item_count, 0);
 	/* GTK_WIDGET_VISIBLE won't work now the widget is being destroyed,
 	 * so assume widget was visible */
-	autosep->ref_count--;
-	autosep->ref_count = MAX(autosep->ref_count, 0);
+	autosep->show_count--;
+	autosep->show_count = MAX(autosep->item_count, 0);
 	auto_separator_update(autosep);
 }
 
@@ -2285,15 +2292,16 @@ static void on_auto_separator_item_destroy(GtkWidget *widget, gpointer user_data
 void ui_auto_separator_add_ref(GeanyAutoSeparator *autosep, GtkWidget *item)
 {
 	/* set widget ptr NULL when widget destroyed */
-	if (autosep->ref_count == 0)
+	if (autosep->item_count == 0)
 		g_signal_connect(autosep->widget, "destroy",
 			G_CALLBACK(gtk_widget_destroyed), &autosep->widget);
 
 	if (GTK_WIDGET_VISIBLE(item))
-	{
-		autosep->ref_count++;
-		auto_separator_update(autosep);
-	}
+		autosep->show_count++;
+
+	autosep->item_count++;
+	auto_separator_update(autosep);
+
 	g_signal_connect(item, "show", G_CALLBACK(on_auto_separator_item_show_hide), autosep);
 	g_signal_connect(item, "hide", G_CALLBACK(on_auto_separator_item_show_hide), autosep);
 	g_signal_connect(item, "destroy", G_CALLBACK(on_auto_separator_item_destroy), autosep);


Modified: src/ui_utils.h
3 files changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -148,7 +148,8 @@
 typedef struct GeanyAutoSeparator
 {
 	GtkWidget	*widget;	/* e.g. GtkSeparatorToolItem, GtkSeparatorMenuItem */
-	gint		ref_count;	/* set to zero initially */
+	gint		show_count;	/* visible items, set to zero initially */
+	gint		item_count;	/* total items, set to zero initially */
 }
 GeanyAutoSeparator;
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list