[nautilus-actions] Optimize redisplay of the modified items in the treeview



commit 056880960e9894ac40bda45f20cfd11e84ecd34e
Author: Pierre Wieser <pwieser trychlos org>
Date:   Wed Oct 14 00:03:01 2009 +0200

    Optimize redisplay of the modified items in the treeview

 ChangeLog                       |   13 +++++++++++++
 src/common/na-object-api.h      |    1 -
 src/common/na-object-id-fn.h    |    2 +-
 src/common/na-object-id.c       |   29 +++++++++++++++++++++++++++--
 src/nact/nact-iaction-tab.c     |    8 ++++----
 src/nact/nact-iactions-list.c   |   17 ++++++++++-------
 src/nact/nact-iadvanced-tab.c   |    6 +++---
 src/nact/nact-icommand-tab.c    |    6 +++---
 src/nact/nact-iconditions-tab.c |   10 +++++-----
 src/nact/nact-main-window.c     |    4 ++--
 src/nact/nact-marshal.list      |    1 +
 src/runtime/na-iduplicable.c    |    7 +------
 12 files changed, 70 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5b85083..dd35af8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2009-10-13 Pierre Wieser <pwieser trychlos org>
 
+	* src/common/na-object-api.h (na_object_get_topmost_parent):
+	Removed alias.
+
+	* src/nact/nact-iaction-tab.c:
+	* src/nact/nact-iadvanced-tab.c:
+	* src/nact/nact-icommand-tab.c:
+	* src/nact/nact-iconditions-tab.c:
+	Force re-display of the item if modified column is displayed in
+	the treeview.
+
+	* src/nact/nact-iactions-list.c (on_tab_updatable_item_updated):
+	Force re-display of the item if asked for and status not modified.
+
 	* src/common/na-object-api.h:
 	* src/common/na-object-id-fn.h:
 	* src/common/na-object-id.c (na_object_check_status_up):
diff --git a/src/common/na-object-api.h b/src/common/na-object-api.h
index 41aec80..1b989da 100644
--- a/src/common/na-object-api.h
+++ b/src/common/na-object-api.h
@@ -64,7 +64,6 @@ G_BEGIN_DECLS
 /* NAObjectId
  */
 #define na_object_check_status_up( object )			na_object_id_check_status_up( NA_OBJECT_ID( object ))
-#define na_object_get_topmost_parent( object )		na_object_id_get_topmost_parent( NA_OBJECT_ID( object ))
 #define na_object_prepare_for_paste( object, pivot, renumber, action ) \
 													na_object_id_prepare_for_paste( NA_OBJECT_ID( object ), pivot, renumber, ( NAObjectAction * ) action )
 #define na_object_set_copy_of_label( object )		na_object_id_set_copy_of_label( NA_OBJECT_ID( object ))
diff --git a/src/common/na-object-id-fn.h b/src/common/na-object-id-fn.h
index 175dc97..3d50be8 100644
--- a/src/common/na-object-id-fn.h
+++ b/src/common/na-object-id-fn.h
@@ -48,7 +48,7 @@
 
 G_BEGIN_DECLS
 
-void        na_object_id_check_status_up( NAObjectId *object );
+gboolean    na_object_id_check_status_up( NAObjectId *object );
 NAObjectId *na_object_id_get_topmost_parent( NAObjectId *object );
 void        na_object_id_prepare_for_paste( NAObjectId *object, NAPivot *pivot, gboolean renumber, NAObjectAction *action );
 void        na_object_id_set_copy_of_label( NAObjectId *object );
diff --git a/src/common/na-object-id.c b/src/common/na-object-id.c
index 7350dfd..0c57340 100644
--- a/src/common/na-object-id.c
+++ b/src/common/na-object-id.c
@@ -47,20 +47,45 @@
  *
  * Checks for modification and validity status of the @object, its
  * parent, the parent of its parent, etc. up to the top of the hierarchy.
+ *
+ * Returns: %TRUE if at least one of the status has changed, %FALSE else.
+ *
+ * Checking the modification of any of the status should be more
+ * efficient that systematically force the display of the item.
  */
