[nautilus-actions] Triggering of selection_changed message is all in IActionsList interface



commit c2fc3f8c3f5fec54c75008cf8f7e70ef6fc43f73
Author: Pierre Wieser <pwieser trychlos org>
Date:   Thu Jul 2 19:08:37 2009 +0200

    Triggering of selection_changed message is all in IActionsList interface

 ChangeLog                     |    4 ++-
 src/nact/nact-iactions-list.c |   43 +++++++++++++++++++++++++++++++++++++++-
 src/nact/nact-iactions-list.h |    3 ++
 src/nact/nact-main-window.c   |   31 +++++++++++------------------
 4 files changed, 59 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c50e271..9f7179e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,7 +11,9 @@
 
 	* src/nact/nact-iactions-list.c:
 	* src/nact/nact-iactions-list.h
-	(nact_iactions_list_set_selection): New function.
+	(nact_iactions_list_set_selection,
+	nact_iactions_list_set_send_selection_changed_on_fill_list,
+	nact_iactions_list_set_is_filling_list)): New functions.
 
 	* src/nact/nact-imenu-item.c:
 	* src/nact/nact-imenu-item.h (nact_imenu_item_size_labels,
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index dece094..bfd6b2b 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -52,6 +52,11 @@ enum {
 	IACTIONS_LIST_N_COLUMN
 };
 
+/* data set against GObject
+ */
+#define SEND_SELECTION_CHANGED_MESSAGE	"iactions-list-send-selection-changed-message"
+#define IS_FILLING_LIST					"iactions-list-is-filling-list"
+
 static GType      register_type( void );
 static void       interface_base_init( NactIActionsListInterface *klass );
 static void       interface_base_finalize( NactIActionsListInterface *klass );
@@ -143,6 +148,9 @@ nact_iactions_list_initial_load( NactWindow *window )
 {
 	g_assert( NACT_IS_IACTIONS_LIST( window ));
 
+	nact_iactions_list_set_send_selection_changed_on_fill_list( window, FALSE );
+	nact_iactions_list_set_is_filling_list( window, FALSE );
+
 	if( NACT_IACTIONS_LIST_GET_INTERFACE( window )->initial_load_widget ){
 		NACT_IACTIONS_LIST_GET_INTERFACE( window )->initial_load_widget( window );
 	} else {
@@ -173,11 +181,15 @@ nact_iactions_list_fill( NactWindow *window )
 {
 	g_assert( NACT_IS_IACTIONS_LIST( window ));
 
+	nact_iactions_list_set_is_filling_list( window, TRUE );
+
 	if( NACT_IACTIONS_LIST_GET_INTERFACE( window )->fill_actions_list ){
 		NACT_IACTIONS_LIST_GET_INTERFACE( window )->fill_actions_list( window );
 	} else {
 		do_fill_actions_list( window );
 	}
+
+	nact_iactions_list_set_is_filling_list( window, FALSE );
 }
 
 /**
@@ -265,6 +277,27 @@ nact_iactions_list_get_selected_action( NactWindow *window )
 	return( action );
 }
 
+/**
+ * Should the IActionsList interface trigger a 'on_selection_changed'
+ * message when the ActionsList list is filled ?
+ */
+void
+nact_iactions_list_set_send_selection_changed_on_fill_list( NactWindow *window, gboolean send_message )
+{
+	g_assert( NACT_IS_IACTIONS_LIST( window ));
+	g_object_set_data( G_OBJECT( window ), SEND_SELECTION_CHANGED_MESSAGE, GINT_TO_POINTER( send_message ));
+}
+
+/**
+ * Is the IActionsList interface currently filling the ActionsList ?
+ */
+void
+nact_iactions_list_set_is_filling_list( NactWindow *window, gboolean is_filling )
+{
+	g_assert( NACT_IS_IACTIONS_LIST( window ));
+	g_object_set_data( G_OBJECT( window ), IS_FILLING_LIST, GINT_TO_POINTER( is_filling ));
+}
+
 static void
 v_on_selection_changed( GtkTreeSelection *selection, gpointer user_data )
 {
@@ -273,8 +306,14 @@ v_on_selection_changed( GtkTreeSelection *selection, gpointer user_data )
 
 	NactIActionsList *instance = NACT_IACTIONS_LIST( user_data );
 
-	if( NACT_IACTIONS_LIST_GET_INTERFACE( instance )->on_selection_changed ){
-		NACT_IACTIONS_LIST_GET_INTERFACE( instance )->on_selection_changed( selection, user_data );
+	g_assert( NACT_IS_WINDOW( user_data ));
+	gboolean send_message = GPOINTER_TO_INT( g_object_get_data( G_OBJECT( user_data ), SEND_SELECTION_CHANGED_MESSAGE ));
+	gboolean is_filling = GPOINTER_TO_INT( g_object_get_data( G_OBJECT( user_data ), IS_FILLING_LIST ));
+
+	if( send_message || !is_filling ){
+		if( NACT_IACTIONS_LIST_GET_INTERFACE( instance )->on_selection_changed ){
+			NACT_IACTIONS_LIST_GET_INTERFACE( instance )->on_selection_changed( selection, user_data );
+		}
 	}
 }
 
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index caf3269..2d5af2c 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -77,6 +77,9 @@ GObject *nact_iactions_list_get_selected_action( NactWindow *window );
 void     nact_iactions_list_set_selection( NactWindow *window, const gchar *uuid, const gchar *label );
 void     nact_iactions_list_set_focus( NactWindow *window );
 
+void     nact_iactions_list_set_send_selection_changed_on_fill_list( NactWindow *window, gboolean send_message );
+void     nact_iactions_list_set_is_filling_list( NactWindow *window, gboolean is_filling );
+
 G_END_DECLS
 
 #endif /* __NACT_IACTIONS_LIST_H__ */
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index c8e6fb5..0f23f46 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -59,7 +59,6 @@ struct NactMainWindowClassPrivate {
  */
 struct NactMainWindowPrivate {
 	gboolean  dispose_has_run;
-	gboolean  selection_changed_authorized;
 	gchar    *current_uuid;
 	gchar    *current_label;
 };
@@ -287,7 +286,9 @@ on_initial_load_toplevel( BaseWindow *window )
 	g_assert( NACT_IS_MAIN_WINDOW( window ));
 	/*NactMainWindow *wnd = NACT_MAIN_WINDOW( window );*/
 
+	g_assert( NACT_IS_IACTIONS_LIST( window ));
 	nact_iactions_list_initial_load( NACT_WINDOW( window ));
+	nact_iactions_list_set_send_selection_changed_on_fill_list( NACT_WINDOW( window ), FALSE );
 }
 
 static void
@@ -312,8 +313,6 @@ on_runtime_init_toplevel( BaseWindow *window )
 	base_window_connect( window, "DuplicateActionButton", "clicked", G_CALLBACK( on_duplicate_button_clicked ));
 	base_window_connect( window, "DeleteActionButton", "clicked", G_CALLBACK( on_delete_button_clicked ));
 	base_window_connect( window, "ImExportButton", "clicked", G_CALLBACK( on_import_export_button_clicked ));
-
-	NACT_MAIN_WINDOW( window )->private->selection_changed_authorized = TRUE;
 }
 
 static void
@@ -323,23 +322,20 @@ on_actions_list_selection_changed( GtkTreeSelection *selection, gpointer user_da
 	g_debug( "%s: selection=%p, user_data=%p", thisfn, selection, user_data );*/
 
 	g_assert( NACT_IS_MAIN_WINDOW( user_data ));
-	if( NACT_MAIN_WINDOW( user_data )->private->selection_changed_authorized ){
-
-		BaseWindow *window = BASE_WINDOW( user_data );
+	BaseWindow *window = BASE_WINDOW( user_data );
 
-		GtkWidget *edit_button = base_window_get_widget( window, "EditActionButton" );
-		GtkWidget *delete_button = base_window_get_widget( window, "DeleteActionButton" );
-		GtkWidget *duplicate_button = base_window_get_widget( window, "DuplicateActionButton" );
+	GtkWidget *edit_button = base_window_get_widget( window, "EditActionButton" );
+	GtkWidget *delete_button = base_window_get_widget( window, "DeleteActionButton" );
+	GtkWidget *duplicate_button = base_window_get_widget( window, "DuplicateActionButton" );
 
-		gboolean enabled = ( gtk_tree_selection_count_selected_rows( selection ) > 0 );
+	gboolean enabled = ( gtk_tree_selection_count_selected_rows( selection ) > 0 );
 
-		gtk_widget_set_sensitive( edit_button, enabled );
-		gtk_widget_set_sensitive( delete_button, enabled );
-		gtk_widget_set_sensitive( duplicate_button, enabled );
+	gtk_widget_set_sensitive( edit_button, enabled );
+	gtk_widget_set_sensitive( delete_button, enabled );
+	gtk_widget_set_sensitive( duplicate_button, enabled );
 
-		NAAction *action = NA_ACTION( nact_iactions_list_get_selected_action( NACT_WINDOW( window )));
-		set_current_action( NACT_MAIN_WINDOW( window ), action );
-	}
+	NAAction *action = NA_ACTION( nact_iactions_list_get_selected_action( NACT_WINDOW( window )));
+	set_current_action( NACT_MAIN_WINDOW( window ), action );
 }
 
 static gboolean
@@ -610,13 +606,10 @@ on_actions_changed( NAIPivotContainer *instance, gpointer user_data )
 	g_assert( NACT_IS_MAIN_WINDOW( instance ));
 	NactMainWindow *self = NACT_MAIN_WINDOW( instance );
 
-	self->private->selection_changed_authorized = FALSE;
-
 	if( !self->private->dispose_has_run ){
 		nact_iactions_list_fill( NACT_WINDOW( instance ));
 	}
 
-	self->private->selection_changed_authorized = TRUE;
 	nact_iactions_list_set_selection(
 			NACT_WINDOW( self ), self->private->current_uuid, self->private->current_label );
 }



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