# HG changeset patch # User nadvornik # Date 1212183706 0 # Node ID 24726eddb2524e28bacd3d65a00ce24667537641 # Parent 842c15317bdf2ed11df9f93ab571e175081fcc2a vflist_populate_view: better handle selected files that are renamed or deleted diff -r 842c15317bdf -r 24726eddb252 src/view_file_list.c --- a/src/view_file_list.c Fri May 30 20:13:16 2008 +0000 +++ b/src/view_file_list.c Fri May 30 21:41:46 2008 +0000 @@ -706,7 +706,6 @@ } */ - static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd) { int i; @@ -733,7 +732,7 @@ g_free(sidecars); } -static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *parent_iter, GList *list, GList *selection) +static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *parent_iter, GList *list, GList *selected) { GList *work; GtkTreeIter iter; @@ -794,7 +793,15 @@ } vflist_setup_iter(vf, store, &new, fd); - vflist_setup_iter_recursive(vf, store, &new, fd->sidecar_files, selection); + vflist_setup_iter_recursive(vf, store, &new, fd->sidecar_files, selected); + + if (g_list_find(selected, fd)) + { + /* renamed files - the same fd appears at different position - select it again*/ + GtkTreeSelection *selection; + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview)); + gtk_tree_selection_select_iter(selection, &new); + } done = TRUE; } @@ -807,7 +814,7 @@ if (fd->version != old_version) { vflist_setup_iter(vf, store, &iter, fd); - vflist_setup_iter_recursive(vf, store, &iter, fd->sidecar_files, selection); + vflist_setup_iter_recursive(vf, store, &iter, fd->sidecar_files, selected); } if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); @@ -1352,6 +1359,31 @@ } } +static void vflist_select_closest(ViewFile *vf, FileData *sel_fd) +{ + GList *work; + + if (sel_fd->parent) sel_fd = sel_fd->parent; + work = vf->list; + + while (work) + { + gint match; + FileData *fd = work->data; + work = work->next; + + + match = filelist_sort_compare_filedata_full(fd, sel_fd, vf->sort_method, vf->sort_ascend); + + if (match >= 0) + { + vflist_select_by_fd(vf, fd); + break; + } + } + +} + void vflist_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode) { GtkTreeModel *store; @@ -1470,6 +1502,7 @@ gint thumbs; GtkTreeRowReference *visible_row = NULL; GtkTreePath *tpath; + GList *selected; store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview))); thumbs = VFLIST_INFO(vf, thumbs_enabled); @@ -1492,7 +1525,17 @@ vflist_listview_set_height(vf->listview, thumbs); - vflist_setup_iter_recursive(vf, store, NULL, vf->list, NULL); + selected = vflist_selection_get_list(vf); + + vflist_setup_iter_recursive(vf, store, NULL, vf->list, selected); + + if (selected && vflist_selection_count(vf, NULL) == 0) + { + /* all selected files disappeared */ + vflist_select_closest(vf, selected->data); + } + + filelist_free(selected); if (visible_row) {