[nautilus-actions] Dynamically resort the treeview when the display order changes
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Dynamically resort the treeview when the display order changes
- Date: Fri, 2 Oct 2009 22:42:04 +0000 (UTC)
commit 80e9a7f68f5f8ba8d4a1bfd1a99c431d99245e03
Author: Pierre Wieser <pwieser trychlos org>
Date: Mon Sep 28 22:46:50 2009 +0200
Dynamically resort the treeview when the display order changes
ChangeLog | 3 +-
src/nact/nact-iactions-list.c | 39 ++++++++++++--
src/nact/nact-iactions-list.h | 1 +
src/nact/nact-main-window.c | 2 +
src/nact/nact-tree-model.c | 116 ++++++++++++++++++++++++++++-------------
src/nact/nact-tree-model.h | 1 +
6 files changed, 121 insertions(+), 41 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 13055ff..74e5056 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -54,7 +54,8 @@
* src/nact/nact-iactions-list.c:
* src/nact/nact-iactions-list.h
- (nact_iactions_list_collapse_all, nact_iactions_list_expand_all):
+ (nact_iactions_list_collapse_all, nact_iactions_list_expand_all,
+ nact_iactions_list_display_order_change):
New functions.
Remove useless nact-iactions-list-item-updated signal.
Connect instead to nact-tab-updatable-item-updated signal.
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 994cc1d..e6550a0 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -465,9 +465,13 @@ nact_iactions_list_collapse_all( NactIActionsList *instance )
GtkTreeView *treeview;
g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
+ g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
- treeview = get_actions_list_treeview( instance );
- gtk_tree_view_collapse_all( treeview );
+ if( st_initialized && !st_finalized ){
+
+ treeview = get_actions_list_treeview( instance );
+ gtk_tree_view_collapse_all( treeview );
+ }
}
/**
@@ -515,6 +519,29 @@ nact_iactions_list_delete( NactIActionsList *instance, GList *items )
}
/**
+ * nact_iactions_list_display_order_change:
+ * @instance: this #NactIActionsList implementation.
+ * @order_mode: the new order mode.
+ *
+ * Setup the new order mode.
+ */
+void
+nact_iactions_list_display_order_change( NactIActionsList *instance, gint order_mode )
+{
+ GtkTreeView *treeview;
+ NactTreeModel *model;
+
+ g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
+
+ if( st_initialized && !st_finalized ){
+
+ treeview = get_actions_list_treeview( instance );
+ model = NACT_TREE_MODEL( gtk_tree_view_get_model( treeview ));
+ nact_tree_model_display_order_change( model, order_mode );
+ }
+}
+
+/**
* nact_iactions_list_expand_all:
* @instance: this #NactIActionsList implementation.
*
@@ -527,9 +554,13 @@ nact_iactions_list_expand_all( NactIActionsList *instance )
GtkTreeView *treeview;
g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
+ g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
- treeview = get_actions_list_treeview( instance );
- gtk_tree_view_expand_all( treeview );
+ if( st_initialized && !st_finalized ){
+
+ treeview = get_actions_list_treeview( instance );
+ gtk_tree_view_expand_all( treeview );
+ }
}
/**
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index 274fd88..36d8af9 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -111,6 +111,7 @@ void nact_iactions_list_dispose( NactIActionsList *instance );
void nact_iactions_list_collapse_all( NactIActionsList *instance );
void nact_iactions_list_delete( NactIActionsList *instance, GList *items );
+void nact_iactions_list_display_order_change( NactIActionsList *instance, gint order_mode );
void nact_iactions_list_expand_all( NactIActionsList *instance );
void nact_iactions_list_fill( NactIActionsList *instance, GList *items );
NAObject *nact_iactions_list_get_item( NactIActionsList *instance, const gchar *uuid );
diff --git a/src/nact/nact-main-window.c b/src/nact/nact-main-window.c
index 89e8d6c..282f496 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -1175,4 +1175,6 @@ ipivot_consumer_on_display_order_changed( NAIPivotConsumer *instance, gint order
g_debug( "%s: instance=%p, order_mode=%d", thisfn, ( void * ) instance, order_mode );
g_assert( NACT_IS_MAIN_WINDOW( instance ));
/*self = NACT_MAIN_WINDOW( instance );*/
+
+ nact_iactions_list_display_order_change( NACT_IACTIONS_LIST( instance ), order_mode );
}
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 3393eaa..d879d19 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -90,6 +90,8 @@ struct NactTreeModelPrivate {
#define XDS_ATOM gdk_atom_intern( "XdndDirectSave0", FALSE )
#define XDS_FILENAME "xds.txt"
+#define TREE_MODEL_ORDER_MODE "nact-tree-model-order-mode"
+
enum {
NACT_XCHANGE_FORMAT_NACT = 0,
NACT_XCHANGE_FORMAT_XDS,
@@ -192,7 +194,7 @@ static void on_drag_end( GtkWidget *widget, GdkDragContext *context, B
/*static gboolean on_drag_drop( GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, BaseWindow *window );
static void on_drag_data_received( GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint info, guint time, BaseWindow *window );*/
-static gint sort_actions_list( GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, BaseWindow *window );
+static gint sort_actions_list( GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data );
static gboolean filter_visible( GtkTreeModel *store, GtkTreeIter *iter, NactTreeModel *model );
static char *get_xds_atom_value( GdkDragContext *context );
@@ -366,7 +368,9 @@ tree_model_new( BaseWindow *window, GtkTreeView *treeview )
static const gchar *thisfn = "nact_tree_model_new";
GtkTreeStore *ts_model;
NactTreeModel *model;
- /*gboolean alpha_order;*/
+ NactApplication *application;
+ NAPivot *pivot;
+ gint order_mode;
g_debug( "%s: window=%p, treeview=%p", thisfn, ( void * ) window, ( void * ) treeview );
g_return_val_if_fail( BASE_IS_WINDOW( window ), NULL );
@@ -376,18 +380,6 @@ tree_model_new( BaseWindow *window, GtkTreeView *treeview )
ts_model = gtk_tree_store_new(
IACTIONS_LIST_N_COLUMN, GDK_TYPE_PIXBUF, G_TYPE_STRING, NA_OBJECT_TYPE );
- gtk_tree_sortable_set_default_sort_func(
- GTK_TREE_SORTABLE( ts_model ),
- ( GtkTreeIterCompareFunc ) sort_actions_list, window, NULL );
-
- /*alpha_order = na_iprefs_get_alphabetical_order( NA_IPREFS( window ));
-
- if( alpha_order ){
- gtk_tree_sortable_set_sort_column_id(
- GTK_TREE_SORTABLE( ts_model ),
- IACTIONS_LIST_LABEL_COLUMN, GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID );
- }*/
-
/* create the filter model
*/
model = g_object_new( NACT_TREE_MODEL_TYPE, "child-model", ts_model, NULL );
@@ -395,6 +387,13 @@ tree_model_new( BaseWindow *window, GtkTreeView *treeview )
gtk_tree_model_filter_set_visible_func(
GTK_TREE_MODEL_FILTER( model ), ( GtkTreeModelFilterVisibleFunc ) filter_visible, model, NULL );
+ /* initialize the sortable interface
+ */
+ application = NACT_APPLICATION( base_window_get_application( window ));
+ pivot = nact_application_get_pivot( application );
+ order_mode = na_iprefs_get_order_mode( NA_IPREFS( pivot ));
+ nact_tree_model_display_order_change( model, order_mode );
+
model->private->window = window;
model->private->treeview = treeview;
@@ -513,6 +512,10 @@ nact_tree_model_dispose( NactTreeModel *model )
/**
* nact_tree_model_display:
+ * @model: this #NactTreeModel instance.
+ * @object: the object whose display is to be refreshed.
+ *
+ * Refresh the display of a #NAObject.
*/
void
nact_tree_model_display( NactTreeModel *model, NAObject *object )
@@ -542,6 +545,65 @@ nact_tree_model_display( NactTreeModel *model, NAObject *object )
}
}
+/**
+ * Setup the new order mode.
+ */
+void
+nact_tree_model_display_order_change( NactTreeModel *model, gint order_mode )
+{
+ GtkTreeStore *store;
+
+ g_return_if_fail( NACT_IS_TREE_MODEL( model ));
+
+ if( !model->private->dispose_has_run ){
+
+ store = GTK_TREE_STORE( gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model )));
+ g_object_set_data( G_OBJECT( store ), TREE_MODEL_ORDER_MODE, GINT_TO_POINTER( order_mode ));
+
+ switch( order_mode ){
+
+ case PREFS_ORDER_ALPHA_ASCENDING:
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE( store ),
+ IACTIONS_LIST_LABEL_COLUMN,
+ GTK_SORT_ASCENDING );
+
+ gtk_tree_sortable_set_sort_func(
+ GTK_TREE_SORTABLE( store ),
+ IACTIONS_LIST_LABEL_COLUMN,
+ ( GtkTreeIterCompareFunc ) sort_actions_list,
+ NULL,
+ NULL );
+ break;
+
+ case PREFS_ORDER_ALPHA_DESCENDING:
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE( store ),
+ IACTIONS_LIST_LABEL_COLUMN,
+ GTK_SORT_DESCENDING );
+
+ gtk_tree_sortable_set_sort_func(
+ GTK_TREE_SORTABLE( store ),
+ IACTIONS_LIST_LABEL_COLUMN,
+ ( GtkTreeIterCompareFunc ) sort_actions_list,
+ NULL,
+ NULL );
+ break;
+
+ case PREFS_ORDER_MANUAL:
+ default:
+
+ gtk_tree_sortable_set_sort_column_id(
+ GTK_TREE_SORTABLE( store ),
+ GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID,
+ 0 );
+ break;
+ }
+ }
+}
+
void
nact_tree_model_dump( NactTreeModel *model )
{
@@ -1452,41 +1514,23 @@ on_drag_data_received( GtkWidget *widget, GdkDragContext *drag_context, gint x,
}*/
static gint
-sort_actions_list( GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, BaseWindow *window )
+sort_actions_list( GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data )
{
/*static const gchar *thisfn = "nact_tree_model_sort_actions_list";*/
NAObjectId *obj_a, *obj_b;
- NactApplication *application;
- NAPivot *pivot;
- gint order_mode;
- gint ret = 0;
+ gint ret;
/*g_debug( "%s: model=%p, a=%p, b=%p, window=%p", thisfn, ( void * ) model, ( void * ) a, ( void * ) b, ( void * ) window );*/
- application = NACT_APPLICATION( base_window_get_application( window ));
- pivot = nact_application_get_pivot( application );
- order_mode = na_iprefs_get_order_mode( NA_IPREFS( pivot ));
-
gtk_tree_model_get( model, a, IACTIONS_LIST_NAOBJECT_COLUMN, &obj_a, -1 );
gtk_tree_model_get( model, b, IACTIONS_LIST_NAOBJECT_COLUMN, &obj_b, -1 );
- switch( order_mode ){
- case PREFS_ORDER_ALPHA_ASCENDING:
- ret = na_pivot_sort_alpha_asc( obj_a, obj_b );
- break;
-
- case PREFS_ORDER_ALPHA_DESCENDING:
- ret = na_pivot_sort_alpha_desc( obj_a, obj_b );
- break;
-
- case PREFS_ORDER_MANUAL:
- default:
- break;
- }
+ ret = na_pivot_sort_alpha_asc( obj_a, obj_b );
g_object_unref( obj_b );
g_object_unref( obj_a );
+ /*g_debug( "%s: ret=%d", thisfn, ret );*/
return( ret );
}
diff --git a/src/nact/nact-tree-model.h b/src/nact/nact-tree-model.h
index c4ca015..bf5f4ff 100644
--- a/src/nact/nact-tree-model.h
+++ b/src/nact/nact-tree-model.h
@@ -94,6 +94,7 @@ void nact_tree_model_runtime_init( NactTreeModel *model, gboolean have_d
void nact_tree_model_dispose( NactTreeModel *model );
void nact_tree_model_display( NactTreeModel *model, NAObject *object );
+void nact_tree_model_display_order_change( NactTreeModel *model, gint order_mode );
void nact_tree_model_dump( NactTreeModel *model );
void nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions);
gchar *nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePath *path, NAObject **parent );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]