[nautilus-actions] nact_iactions_list_delete_selection no more returns a selectable path



commit b17efe34aad9084da8350460ce5523dfaea7367d
Author: Pierre Wieser <pwieser trychlos org>
Date:   Sun Sep 20 12:39:46 2009 +0200

    nact_iactions_list_delete_selection no more returns a selectable path

 ChangeLog                     |   18 +++++++++++++++
 TODO                          |    5 ++++
 src/common/na-object-item.c   |    7 ++++++
 src/nact/nact-clipboard.c     |    6 -----
 src/nact/nact-iactions-list.c |   35 ++++++++++++++---------------
 src/nact/nact-iactions-list.h |    4 +-
 src/nact/nact-main-menubar.c  |   47 ++++++++++++++++++++++++++++++----------
 src/nact/nact-tree-model.c    |    3 +-
 8 files changed, 86 insertions(+), 39 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c818959..60ec74e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-09-20 Pierre Wieser <pwieser trychlos org>
+
+	* src/common/na-object-item.c (object_id_new_id):
+	Function becomes recursive.
+
+	* src/nact/nact-clipboard.c (renumber_items):
+	Removes recursivity as it is provided by the class.
+
+	* src/nact/nact-iactions-list.c:
+	* src/nact/nact-iactions-list.h (nact_iactions_list_delete_selection):
+	No more returns the path to be selected as this can be directly taken
+	into account by the function itself.
+	Check depth of path before trying gtk_tree_path_up.
+
+	* src/nact/nact-main-menubar.c:
+	Reorganize code to avoid the need of delete_selection returning
+	a path to be selected.
+
 2009-09-19 Pierre Wieser <pwieser trychlos org>
 
 	* src/common/na-gconf-provider.c:
diff --git a/TODO b/TODO
index e1a401f..fc37ca8 100644
--- a/TODO
+++ b/TODO
@@ -45,3 +45,8 @@
   (see the 26 exported actions, and the screenshot of Nautilus view)
 
 - open a bug against gnome-packagekit: keep the last window size and position
+
+- gtk_tree_path_up returns TRUE even if there is no parent
+  cf. commit 5ee6938486cd82f1274969506873df950348dd61 and before
+  function nact-tree-model.c::add_parent
+  recreate a small code which reproduces this bug and open in bugzilla
diff --git a/src/common/na-object-item.c b/src/common/na-object-item.c
index c7d89d0..cf26197 100644
--- a/src/common/na-object-item.c
+++ b/src/common/na-object-item.c
@@ -914,6 +914,7 @@ object_get_childs( const NAObject *object )
 static gchar *
 object_id_new_id( const NAObjectId *item )
 {
+	GList *it;
 	uuid_t uuid;
 	gchar uuid_str[64];
 	gchar *new_uuid;
@@ -921,6 +922,12 @@ object_id_new_id( const NAObjectId *item )
 	g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NULL );
 	g_return_val_if_fail( !NA_OBJECT_ITEM( item )->private->dispose_has_run, NULL );
 
+	for( it = NA_OBJECT_ITEM( item )->private->items ; it ; it = it->next ){
+		if( NA_IS_OBJECT_ITEM( it->data )){
+			na_object_set_new_id( it->data );
+		}
+	}
+
 	uuid_generate( uuid );
 	uuid_unparse_lower( uuid, uuid_str );
 	new_uuid = g_strdup( uuid_str );
diff --git a/src/nact/nact-clipboard.c b/src/nact/nact-clipboard.c
index e0370bc..08c8bed 100644
--- a/src/nact/nact-clipboard.c
+++ b/src/nact/nact-clipboard.c
@@ -435,16 +435,10 @@ static void
 renumber_items( GList *items )
 {
 	GList *it;
-	GList *subitems;
 
 	for( it = items ; it ; it = it->next ){
-
 		if( NA_IS_OBJECT_ITEM( it->data )){
 			na_object_set_new_id( NA_OBJECT_ITEM( it->data ));
-
-			subitems = na_object_get_items( it->data );
-			renumber_items( subitems );
-			na_object_free_items( subitems );
 		}
 	}
 }
diff --git a/src/nact/nact-iactions-list.c b/src/nact/nact-iactions-list.c
index dac3505..50922d8 100644
--- a/src/nact/nact-iactions-list.c
+++ b/src/nact/nact-iactions-list.c
@@ -428,25 +428,20 @@ nact_iactions_list_dispose( NactIActionsList *instance )
 /**
  * nact_iactions_list_delete_selection:
  * @window: this #NactIActionsList instance.
- * @path: a #GtkTreePath allocated here to point to the new row to select.
  *
  * Deletes the current selection from the underlying tree store.
  *
- * 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().
+ * This function takes care of repositionning a new selection if
+ * possible, and refilter the display model.
  */
 void
-nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **path )
+nact_iactions_list_delete_selection( NactIActionsList *instance )
 {
 	GtkTreeView *treeview;
 	GtkTreeModel *model;
 	GtkTreeSelection *selection;
 	GList *selected;
+	GtkTreePath *path = NULL;
 
 	g_return_if_fail( NACT_IS_IACTIONS_LIST( instance ));
 
@@ -457,7 +452,7 @@ nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **p
 	set_selection_changed_mode( instance, FALSE );
 
 	if( g_list_length( selected )){
-		*path = gtk_tree_path_copy(( GtkTreePath * ) selected->data );
+		path = gtk_tree_path_copy(( GtkTreePath * ) selected->data );
 		nact_tree_model_remove( NACT_TREE_MODEL( model ), selected );
 	}
 
@@ -466,7 +461,10 @@ 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 ));
+	if( path ){
+		nact_iactions_list_select_row( instance, path );
+		gtk_tree_model_filter_refilter( GTK_TREE_MODEL_FILTER( model ));
+	}
 }
 
 /**
@@ -619,6 +617,8 @@ nact_iactions_list_has_modified_items( NactIActionsList *instance )
  * nact_iactions_list_insert_items:
  * @instance: this #NactIActionsList instance.
  * @items: a list of items to be inserted (e.g. from a paste).
+ * @sibling: the #NAObject besides which the insertion should occurs ;
+ * this may prevent e.g. to go inside a menu.
  *
  * Inserts the provided @items list in the treeview.
  *
@@ -635,7 +635,7 @@ nact_iactions_list_has_modified_items( NactIActionsList *instance )
  * possible, and refilter the display model.
  */
 void
-nact_iactions_list_insert_items( NactIActionsList *instance, GList *items )
+nact_iactions_list_insert_items( NactIActionsList *instance, GList *items, NAObject *sibling )
 {
 	static const gchar *thisfn = "nact_iactions_list_insert_items";
 	GtkTreeView *treeview;
@@ -825,24 +825,23 @@ nact_iactions_list_select_row( NactIActionsList *instance, GtkTreePath *path )
 	gtk_tree_selection_unselect_all( selection );
 
 	model = gtk_tree_view_get_model( treeview );
+	g_debug( "nact_iactions_list_select_row: path=%s", gtk_tree_path_to_string( path ));
 
 	if( gtk_tree_model_get_iter( model, &iter, path )){
-		/*gtk_tree_selection_select_iter( selection, &iter );*/
 		select_row( treeview, model, &iter );
 
 	} else {
 		gtk_tree_path_next( path );
 		if( gtk_tree_model_get_iter( model, &iter, path )){
-			/*gtk_tree_selection_select_iter( selection, &iter );*/
 			select_row( treeview, model, &iter );
 
 		} else if( gtk_tree_path_prev( path ) && gtk_tree_model_get_iter( model, &iter, path )){
-			/*gtk_tree_selection_select_iter( selection, &iter );*/
 			select_row( treeview, model, &iter );
 
-		} else if( gtk_tree_path_up( path ) && gtk_tree_model_get_iter( model, &iter, path )){
-			/*gtk_tree_selection_select_iter( selection, &iter );*/
-			select_row( treeview, model, &iter );
+		} else if( gtk_tree_path_get_depth( path ) > 1 &&
+					gtk_tree_path_up( path ) &&
+					gtk_tree_model_get_iter( model, &iter, path )){
+						select_row( treeview, model, &iter );
 		}
 	}
 
diff --git a/src/nact/nact-iactions-list.h b/src/nact/nact-iactions-list.h
index a909b32..a3957eb 100644
--- a/src/nact/nact-iactions-list.h
+++ b/src/nact/nact-iactions-list.h
@@ -76,13 +76,13 @@ void      nact_iactions_list_runtime_init_toplevel( NactIActionsList *instance,
 void      nact_iactions_list_all_widgets_showed( NactIActionsList *instance );
 void      nact_iactions_list_dispose( NactIActionsList *instance );
 
-void      nact_iactions_list_delete_selection( NactIActionsList *instance, GtkTreePath **path );
+void      nact_iactions_list_delete_selection( NactIActionsList *instance );
 void      nact_iactions_list_fill( NactIActionsList *instance, GList *items );
 GList    *nact_iactions_list_get_items( NactIActionsList *instance );
 GList    *nact_iactions_list_get_selected_items( NactIActionsList *instance );
 gboolean  nact_iactions_list_has_exportable( NactIActionsList *instance );
 gboolean  nact_iactions_list_has_modified_items( NactIActionsList *instance );
-void      nact_iactions_list_insert_items( NactIActionsList *instance, GList *items );
+void      nact_iactions_list_insert_items( NactIActionsList *instance, GList *items, NAObject *sibling );
 gboolean  nact_iactions_list_is_expanded( NactIActionsList *instance, const NAObject *item );
 gboolean  nact_iactions_list_is_only_actions_mode( NactIActionsList *instance );
 void      nact_iactions_list_select_row( NactIActionsList *instance, GtkTreePath *path );
diff --git a/src/nact/nact-main-menubar.c b/src/nact/nact-main-menubar.c
index 284dfb1..7908e58 100644
--- a/src/nact/nact-main-menubar.c
+++ b/src/nact/nact-main-menubar.c
@@ -281,7 +281,7 @@ on_new_menu_activated( GtkAction *gtk_action, NactMainWindow *window )
 
 	menu = na_object_menu_new();
 	items = g_list_prepend( items, menu );
-	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
+	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 	na_object_free_items( items );
 }
 
@@ -296,7 +296,7 @@ on_new_action_activated( GtkAction *gtk_action, NactMainWindow *window )
 
 	action = na_object_action_new_with_profile();
 	items = g_list_prepend( items, action );
-	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
+	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 	na_object_free_items( items );
 }
 
