[gnome-scan/gnome-scan-0-6] Set sensitivity of remove/clear button according to list contents



commit 40b42c7b711ec3111e34f16e7844e919262317f3
Author: Ã?tienne Bersac <bersace gnome org>
Date:   Tue Jun 9 19:57:29 2009 +0200

    Set sensitivity of remove/clear button according to list contents
---
 modules/gsfile-filenames-widget.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/modules/gsfile-filenames-widget.c b/modules/gsfile-filenames-widget.c
index 8b561be..6e89cc0 100644
--- a/modules/gsfile-filenames-widget.c
+++ b/modules/gsfile-filenames-widget.c
@@ -42,6 +42,8 @@ struct _GSFileFilenamesWidgetPrivate
 	GtkWidget			*filechooser;
 	GtkListStore		*liststore;
 	GtkTreeSelection	*selection;
+	GtkWidget			*remove_btn;
+	GtkWidget			*clear_btn;
 };
 
 enum
@@ -143,12 +145,14 @@ gsfile_filenames_widget_build (GnomeScanParamWidget *gspw)
 					  (GCallback) gsffw_filenames_add, gsffw);
 	gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
 	
-	button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
+	priv->remove_btn = button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
+	gtk_widget_set_sensitive(button, FALSE);
 	g_signal_connect (button, "clicked",
 					  (GCallback) gsffw_filenames_remove, gsffw);
 	gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
 	
-	button = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
+	priv->clear_btn = button = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
+	gtk_widget_set_sensitive(button, FALSE);
 	g_signal_connect (button, "clicked",
 					  (GCallback) gsffw_filenames_clear, gsffw);
 	gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
@@ -250,6 +254,8 @@ gsffw_filenames_populate (GSFileFilenamesWidget *gsffw)
 	gtk_tree_model_foreach (GTK_TREE_MODEL (GET_PRIVATE (gsffw)->liststore),
 							(GtkTreeModelForeachFunc) gsffw_filenames_preview_foreach_func,
 							gsffw);
+	gtk_widget_set_sensitive(priv->remove_btn, TRUE);
+	gtk_widget_set_sensitive(priv->clear_btn, TRUE);
 	gsffw_filenames_changed (gsffw);
 }
 
@@ -292,13 +298,21 @@ gsffw_filenames_remove (GtkButton *button, GSFileFilenamesWidget *gsffw)
 		gtk_tree_path_free (node->data);
 	}
 	g_list_free (first);
+	/* deactivate removing buttons if no first row */
+	if (!gtk_tree_model_get_iter_first(model, &iter)) {
+		gtk_widget_set_sensitive(priv->remove_btn, FALSE);
+		gtk_widget_set_sensitive(priv->clear_btn, FALSE);
+	}
 	gsffw_filenames_changed (gsffw);
 }
 
 static void
 gsffw_filenames_clear (GtkButton *button, GSFileFilenamesWidget *gsffw)
 {
+	GSFileFilenamesWidgetPrivate *priv = GET_PRIVATE (gsffw);
 	gtk_list_store_clear (GET_PRIVATE (gsffw)->liststore);
+	gtk_widget_set_sensitive(priv->remove_btn, FALSE);
+	gtk_widget_set_sensitive(priv->clear_btn, FALSE);
 	gsffw_filenames_changed (gsffw);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]