*-----------------------------------------------------------------------------
*/
+static gboolean vflist_dummy_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath,
+ gboolean path_currently_selected, gpointer data)
+{
+ return TRUE;
+}
+
void vflist_sort_set(ViewFileList *vfl, SortType type, gint ascend)
{
+ GtkTreeModel *model;
GtkListStore *store;
GList *work;
+ GtkTreeSelection *selection;
+ GtkTreePath *tpath;
+ GtkTreeIter iter;
+ GList *select_list;
+ FileData *cursor_fd = NULL;
+ gint single_select;
if (vfl->sort_method == type && vfl->sort_ascend == ascend) return;
vfl->list = filelist_sort(vfl->list, vfl->sort_method, vfl->sort_ascend);
+ /* now reorder the treeview, maintaining current selection */
+
+#if 0
+ /* this is simpler, but much slower */
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfl->listview)));
- /* reorder the treeview, maintaining current selection */
work = g_list_last(vfl->list);
while (work)
{
work = work->prev;
}
+#endif
+
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfl->listview));
+
+ gtk_tree_selection_set_select_function(selection, vflist_dummy_select_cb, vfl, NULL);
+
+ select_list = gtk_tree_selection_get_selected_rows(selection, &model);
+ work = select_list;
+ while (work)
+ {
+ FileData *fd;
+
+ tpath = work->data;
+ gtk_tree_model_get_iter(model, &iter, tpath);
+ gtk_tree_model_get(model, &iter, FILE_COLUMN_POINTER, &fd, -1);
+ gtk_tree_path_free(tpath);
+
+ work->data = fd;
+ work = work->next;
+ }
+
+ select_list = filelist_sort(select_list, vfl->sort_method, vfl->sort_ascend);
+
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(vfl->listview), &tpath, NULL);
+ if (tpath)
+ {
+ if (gtk_tree_model_get_iter(model, &iter, tpath))
+ {
+ gtk_tree_model_get(model, &iter, FILE_COLUMN_POINTER, &cursor_fd, -1);
+ }
+ gtk_tree_path_free(tpath);
+ }
+
+ single_select = (select_list && !select_list->next);
+ if (single_select) cursor_fd = select_list->data;
+
+ store = GTK_LIST_STORE(model);
+ gtk_list_store_clear(store);
+
+ work = vfl->list;
+ while (work)
+ {
+ FileData *fd;
+ gchar *size;
+
+ fd = work->data;
+ size = text_from_size(fd->size);
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter, FILE_COLUMN_POINTER, fd,
+ FILE_COLUMN_THUMB, (vfl->thumbs_enabled) ? fd->pixbuf : NULL,
+ FILE_COLUMN_NAME, fd->name,
+ FILE_COLUMN_SIZE, size,
+ FILE_COLUMN_DATE, text_from_time(fd->date),
+ FILE_COLUMN_COLOR, FALSE, -1);
+ g_free(size);
+
+ if (select_list && select_list->data == fd)
+ {
+ select_list = g_list_remove(select_list, fd);
+ gtk_tree_selection_select_iter(selection, &iter);
+ }
+
+ work = work->next;
+ }
+
+ g_list_free(select_list);
+
+ if (cursor_fd &&
+ vflist_find_row(vfl, cursor_fd, &iter) >= 0)
+ {
+ if (single_select)
+ {
+ vflist_move_cursor(vfl, &iter);
+ }
+ else
+ {
+ tree_view_row_make_visible(GTK_TREE_VIEW(vfl->listview), &iter, TRUE);
+ }
+ }
+
+ gtk_tree_selection_set_select_function(selection, vflist_select_cb, vfl, NULL);
}
/*