@@ -324,7 +324,7 @@ on_new_profile_activated( GtkAction *gtk_action, NactMainWindow *window )
 	na_object_set_id( profile, name );
 
 	items = g_list_prepend( items, profile );
-	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
+	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 
 	na_object_free_items( items );
 	g_free( name );
@@ -442,16 +442,14 @@ static void
 on_cut_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	GList *items;
-	GtkTreePath *path;
 
 	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 
 	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
-	nact_iactions_list_delete_selection( NACT_IACTIONS_LIST( window ), &path );
 	nact_main_window_move_to_deleted( window, items );
 	nact_clipboard_primary_set( items, FALSE );
-	nact_iactions_list_select_row( NACT_IACTIONS_LIST( window ), path );
+	nact_iactions_list_delete_selection( NACT_IACTIONS_LIST( window ));
 
 	/* do not unref selected items as the ref has been moved to main_deleted
 	 */
@@ -481,7 +479,7 @@ on_copy_activated( GtkAction *gtk_action, NactMainWindow *window )
 }
 
 /*
- * pastes the current coontent of the clipboard
+ * pastes the current content of the clipboard
  * - (menu) get from clipboard a copy of installed items
  *          the clipboard will return a new copy
  *          and renumber its own data for allowing a new paste
@@ -497,14 +495,41 @@ on_paste_activated( GtkAction *gtk_action, NactMainWindow *window )
 	GList *items;
 
 	items = nact_clipboard_primary_get();
-	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items );
+	nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), items, NULL );
 	na_object_free_items( items );
 }
 
+/*
+ * duplicate is just as paste, with the difference that content comes
+ * from the current selection, instead of coming from the clipboard
+ *
+ * this is nonetheless a bit more complicated because when we duplicate
+ * some items (e.g. a multiple selection), we expect to see the new
+ * items just besides the original ones...
+ */
 static void
 on_duplicate_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
-	g_signal_emit_by_name( window, IACTIONS_LIST_SIGNAL_ITEM_UPDATED, NULL );
+	GList *items, *it;
+	GList *dup;
+	NAObject *obj;
+
+	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
+	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
+
+	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
+	for( it = items ; it ; it = it->next ){
+		obj = NA_OBJECT( na_object_duplicate( it->data ));
+		if( NA_IS_OBJECT_ITEM( obj )){
+			na_object_set_new_id( obj );
+		}
+		na_object_set_origin_rec( obj, NULL );
+		dup = g_list_prepend( NULL, obj );
+		nact_iactions_list_insert_items( NACT_IACTIONS_LIST( window ), dup, it->data );
+		na_object_free_items( dup );
+	}
+
+	na_object_free_items( items );
 }
 
 /*
@@ -519,15 +544,13 @@ static void
 on_delete_activated( GtkAction *gtk_action, NactMainWindow *window )
 {
 	GList *items;
-	GtkTreePath *path;
 
 	g_return_if_fail( GTK_IS_ACTION( gtk_action ));
 	g_return_if_fail( NACT_IS_MAIN_WINDOW( window ));
 
 	items = nact_iactions_list_get_selected_items( NACT_IACTIONS_LIST( window ));
-	nact_iactions_list_delete_selection( NACT_IACTIONS_LIST( window ), &path );
 	nact_main_window_move_to_deleted( window, items );
-	nact_iactions_list_select_row( NACT_IACTIONS_LIST( window ), path );
+	nact_iactions_list_delete_selection( NACT_IACTIONS_LIST( window ));
 
 	/* do not unref selected items as the ref has been moved to main_deleted
 	 */
diff --git a/src/nact/nact-tree-model.c b/src/nact/nact-tree-model.c
index 0628f72..e0c47ca 100644
--- a/src/nact/nact-tree-model.c
+++ b/src/nact/nact-tree-model.c
@@ -763,7 +763,8 @@ add_parent( GList *parents, GtkTreeModel *store, GtkTreeIter *obj_iter, GtkTreeP
 	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 )){
+	if( gtk_tree_path_get_depth( path ) > 1 ){
+		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 );
 



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