-void
+gboolean
 na_object_id_check_status_up( NAObjectId *object )
 {
-	g_return_if_fail( NA_OBJECT_ID( object ));
+	gboolean changed;
+	gboolean was_modified, is_modified;
+	gboolean was_valid, is_valid;
+
+	g_return_val_if_fail( NA_OBJECT_ID( object ), FALSE );
+
+	changed = FALSE;
 
 	if( !object->private->dispose_has_run ){
 
+		was_modified = na_object_is_modified( object );
+		was_valid = na_object_is_valid( object );
+
 		na_iduplicable_check_status( NA_IDUPLICABLE( object ));
 
+		is_modified = na_object_is_modified( object );
+		is_valid = na_object_is_valid( object );
+
 		if( object->private->parent ){
 			na_object_id_check_status_up( NA_OBJECT_ID( object->private->parent ));
 		}
+
+		changed =
+			( was_modified && !is_modified ) ||
+			( !was_modified && is_modified ) ||
+			( was_valid && !is_valid ) ||
+			( !was_valid && is_valid );
 	}
+
+	return( changed );
 }
 
 /**
diff --git a/src/nact/nact-iaction-tab.c b/src/nact/nact-iaction-tab.c
index 88967aa..cd05490 100644
--- a/src/nact/nact-iaction-tab.c
+++ b/src/nact/nact-iaction-tab.c
@@ -496,7 +496,7 @@ on_enabled_toggled( GtkToggleButton *button, NactIActionTab *instance )
 	if( edited && NA_IS_OBJECT_ACTION( edited )){
 		enabled = gtk_toggle_button_get_active( button );
 		na_object_item_set_enabled( edited, enabled );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
@@ -514,7 +514,7 @@ on_label_changed( GtkEntry *entry, NactIActionTab *instance )
 	if( edited ){
 		label = gtk_entry_get_text( entry );
 		na_object_set_label( NA_OBJECT( edited ), label );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, TRUE );
 		check_for_label( instance, entry, label );
 	}
 
@@ -576,7 +576,7 @@ on_icon_changed( GtkEntry *icon_entry, NactIActionTab *instance )
 	if( edited ){
 		icon_name = gtk_entry_get_text( icon_entry );
 		na_object_item_set_icon( edited, icon_name );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, TRUE );
 
 		if( icon_name && strlen( icon_name ) > 0 ){
 			icon = na_object_item_get_pixbuf( edited, image );
@@ -598,7 +598,7 @@ on_tooltip_changed( GtkEntry *entry, NactIActionTab *instance )
 
 	if( edited ){
 		na_object_item_set_tooltip( edited, gtk_entry_get_text( entry ));
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index a32d421..fbc4009 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -168,7 +168,7 @@ static gboolean     on_focus_out( GtkWidget *widget, GdkEventFocus *event, NactI
 static gboolean     on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, NactIActionsList *instance );
 static void         on_label_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, NactIActionsList *instance );
 static void         on_treeview_selection_changed( GtkTreeSelection *selection, NactIActionsList *instance );
-static void         on_tab_updatable_item_updated( NactIActionsList *instance, NAObject *object );
+static void         on_tab_updatable_item_updated( NactIActionsList *instance, NAObject *object, gboolean force_display );
 static void         on_iactions_list_selection_changed( NactIActionsList *instance, GSList *selected_items );
 static void         select_first_row( NactIActionsList *instance );
 static void         select_row_at_path( NactIActionsList *instance, GtkTreeView *treeview, GtkTreeModel *model, GtkTreePath *path );
@@ -1145,7 +1145,7 @@ nact_iactions_list_insert_into( NactIActionsList *instance, GList *items )
 
 		parent = do_insert_into_first( treeview, model, items, insert_path, &new_path );
 
-		na_object_check_status( parent );
+		na_object_check_status_up( parent );
 
 		gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( model ));
 
@@ -1311,7 +1311,7 @@ update_parents_edition_status( GList *parents, GList *items )
 	}*/
 
 	for( it = parents ; it ; it = it->next ){
-		na_object_check_status( it->data );
+		na_object_check_status_up( it->data );
 	}
 
 	g_list_free( parents );
