[nautilus-actions] Update tree on delete
- From: Pierre Wieser <pwieser src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Update tree on delete
- Date: Sat, 26 Sep 2009 22:47:45 +0000 (UTC)
commit b107f0af498682aa97791dd8bfe269bf4e291009
Author: Pierre Wieser <pwieser trychlos org>
Date: Sat Sep 19 17:52:39 2009 +0200
Update tree on delete
ChangeLog | 5 ++
src/common/na-obj-action.c | 2 +-
src/nact/nact-iactions-list.c | 35 ++++++++--
src/nact/nact-iactions-list.h | 6 --
src/nact/nact-main-window.c | 4 +-
src/nact/nact-tree-model.c | 154 +++++++++++++++++++----------------------
src/nact/nact-tree-model.h | 1 +
7 files changed, 108 insertions(+), 99 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 519b0ed..12e0cc6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@
* src/common/na-object.c b:
Add class name in instance_dipose() trace.
+ * src/common/na-obj-action.c (are_equal): Remove trace.
+
* src/common/na-obj-menu.c:
Remove traces at instance_dispose() and instance_finalize().
@@ -36,6 +38,9 @@
nact_main_window_get_modified_items_count(): Replaced with
nact_main_window_has_modified_items().
+ * src/nact/nact-tree-model.c:
+ * src/nact/nact-tree-model.h (nact_tree_model_display): New function.
+
* src/nact/nact-window.c:
* src/nact/nact-window.h (nact_window_warn_count_modified):
Renamed as nact_window_warn_modified() with string change.
diff --git a/src/common/na-obj-action.c b/src/common/na-obj-action.c
index 937a626..4572d4c 100644
--- a/src/common/na-obj-action.c
+++ b/src/common/na-obj-action.c
@@ -565,7 +565,7 @@ object_are_equal( const NAObject *a, const NAObject *b )
equal = ( g_utf8_collate( first->private->version, second->private->version ) == 0 );
}
- g_debug( "na_object_action_are_equal: %s", equal ? "True":"False" );
+ /*g_debug( "na_object_action_are_equal: %s", equal ? "True":"False" );*/
return( equal );
}
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index 37b2f66..88564f9 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -434,6 +434,10 @@ nact_iactions_list_dispose( NactIActionsList *instance )
* The returned @path tries to represent the most probable available
* selection after deletion has occured.
* It should be gtk_tree_path_free() by the caller.
+ *
+ * This function takes care of refilter the display model.
+ * if possible, a new selection should be set with
+ * #nact_iactions_list_select_row().
*/
void
nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **path )
@@ -460,6 +464,8 @@ nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **p
g_list_foreach( selected, ( GFunc ) gtk_tree_path_free, NULL );
g_list_free( selected );
+
+ gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( model ));
}
/**
@@ -623,6 +629,9 @@ nact_iactions_list_has_modified_items( NactIActionsList *instance )
*
* If new item is a #NAActionMenu or a #NAAction, it will be inserted
* before the current action or inside the current menu.
+ *
+ * This function takes care of repositionning a new selection if
+ * possible, and refilter the display model.
*/
void
nact_iactions_list_insert_items( NactIActionsList *instance, GList *items )
@@ -632,9 +641,10 @@ nact_iactions_list_insert_items( NactIActionsList *instance, GList *items )
GtkTreeModel *model;
GtkTreeSelection *selection;
GList *list_selected;
- GtkTreePath *insert_path;
- GtkTreePath *last_path;
- GList *parents, *it;
+ GtkTreePath *insert_path = NULL;
+ GtkTreePath *last_path = NULL;
+ GList *parents = NULL;
+ GList *it;
g_debug( "%s: instance=%p, items=%p (%d items)",
thisfn, ( void * ) instance, ( void * ) items, g_list_length( items ));
@@ -645,7 +655,6 @@ nact_iactions_list_insert_items( NactIActionsList *instance, GList *items )
model = gtk_tree_view_get_model( treeview );
g_return_if_fail( NACT_IS_TREE_MODEL( model ));
- insert_path = NULL;
selection = gtk_tree_view_get_selection( treeview );
list_selected = gtk_tree_selection_get_selected_rows( selection, NULL );
if( g_list_length( list_selected )){
@@ -655,7 +664,6 @@ nact_iactions_list_insert_items( NactIActionsList *instance, GList *items )
g_list_foreach( list_selected, ( GFunc ) gtk_tree_path_free, NULL );
g_list_free( list_selected );
- parents = NULL;
last_path = do_insert_items( treeview, model, items, insert_path, 0, &parents );
for( it = parents ; it ; it = it->next ){
@@ -1256,7 +1264,7 @@ on_treeview_selection_changed( GtkTreeSelection *selection, NactIActionsList *in
selected_items = nact_iactions_list_get_selected_items( instance );
- if( !is_selection_changed_authorized( instance )){
+ if( is_selection_changed_authorized( instance )){
g_signal_emit_by_name( instance, IACTIONS_LIST_SIGNAL_SELECTION_CHANGED, selected_items );
}
}
@@ -1281,6 +1289,21 @@ on_iactions_list_item_updated( NactIActionsList *instance, NAObject *object )
static void
on_iactions_list_item_updated_treeview( NactIActionsList *instance, NAObject *object )
{
+ NAObject *item;
+ GtkTreeView *treeview;
+ GtkTreeModel *model;
+
+ if( object ){
+ item = NA_IS_OBJECT_PROFILE( object )
+ ? NA_OBJECT( na_object_profile_get_action( NA_OBJECT_PROFILE( object )))
+ : object;
+
+ na_object_check_edition_status( item );
+
+ treeview = get_actions_list_treeview( instance );
+ model = gtk_tree_view_get_model( treeview );
+ nact_tree_model_display( NACT_TREE_MODEL( model ), object );
+ }
}
/*
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index b10aaf6..a909b32 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -92,12 +92,6 @@ void nact_iactions_list_set_multiple_selection_mode( NactIActionsList *inst
void nact_iactions_list_set_only_actions_mode( NactIActionsList *instance, gboolean only_actions );
void nact_iactions_list_toggle_collapse( NactIActionsList *instance, const NAObject *item );
-/*
-void nact_list_actions_insert_item( NactMainWindow *window, NAObject *item );
-void nact_list_actions_set_selection( NactMainWindow *window, GType type, const gchar *uuid, const gchar *label );
-void nact_list_actions_update_selected( NactMainWindow *window, NAAction *action );
-*/
-
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 08384d4..bf62060 100644
--- a/src/nact/nact-main-window.c
+++ b/src/nact/nact-main-window.c
@@ -909,14 +909,14 @@ set_current_profile( NactMainWindow *window, gboolean set_action, GSList *select
static void
on_tab_updatable_item_updated( NactMainWindow *window, gpointer user_data )
{
- static const gchar *thisfn = "on_tab_updatable_item_updated";
+ static const gchar *thisfn = "nact_main_window_on_tab_updatable_item_updated";
g_debug( "%s: window=%p, user_data=%p", thisfn, ( void * ) window, ( void * ) user_data );
g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
if( !window->private->dispose_has_run ){
- g_signal_emit_by_name( window, IACTIONS_LIST_SIGNAL_ITEM_UPDATED, NULL );
+ g_signal_emit_by_name( window, IACTIONS_LIST_SIGNAL_ITEM_UPDATED, user_data );
}
}
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index d0f0d98..0628f72 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -145,14 +145,15 @@ static void instance_finalize( GObject *application );
static NactTreeModel *tree_model_new( BaseWindow *window, GtkTreeView *treeview );
+static GList *add_parent( GList *parents, GtkTreeModel *store, GtkTreeIter *obj_iter, GtkTreePath *obj_path );
static void append_item( GtkTreeStore *model, GtkTreeView *treeview, GtkTreeIter *parent, GtkTreeIter *iter, const NAObject *object );
static void display_item( GtkTreeStore *model, GtkTreeView *treeview, GtkTreeIter *iter, const NAObject *object );
static gboolean dump_store( NactTreeModel *model, GtkTreePath *path, NAObject *object, ntmDumpStruct *ntm );
static void fill_tree_store( GtkTreeStore *model, GtkTreeView *treeview, GList *items, gboolean only_actions, GtkTreeIter *parent );
static void iter_on_store( NactTreeModel *model, GtkTreeModel *store, GtkTreeIter *parent, FnIterOnStore fn, gpointer user_data );
static gboolean iter_on_store_item( NactTreeModel *model, GtkTreeModel *store, GtkTreeIter *iter, FnIterOnStore fn, gpointer user_data );
-/*static gboolean search_for_object( NactTreeModel *model, GtkTreeModel *store, const NAObject *object, GtkTreeIter *iter );
-static gboolean search_for_objet_iter( NactTreeModel *model, GtkTreePath *path, NAObject *object, ntmSearchStruct *ntm );*/
+static gboolean search_for_object( NactTreeModel *model, GtkTreeModel *store, const NAObject *object, GtkTreeIter *iter );
+static gboolean search_for_objet_iter( NactTreeModel *model, GtkTreePath *path, NAObject *object, ntmSearchStruct *ntm );
static gboolean imulti_drag_source_row_draggable( EggTreeMultiDragSource *drag_source, GList *path_list );
static gboolean imulti_drag_source_drag_data_get( EggTreeMultiDragSource *drag_source, GdkDragContext *context, GtkSelectionData *selection_data, GList *path_list, guint info );
@@ -484,6 +485,24 @@ nact_tree_model_dispose( NactTreeModel *model )
gtk_tree_store_clear( ts_model );
}
+/**
+ * nact_tree_model_display:
+ */
+void
+nact_tree_model_display( NactTreeModel *model, NAObject *object )
+{
+ GtkTreeStore *store;
+ GtkTreeIter iter;
+
+ store = GTK_TREE_STORE( gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model )));
+
+ if( search_for_object( model, GTK_TREE_MODEL( store ), object, &iter )){
+ display_item( store, model->private->treeview, &iter, object );
+ }
+
+ gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( model ));
+}
+
void
nact_tree_model_dump( NactTreeModel *model )
{
@@ -677,80 +696,6 @@ nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePat
gtk_tree_model_filter_convert_child_iter_to_iter( GTK_TREE_MODEL_FILTER( model ), iter, &store_iter );
}
-#if 0
-void
-nact_tree_model_insert_item( NactTreeModel *model, const NAObject *object, GtkTreePath *path, const NAObject *selected, GtkTreeIter *iter )
-{
- static const gchar *thisfn = "nact_tree_model_insert_item";
- gchar *path_str;
- GtkTreeModel *store;
- GtkTreeIter sibling;
- GtkTreeIter *parent;
- GtkTreeIter store_iter;
- GtkTreeIter profile_iter;
- GList *profiles;
-
- path_str = path ? gtk_tree_path_to_string( path ) : NULL;
- g_debug( "%s: model=%p, object=%p, path=%p (%s), selected=%p, iter=%p",
- thisfn, ( void * ) model, ( void * ) object, ( void * ) path, path_str, ( void * ) selected, ( void * ) iter );
- g_free( path_str );
-
- g_return_if_fail( NACT_IS_TREE_MODEL( model ));
- g_return_if_fail( NA_IS_OBJECT( object ));
- g_return_if_fail( iter );
-
- store = gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model ));
- parent = NULL;
-
- if( path ){
- g_return_if_fail( selected );
- g_return_if_fail( NA_IS_OBJECT( selected ));
-
- if( NA_IS_OBJECT_ITEM( object )){
- if( !NA_IS_OBJECT_ITEM( selected )){
- gtk_tree_path_up( path );
- }
- gtk_tree_model_get_iter( store, &sibling, path );
- if( NA_IS_OBJECT_MENU( selected )){
- parent = gtk_tree_iter_copy( &sibling );
- na_object_insert_item( selected, object );
- }
- }
-
- if( NA_IS_OBJECT_PROFILE( object )){
- if( NA_IS_OBJECT_ACTION( selected )){
- gtk_tree_path_down( path );
- g_debug( "nact_tree_model_insert_item: object_is_action_profile, selected_is_action" );
- }
- gtk_tree_model_get_iter( store, &sibling, path );
- }
-
- } else {
- g_return_if_fail( NA_IS_OBJECT_ITEM( object ));
- }
-
- gtk_tree_store_insert_before( GTK_TREE_STORE( store ), &store_iter, parent, parent ? NULL : ( path ? &sibling : NULL ));
- gtk_tree_store_set( GTK_TREE_STORE( store ), &store_iter, IACTIONS_LIST_NAOBJECT_COLUMN, object, -1 );
- display_item( GTK_TREE_STORE( store ), model->private->treeview, &store_iter, object );
-
- if( parent ){
- gtk_tree_iter_free( parent );
- }
-
- if( NA_IS_OBJECT_ACTION( object )){
- g_return_if_fail( na_object_get_items_count( object ) == 1 );
- profiles = na_object_get_items( object );
- append_item( GTK_TREE_STORE( store ), model->private->treeview, &store_iter, &profile_iter, NA_OBJECT( profiles->data ));
- na_object_free_items( profiles );
- }
-
- nact_tree_model_update_parent( model, object );
-
- gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( model ));
- gtk_tree_model_filter_convert_child_iter_to_iter( GTK_TREE_MODEL_FILTER( model ), iter, &store_iter );
-}
-#endif
-
void
nact_tree_model_iter( NactTreeModel *model, FnIterOnStore fn, gpointer user_data )
{
@@ -777,23 +722,63 @@ nact_tree_model_iter( NactTreeModel *model, FnIterOnStore fn, gpointer user_data
void
nact_tree_model_remove( NactTreeModel *model, GList *selected )
{
- GList *reversed, *item;
+ GList *reversed, *it;
GtkTreeIter iter;
GtkTreeStore *store;
gchar *path_str;
+ GList *parents = NULL;
reversed = g_list_reverse( selected );
store = GTK_TREE_STORE( gtk_tree_model_filter_get_model( GTK_TREE_MODEL_FILTER( model )));
- for( item = reversed ; item ; item = item->next ){
+ for( it = reversed ; it ; it = it->next ){
- path_str = gtk_tree_path_to_string(( GtkTreePath * ) item->data );
+ path_str = gtk_tree_path_to_string(( GtkTreePath * ) it->data );
g_debug( "nact_tree_model_remove: path=%s", path_str );
g_free( path_str );
- gtk_tree_model_get_iter( GTK_TREE_MODEL( store ), &iter, ( GtkTreePath * ) item->data );
+ gtk_tree_model_get_iter( GTK_TREE_MODEL( store ), &iter, ( GtkTreePath * ) it->data );
+ parents = add_parent( parents, GTK_TREE_MODEL( store ), &iter, ( GtkTreePath * ) it->data );
gtk_tree_store_remove( store, &iter );
}
+
+ for( it = parents ; it ; it = it->next ){
+ na_object_check_edition_status( it->data );
+ }
+}
+
+/*
+ * iter and path are positionned on the row which is going to be deleted
+ * remove the object from the subitems list of parent (if any)
+ * add parent to the list to check its status after remove will be done
+ */
+static GList *
+add_parent( GList *parents, GtkTreeModel *store, GtkTreeIter *obj_iter, GtkTreePath *obj_path )
+{
+ NAObject *object;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ NAObject *parent;
+
+ gtk_tree_model_get( store, obj_iter, IACTIONS_LIST_NAOBJECT_COLUMN, &object, -1 );
+ path = gtk_tree_path_copy( obj_path );
+
+ if( gtk_tree_path_up( path )){
+ gtk_tree_model_get_iter( store, &iter, path );
+ gtk_tree_model_get( store, &iter, IACTIONS_LIST_NAOBJECT_COLUMN, &parent, -1 );
+
+ if( !g_list_find( parents, parent )){
+ parents = g_list_prepend( parents, parent );
+ na_object_remove_item( parent, object );
+ }
+
+ g_object_unref( parent );
+ }
+
+ gtk_tree_path_free( path );
+ g_object_unref( object );
+
+ return( parents );
}
static void
@@ -876,7 +861,7 @@ iter_on_store_item( NactTreeModel *model, GtkTreeModel *store, GtkTreeIter *iter
return( stop );
}
-/*static gboolean
+static gboolean
search_for_object( NactTreeModel *model, GtkTreeModel *store, const NAObject *object, GtkTreeIter *result_iter )
{
gboolean found = FALSE;
@@ -907,10 +892,11 @@ search_for_objet_iter( NactTreeModel *model, GtkTreePath *path, NAObject *object
if( gtk_tree_model_get_iter( ntm->store, ntm->iter, path )){
ntm->found = TRUE;
}
- }*/
+ }
+
/* stop iteration when found */
- /*return( ntm->found );
-}*/
+ return( ntm->found );
+}
/*
* all rows are draggable
diff --git a/src/nact/nact-tree-model.h b/src/nact/nact-tree-model.h
index 8618655..82c8f41 100644
--- a/src/nact/nact-tree-model.h
+++ b/src/nact/nact-tree-model.h
@@ -91,6 +91,7 @@ void nact_tree_model_initial_load( BaseWindow *window, GtkTreeView *treeview
void nact_tree_model_runtime_init( NactTreeModel *model, gboolean have_dnd );
void nact_tree_model_dispose( NactTreeModel *model );
+void nact_tree_model_display( NactTreeModel *model, NAObject *object );
void nact_tree_model_dump( NactTreeModel *model );
void nact_tree_model_fill( NactTreeModel *model, GList *items, gboolean only_actions);
void nact_tree_model_insert( NactTreeModel *model, const NAObject *object, GtkTreePath *path, GtkTreeIter *iter, NAObject **parent );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]