[nautilus-actions] Fix item deletion when not yet written to a backend
- From: Pierre Wieser <pwieser src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-actions] Fix item deletion when not yet written to a backend
- Date: Fri, 9 Dec 2011 18:24:03 +0000 (UTC)
commit d378fa6150536e1e7650b239d27cff552fef6623
Author: Pierre Wieser <pwieser trychlos org>
Date: Fri Dec 9 19:23:39 2011 +0100
Fix item deletion when not yet written to a backend
ChangeLog | 11 +++++
src/core/na-updater.c | 20 ++++++---
src/nact/nact-menubar-file.c | 6 ++-
src/nact/nact-tree-ieditable.c | 87 ++++++++++++++++++++++++++++++++--------
4 files changed, 98 insertions(+), 26 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 174f530..21b3110 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2011-12-09 Pierre Wieser <pwieser trychlos org>
+ * src/core/na-updater.c (na_updater_delete_item):
+ Do not try to remove from the backend an item which has never been written.
+
+ * src/nact/nact-menubar-file.c:
+ Fix typo in translatable message.
+ (nact_menubar_file_save_items): Reinitialize messages pointer.
+
+ * src/nact/nact-tree-ieditable.c (add_to_deleted_rec):
+ Only count as deleted items which were read from the backend.
+ Compute level zero status.
+
* src/core/na-importer-ask.c (na_importer_ask_user):
* src/core/na-settings.h:
Change import default mode and export default format to 'Ask'.
diff --git a/src/core/na-updater.c b/src/core/na-updater.c
index 15eee05..cada661 100644
--- a/src/core/na-updater.c
+++ b/src/core/na-updater.c
@@ -593,19 +593,25 @@ guint
na_updater_delete_item( const NAUpdater *updater, const NAObjectItem *item, GSList **messages )
{
guint ret;
+ NAIOProvider *provider;
- ret = NA_IIO_PROVIDER_CODE_PROGRAM_ERROR;
+ g_return_val_if_fail( NA_IS_UPDATER( updater ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+ g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+ g_return_val_if_fail( messages, NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
- g_return_val_if_fail( NA_IS_UPDATER( updater ), ret );
- g_return_val_if_fail( NA_IS_OBJECT_ITEM( item ), ret );
- g_return_val_if_fail( messages, ret );
+ ret = NA_IIO_PROVIDER_CODE_OK;
if( !updater->private->dispose_has_run ){
- NAIOProvider *provider = na_object_get_provider( item );
- g_return_val_if_fail( provider, ret );
+ provider = na_object_get_provider( item );
- ret = na_io_provider_delete_item( provider, item, messages );
+ /* provider may be NULL if the item has been deleted from the UI
+ * without having been ever saved
+ */
+ if( provider ){
+ g_return_val_if_fail( NA_IS_IO_PROVIDER( provider ), NA_IIO_PROVIDER_CODE_PROGRAM_ERROR );
+ ret = na_io_provider_delete_item( provider, item, messages );
+ }
}
return( ret );
diff --git a/src/nact/nact-menubar-file.c b/src/nact/nact-menubar-file.c
index 007a44c..cc07aea 100644
--- a/src/nact/nact-menubar-file.c
+++ b/src/nact/nact-menubar-file.c
@@ -53,7 +53,7 @@ static guint st_event_autosave = 0;
static gchar *st_save_error = N_( "Save error" );
static gchar *st_save_warning = N_( "Some items may not have been saved" );
static gchar *st_level_zero_write = N_( "Unable to rewrite the level-zero items list" );
-static gchar *st_delete_error = N_( "Some items have not be deleted" );
+static gchar *st_delete_error = N_( "Some items have not been deleted" );
static gboolean save_item( BaseWindow *window, NAUpdater *updater, NAObjectItem *item, GSList **messages );
static void install_autosave( NactMenubar *bar );
@@ -296,6 +296,7 @@ nact_menubar_file_save_items( BaseWindow *window )
base_window_display_error_dlg( window, gettext( st_save_error ), msg );
g_free( msg );
na_core_utils_slist_free( messages );
+ messages = NULL;
}
} else {
@@ -315,6 +316,7 @@ nact_menubar_file_save_items( BaseWindow *window )
base_window_display_error_dlg( window, gettext( st_save_error ), msg );
g_free( msg );
na_core_utils_slist_free( messages );
+ messages = NULL;
} else {
na_object_free_items( items );
@@ -327,7 +329,6 @@ nact_menubar_file_save_items( BaseWindow *window )
* recursively each and every modified item
*/
new_pivot = NULL;
- messages = NULL;
for( it = items ; it ; it = it->next ){
save_item( window, bar->private->updater, NA_OBJECT_ITEM( it->data ), &messages );
@@ -342,6 +343,7 @@ nact_menubar_file_save_items( BaseWindow *window )
base_window_display_error_dlg( window, gettext( st_save_warning ), msg );
g_free( msg );
na_core_utils_slist_free( messages );
+ messages = NULL;
}
na_pivot_set_new_items( NA_PIVOT( bar->private->updater ), g_list_reverse( new_pivot ));
diff --git a/src/nact/nact-tree-ieditable.c b/src/nact/nact-tree-ieditable.c
index 2a06b0c..cea76f4 100644
--- a/src/nact/nact-tree-ieditable.c
+++ b/src/nact/nact-tree-ieditable.c
@@ -32,6 +32,7 @@
#include <config.h>
#endif
+#include <api/na-core-utils.h>
#include <api/na-object-api.h>
#include <core/na-updater.h>
@@ -60,6 +61,7 @@ typedef struct {
guint count_modified;
gboolean level_zero_changed;
GList *deleted;
+ guint count_deleted;
}
IEditableData;
@@ -84,6 +86,8 @@ static void decrement_counters( NactTreeIEditable *view, IEditableData
static GtkTreePath *do_insert_before( IEditableData *ied, GList *items, GtkTreePath *insert_path );
static GtkTreePath *do_insert_into( IEditableData *ied, GList *items, GtkTreePath *insert_path );
static void increment_counters( NactTreeIEditable *view, IEditableData *ied, GList *items );
+static void check_level_zero_status( NactTreeIEditable *instance );
+static gchar *get_items_id_list_str( GList *items_list );
static GtkTreePath *get_selection_first_path( GtkTreeView *treeview );
static gboolean get_modification_status( IEditableData *ied );
static IEditableData *get_instance_data( NactTreeIEditable *view );
@@ -455,7 +459,7 @@ nact_tree_ieditable_delete( NactTreeIEditable *instance, GList *items, TreeIEdit
if( parent ){
na_object_check_status( parent );
} else {
- g_signal_emit_by_name( ied->window, TREE_SIGNAL_LEVEL_ZERO_CHANGED, TRUE );
+ check_level_zero_status( instance );
}
/* record the deleted item in the 'deleted' list,
@@ -496,6 +500,9 @@ nact_tree_ieditable_delete( NactTreeIEditable *instance, GList *items, TreeIEdit
* Recursively adds to the 'deleted' list the NAObjectItem object currently being deleted.
*
* Increments the 'modified' count with the deleted items which were not modified.
+ *
+ * Only increments the 'deleted' count for items we may have to actually remove
+ * from the backend, i.e. those who have a non-null provider.
*/
static void
add_to_deleted_rec( IEditableData *ied, NAObject *object )
@@ -510,6 +517,10 @@ add_to_deleted_rec( IEditableData *ied, NAObject *object )
if( na_object_is_modified( object )){
ied->count_modified -= 1;
}
+
+ if( na_object_get_provider( object )){
+ ied->count_deleted += 1;
+ }
}
if( NA_IS_OBJECT_MENU( object )){
@@ -564,7 +575,6 @@ nact_tree_ieditable_remove_deleted( NactTreeIEditable *instance, GSList **messag
GList *it;
NAObjectItem *item;
GList *not_deleted;
- guint delete_ret;
g_return_val_if_fail( NACT_IS_TREE_IEDITABLE( instance ), TRUE );
@@ -580,20 +590,9 @@ nact_tree_ieditable_remove_deleted( NactTreeIEditable *instance, GSList **messag
g_debug( "%s: item=%p (%s)", thisfn, ( void * ) item, G_OBJECT_TYPE_NAME( item ));
na_object_dump_norec( item );
- delete_ret = na_updater_delete_item( ied->updater, item, messages );
- delete_ok = ( delete_ret == NA_IIO_PROVIDER_CODE_OK );
-
- if( !delete_ok ){
+ if( na_updater_delete_item( ied->updater, item, messages ) != NA_IIO_PROVIDER_CODE_OK ){
not_deleted = g_list_prepend( not_deleted, na_object_ref( item ));
-
-#if 0
- } else {
- origin = ( NAObject * ) na_object_get_origin( item );
- if( origin ){
- na_updater_remove_item( updater, origin );
- g_object_unref( origin );
- }
-#endif
+ delete_ok = FALSE;
}
}
@@ -978,6 +977,54 @@ nact_tree_ieditable_is_level_zero_modified( const NactTreeIEditable *instance )
return( is_modified );
}
+static void
+check_level_zero_status( NactTreeIEditable *instance )
+{
+ static const gchar *thisfn = "nact_tree_ieditable_check_level_zero_status";
+ gboolean status;
+ IEditableData *ied;
+ GList *items;
+ gchar *pivot_str, *view_str;
+
+ ied = get_instance_data( instance );
+ items = na_pivot_get_items( NA_PIVOT( ied->updater ));
+ pivot_str = get_items_id_list_str( items );
+
+ items = nact_tree_view_get_items( NACT_TREE_VIEW( instance ));
+ view_str = get_items_id_list_str( items );
+ na_object_free_items( items );
+
+ status = ( g_utf8_collate( pivot_str, view_str ) != 0 );
+ g_debug( "%s: pivot_str='%s', view_str='%s', status=%s", thisfn, pivot_str, view_str, status ? "True":"False" );
+
+ g_free( pivot_str );
+ g_free( view_str );
+
+ g_signal_emit_by_name( ied->window, TREE_SIGNAL_LEVEL_ZERO_CHANGED, status );
+}
+
+static gchar *
+get_items_id_list_str( GList *items_list )
+{
+ GList *it;
+ gchar *id;
+ GSList *slist;
+ gchar *list_str;
+
+ slist = NULL;
+
+ for( it = items_list ; it ; it = it->next ){
+ id = na_object_get_id( it->data );
+ slist = g_slist_prepend( slist, id );
+ }
+
+ slist = g_slist_reverse( slist );
+ list_str = na_core_utils_slist_join_at_end( slist, ";" );
+ na_core_utils_slist_free( slist );
+
+ return( list_str );
+}
+
static GtkTreePath *
get_selection_first_path( GtkTreeView *treeview )
{
@@ -1005,10 +1052,16 @@ get_selection_first_path( GtkTreeView *treeview )
static gboolean
get_modification_status( IEditableData *ied )
{
+ static const gchar *thisfn = "nact_tree_ieditable_get_modification_status";
gboolean modified;
- modified = ( ied->count_modified > 0 ) ||
- ( g_list_length( ied->deleted ) > 0 ) || ( ied->level_zero_changed );
+ modified = ( ied->count_modified > 0 ||
+ ied->count_deleted > 0 ||
+ ied->level_zero_changed );
+
+ g_debug( "%s: count_modified=%d, deleted=%d, level_zero_changed=%s, modified=%s",
+ thisfn, ied->count_modified, ied->count_deleted,
+ ied->level_zero_changed ? "True":"False", modified ? "True":"False" );
return( modified );
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]