@@ -1921,21 +1921,24 @@ on_treeview_selection_changed( GtkTreeSelection *selection, NactIActionsList *in
  * update the treeview to reflects its new edition status
  */
 static void
-on_tab_updatable_item_updated( NactIActionsList *instance, NAObject *object )
+on_tab_updatable_item_updated( NactIActionsList *instance, NAObject *object, gboolean force_display )
 {
 	static const gchar *thisfn = "nact_iactions_list_on_tab_updatable_item_updated";
-	NAObjectId *item;
 	GtkTreeView *treeview;
 	GtkTreeModel *model;
 
 	g_debug( "%s: instance=%p, object=%p (%s)", thisfn,
 			( void * ) instance, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
+	g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
+	g_return_if_fail( NA_IS_OBJECT( object ));
+	g_return_if_fail( NA_IS_IDUPLICABLE( object ));
 
 	if( object ){
 		treeview = get_actions_list_treeview( instance );
 		model = gtk_tree_view_get_model( treeview );
-		item = na_object_get_topmost_parent( object );
-		na_object_check_status( item );
+		if( !na_object_check_status_up( object ) && force_display ){
+			on_edition_status_changed( instance, NA_IDUPLICABLE( object ));
+		}
 	}
 }
 
diff --git a/src/nact/nact-iadvanced-tab.c b/src/nact/nact-iadvanced-tab.c
index 40af342..9138ffc 100644
--- a/src/nact/nact-iadvanced-tab.c
+++ b/src/nact/nact-iadvanced-tab.c
@@ -565,7 +565,7 @@ on_remove_scheme_clicked( GtkButton *button, NactIAdvancedTab *instance )
 					TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
 					NULL );
 			na_object_profile_set_scheme( edited, scheme, FALSE );
-			g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+			g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 		}
 
 		g_free( scheme );
@@ -604,7 +604,7 @@ on_scheme_keyword_edited( GtkCellRendererText *renderer, const gchar *path, cons
 				NULL );
 		na_object_profile_set_scheme( edited, old_text, FALSE );
 		na_object_profile_set_scheme( edited, text, TRUE );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 
 	g_free( old_text );
@@ -663,7 +663,7 @@ on_scheme_selection_toggled( GtkCellRendererToggle *renderer, gchar *path, NactI
 
 		g_free( scheme );
 
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
diff --git a/src/nact/nact-icommand-tab.c b/src/nact/nact-icommand-tab.c
index ab8fc87..bcde9d6 100644
--- a/src/nact/nact-icommand-tab.c
+++ b/src/nact/nact-icommand-tab.c
@@ -497,7 +497,7 @@ on_label_changed( GtkEntry *entry, NactICommandTab *instance )
 	if( edited ){
 		label = gtk_entry_get_text( entry );
 		na_object_set_label( edited, label );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, TRUE );
 		check_for_label( instance, entry, label );
 	}
 }
@@ -525,7 +525,7 @@ on_parameters_changed( GtkEntry *entry, NactICommandTab *instance )
 
 	if( edited ){
 		na_object_profile_set_parameters( edited, gtk_entry_get_text( entry ));
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 
 	update_example_label( instance, edited );
@@ -596,7 +596,7 @@ on_path_changed( GtkEntry *entry, NactICommandTab *instance )
 
 	if( edited ){
 		na_object_profile_set_path( edited, gtk_entry_get_text( entry ));
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 
 	update_example_label( instance, edited );
diff --git a/src/nact/nact-iconditions-tab.c b/src/nact/nact-iconditions-tab.c
index a85d015..d33b49c 100644
--- a/src/nact/nact-iconditions-tab.c
+++ b/src/nact/nact-iconditions-tab.c
@@ -406,7 +406,7 @@ on_basenames_changed( GtkEntry *entry, NactIConditionsTab *instance )
 		basenames = na_utils_text_to_string_list( text );
 		na_object_profile_set_basenames( edited, basenames );
 		na_utils_free_string_list( basenames );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
@@ -430,7 +430,7 @@ on_isfiledir_toggled( GtkToggleButton *button, NactIConditionsTab *instance )
 	if( edited ){
 		nact_iconditions_tab_get_isfiledir( instance, &isfile, &isdir );
 		na_object_profile_set_isfiledir( edited, isfile, isdir );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
@@ -448,7 +448,7 @@ on_matchcase_toggled( GtkToggleButton *button, NactIConditionsTab *instance )
 	if( edited ){
 		matchcase = gtk_toggle_button_get_active( button );
 		na_object_profile_set_matchcase( edited, matchcase );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
@@ -469,7 +469,7 @@ on_mimetypes_changed( GtkEntry *entry, NactIConditionsTab *instance )
 		mimetypes = na_utils_text_to_string_list( text );
 		na_object_profile_set_mimetypes( edited, mimetypes );
 		na_utils_free_string_list( mimetypes );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
@@ -487,7 +487,7 @@ on_multiple_toggled( GtkToggleButton *button, NactIConditionsTab *instance )
 	if( edited ){
 		multiple = gtk_toggle_button_get_active( button );
 		na_object_profile_set_multiple( edited, multiple );
-		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited );
+		g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 	}
 }
 
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 698865c..5a7313d 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -155,7 +155,7 @@ static void     set_current_object_item( NactMainWindow *window, GSList *selecte
 static void     set_current_profile( NactMainWindow *window, gboolean set_action, GSList *selected_items );
 static gchar   *iactions_list_get_treeview_name( NactIActionsList *instance );
 
-static void     on_tab_updatable_item_updated( NactMainWindow *window, gpointer user_data );
+static void     on_tab_updatable_item_updated( NactMainWindow *window, gpointer user_data, gboolean force_display );
 
 static gboolean confirm_for_giveup_from_menu( NactMainWindow *window );
 static gboolean confirm_for_giveup_from_pivot( NactMainWindow *window );
@@ -1094,7 +1094,7 @@ iactions_list_get_treeview_name( NactIActionsList *instance )
 }
 
 static void
-on_tab_updatable_item_updated( NactMainWindow *window, gpointer user_data )
+on_tab_updatable_item_updated( NactMainWindow *window, gpointer user_data, gboolean force_display )
 {
 	/*static const gchar *thisfn = "nact_main_window_on_tab_updatable_item_updated";*/
 
diff --git a/src/nact/nact-marshal.list b/src/nact/nact-marshal.list
index 5622cff..5151d62 100644
--- a/src/nact/nact-marshal.list
+++ b/src/nact/nact-marshal.list
@@ -1,2 +1,3 @@
 VOID:INT,INT,INT
 VOID:POINTER,POINTER,INT
+VOID:POINTER,BOOLEAN
diff --git a/src/runtime/na-iduplicable.c b/src/runtime/na-iduplicable.c
index 41d6727..c075059 100644
--- a/src/runtime/na-iduplicable.c
+++ b/src/runtime/na-iduplicable.c
@@ -322,17 +322,12 @@ na_iduplicable_dump( const NAIDuplicable *object )
 void
 na_iduplicable_check_status( const NAIDuplicable *object )
 {
-#if NA_IDUPLICABLE_EDITION_STATUS_DEBUG
 	static const gchar *thisfn = "na_iduplicable_check_status";
-#endif
 	gboolean modified = TRUE;
 	NAIDuplicable *origin;
 	gboolean valid;
 
-#if NA_IDUPLICABLE_EDITION_STATUS_DEBUG
-	g_debug( "%s: object=%p (%s)", thisfn,
-			( void * ) object, G_OBJECT_TYPE_NAME( object ));
-#endif
+	g_debug( "%s: object=%p (%s)", thisfn, ( void * ) object, G_OBJECT_TYPE_NAME( object ));
 	g_return_if_fail( st_initialized && !st_finalized );
 	g_return_if_fail( NA_IS_IDUPLICABLE( object ));
 



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