X-Git-Url: http://geeqie.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fview_file_list.c;h=bee6bfc5e280efcec5e9a75b4fac835a5d204605;hb=63a96f8504a2773d03bd8956c17eb6bb09a706c7;hp=06edf9fb1c6856c9e4d7c054bc9caed93cf3f5f1;hpb=2d51dd3a2bc18199726de6ed43fc024001852826;p=geeqie.git diff --git a/src/view_file_list.c b/src/view_file_list.c index 06edf9fb..bee6bfc5 100644 --- a/src/view_file_list.c +++ b/src/view_file_list.c @@ -1,13 +1,22 @@ /* - * Geeqie - * (C) 2004 John Ellis - * Copyright (C) 2008 - 2012 The Geeqie Team + * Copyright (C) 2004 John Ellis + * Copyright (C) 2008 - 2016 The Geeqie Team * * Author: John Ellis * - * This software is released under the GNU General Public License (GNU GPL). - * Please read the included file COPYING for more information. - * This software comes with no warranty of any kind, use at your own risk! + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "main.h" @@ -136,51 +145,6 @@ static FileData *vflist_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTree return NULL; } -#if 0 -static gint vflist_find_sidecar_list_idx(GList *work, FileData *fd) -{ - gint i = 0; - while (work) - { - FileData *fd_p = work->data; - if (fd == fd_p) return i; - - i++; - - GList *work2 = fd_p->sidecar_files; - while (work2) - { - fd_p = work2->data; - if (fd == fd_p) return i; - - i++; - work2 = work2->next; - } - work = work->next; - } - return -1; -} - -static gint vflist_sidecar_list_count(GList *work) -{ - gint i = 0; - while (work) - { - FileData *fd = work->data; - i++; - - GList *work2 = fd->sidecar_files; - while (work2) - { - i++; - work2 = work2->next; - } - work = work->next; - } - return i; -} -#endif - static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { FileData *fd; @@ -193,9 +157,25 @@ static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *path, Gt return FALSE; } -static void vflist_store_clear(ViewFile *vf) +static void vflist_store_clear(ViewFile *vf, gboolean unlock_files) { GtkTreeModel *store; + GList *files = NULL; + + if (unlock_files && vf->marks_enabled) + { + // unlock locked files in this directory + filelist_read(vf->dir_fd, &files, NULL); + while (files) + { + FileData *fd = files->data; + files = files->next; + file_data_unlock(fd); + file_data_unref(fd); // undo the ref that got added in filelist_read + } + } + + g_list_free(files); store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)); gtk_tree_model_foreach(store, vflist_store_clear_cb, NULL); gtk_tree_store_clear(GTK_TREE_STORE(store)); @@ -223,27 +203,6 @@ static void vflist_move_cursor(ViewFile *vf, GtkTreeIter *iter) gtk_tree_path_free(tpath); } -#if 0 -static gint vflist_column_idx(ViewFile *vf, gint store_idx) -{ - GList *columns, *work; - gint i = 0; - - columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vf->listview)); - work = columns; - while (work) - { - GtkTreeViewColumn *column = work->data; - if (store_idx == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"))) - break; - work = work->next; - i++; - } - - g_list_free(columns); - return i; -} -#endif /* *----------------------------------------------------------------------------- @@ -257,8 +216,6 @@ static void vflist_dnd_get(GtkWidget *widget, GdkDragContext *context, { ViewFile *vf = data; GList *list = NULL; - gchar *uri_text = NULL; - gint total; if (!VFLIST(vf)->click_fd) return; @@ -319,18 +276,12 @@ static void vflist_drag_data_received(GtkWidget *entry_widget, GdkDragContext *c if (fd) { /* Add keywords to file */ - gchar *str = gtk_selection_data_get_text(selection); + gchar *str = (gchar *) gtk_selection_data_get_text(selection); GList *kw_list = string_to_keywords_list(str); - + metadata_append_list(fd, KEYWORD_KEY, kw_list); string_list_free(kw_list); g_free(str); -/* -file notification should handle this automatically - if (vf->layout && vf->layout->bar_info) { - bar_set_fd(vf->layout->bar_info, fd); - } -*/ } } } @@ -369,7 +320,7 @@ GList *vflist_selection_get_one(ViewFile *vf, FileData *fd) /* check if the row is expanded */ GtkTreeModel *store; GtkTreeIter iter; - + store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)); if (vflist_find_row(vf, fd, &iter) >= 0) { @@ -518,7 +469,7 @@ static gboolean vflist_row_rename_cb(TreeEditData *td, const gchar *old, const g file_data_unref(fd); g_free(old_path); } - + g_free(new_path); return FALSE; @@ -577,7 +528,7 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat GtkTreeIter iter; FileData *fd = NULL; GtkTreeViewColumn *column; - + vf->clicked_mark = 0; if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, @@ -597,9 +548,6 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat gtk_tree_model_get_iter(store, &iter, tpath); gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); -#if 0 - gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); -#endif gtk_tree_path_free(tpath); } @@ -643,12 +591,10 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat return (gtk_tree_selection_count_selected_rows(selection) > 1); } -#if 1 if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS) { if (vf->layout) layout_image_full_screen_start(vf->layout); } -#endif return FALSE; } @@ -712,7 +658,6 @@ gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d gtk_tree_selection_unselect_all(selection); gtk_tree_selection_select_iter(selection, &iter); vflist_move_cursor(vf, &iter); -// return TRUE;// FIXME - expand } return FALSE; @@ -822,13 +767,6 @@ static void vflist_collapse_cb(GtkTreeView *tree_view, GtkTreeIter *iter, GtkTre *----------------------------------------------------------------------------- */ -/* -static gboolean vflist_dummy_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, - gboolean path_currently_selected, gpointer data) -{ - return TRUE; -} -*/ static gchar* vflist_get_formatted(ViewFile *vf, const gchar *name, const gchar *sidecars, const gchar *size, const gchar *time, gboolean expanded) { @@ -885,7 +823,7 @@ static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *it const gchar *disabled_grouping; gchar *formatted; gboolean expanded = FALSE; - + if (fd->sidecar_files) /* expanded has no effect on files without sidecars */ { gtk_tree_model_get(GTK_TREE_MODEL(store), iter, FILE_COLUMN_EXPANDED, &expanded, -1); @@ -896,9 +834,9 @@ static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *it disabled_grouping = fd->disable_grouping ? _(" [NO GROUPING]") : ""; name = g_strdup_printf("%s%s%s", link, fd->name, disabled_grouping); size = text_from_size(fd->size); - + formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded); - + gtk_tree_store_set(store, iter, FILE_COLUMN_POINTER, fd, FILE_COLUMN_VERSION, fd->version, FILE_COLUMN_THUMB, fd->thumb_pixbuf, @@ -977,7 +915,7 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr if (match == 0) g_warning("multiple fd for the same path"); } - + } else { @@ -1005,7 +943,7 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr vflist_setup_iter(vf, store, &new, file_data_ref(fd)); vflist_setup_iter_recursive(vf, store, &new, fd->sidecar_files, selected, force); - + if (g_list_find(selected, fd)) { /* renamed files - the same fd appears at different position - select it again*/ @@ -1046,14 +984,14 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr valid = gtk_tree_store_remove(store, &iter); } - + /* move the prepended entries to the correct position */ if (num_prepended) { gint i; gint num_total = num_prepended + num_ordered; gint *new_order = g_malloc(num_total * sizeof(gint)); - + for (i = 0; i < num_total; i++) { if (i < num_ordered) @@ -1128,7 +1066,7 @@ void vflist_thumb_progress_count(GList *list, gint *count, gint *done) work = work->next; if (fd->thumb_pixbuf) (*done)++; - + if (fd->sidecar_files) { vflist_thumb_progress_count(fd->sidecar_files, count, done); @@ -1160,7 +1098,7 @@ FileData *vflist_thumb_next_fd(ViewFile *vf) GtkTreeModel *store; GtkTreeIter iter; gboolean valid = TRUE; - + store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)); gtk_tree_model_get_iter(store, &iter, tpath); gtk_tree_path_free(tpath); @@ -1242,19 +1180,19 @@ gint vflist_index_by_fd(ViewFile *vf, FileData *fd) { FileData *list_fd = work->data; if (list_fd == fd) return p; - + work2 = list_fd->sidecar_files; while (work2) { /* FIXME: return the same index also for sidecars - it is sufficient for next/prev navigation but it should be rewritten + it is sufficient for next/prev navigation but it should be rewritten without using indexes at all */ FileData *sidecar_fd = work2->data; if (sidecar_fd == fd) return p; work2 = work2->next; } - + work = work->next; p++; } @@ -1402,7 +1340,7 @@ GList *vflist_selection_get_list(ViewFile *vf) gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1); list = g_list_prepend(list, file_data_ref(fd)); - + if (!fd->parent && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vf->listview), tpath)) { /* unexpanded - add whole group */ @@ -1494,13 +1432,13 @@ static gboolean tree_model_get_iter_last(GtkTreeModel *store, GtkTreeIter *iter) while (TRUE) { GtkTreeIter next = *iter; - + if (gtk_tree_model_iter_next(store, &next)) *iter = next; else break; } - + return TRUE; } @@ -1526,7 +1464,7 @@ void vflist_select_invert(ViewFile *vf) gtk_tree_selection_unselect_iter(selection, &iter); else gtk_tree_selection_select_iter(selection, &iter); - + valid = tree_model_iter_prev(store, &iter); } } @@ -1561,10 +1499,10 @@ static void vflist_select_closest(ViewFile *vf, FileData *sel_fd) { GList *work; FileData *fd = NULL; - + if (sel_fd->parent) sel_fd = sel_fd->parent; work = vf->list; - + while (work) { gint match; @@ -1572,7 +1510,7 @@ static void vflist_select_closest(ViewFile *vf, FileData *sel_fd) work = work->next; match = filelist_sort_compare_filedata_full(fd, sel_fd, vf->sort_method, vf->sort_ascend); - + if (match >= 0) break; } @@ -1659,7 +1597,7 @@ void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode) case STM_MODE_TOGGLE: file_data_set_mark(fd, n, !file_data_get_mark(fd, n)); break; } - + if (!file_data_filter_marks(fd, vf_marks_get_filter(vf))) /* file no longer matches the filter -> remove it */ { vf_refresh_idle(vf); @@ -1672,7 +1610,7 @@ void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode) vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, NULL, FALSE); } - + file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM); work = work->next; @@ -1736,7 +1674,7 @@ static void vflist_populate_view(ViewFile *vf, gboolean force) if (!vf->list) { - vflist_store_clear(vf); + vflist_store_clear(vf, FALSE); vf_send_update(vf); return; } @@ -1744,7 +1682,7 @@ static void vflist_populate_view(ViewFile *vf, gboolean force) vflist_listview_set_columns(vf->listview, VFLIST(vf)->thumbs_enabled, vflist_is_multiline(vf)); selected = vflist_selection_get_list(vf); - + vflist_setup_iter_recursive(vf, store, NULL, vf->list, selected, force); if (selected && vflist_selection_count(vf, NULL) == 0) @@ -1754,7 +1692,7 @@ static void vflist_populate_view(ViewFile *vf, gboolean force) } filelist_free(selected); - + vf_send_update(vf); vf_thumb_update(vf); } @@ -1773,6 +1711,20 @@ gboolean vflist_refresh(ViewFile *vf) file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification of changes detected by filelist_read */ ret = filelist_read(vf->dir_fd, &vf->list, NULL); + + if (vf->marks_enabled) + { + // When marks are enabled, lock FileDatas so that we don't end up re-parsing XML + // each time a mark is changed. + file_data_lock_list(vf->list); + } + else + { + // FIXME: only do this when needed (aka when we just switched from + // FIXME: marks-enabled to marks-disabled) + file_data_unlock_list(vf->list); + } + vf->list = file_data_filter_marks_list(vf->list, vf_marks_get_filter(vf)); file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM); @@ -1784,6 +1736,8 @@ gboolean vflist_refresh(ViewFile *vf) vflist_populate_view(vf, FALSE); + DEBUG_1("%s vflist_refresh: free filelist", get_exec_time()); + filelist_free(old_list); DEBUG_1("%s vflist_refresh: done", get_exec_time()); @@ -1898,7 +1852,7 @@ static void vflist_listview_mark_toggled_cb(GtkCellRendererToggle *cell, gchar * gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, col_idx, &marked, -1); marked = !marked; - + /* the change has a very limited range and the standard notification would trigger complete re-read of the directory - try to do only minimal update instead */ file_data_unregister_notify_func(vf_notify_cb, vf); @@ -1923,10 +1877,6 @@ static void vflist_listview_add_column_toggle(ViewFile *vf, gint n, const gchar { GtkTreeViewColumn *column; GtkCellRenderer *renderer; - GtkTreeStore *store; - gint index; - - store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview))); renderer = gtk_cell_renderer_toggle_new(); column = gtk_tree_view_column_new_with_attributes(title, renderer, "active", n, NULL); @@ -1935,7 +1885,7 @@ static void vflist_listview_add_column_toggle(ViewFile *vf, gint n, const gchar g_object_set_data(G_OBJECT(column), "column_store_idx", GUINT_TO_POINTER(n)); g_object_set_data(G_OBJECT(renderer), "column_store_idx", GUINT_TO_POINTER(n)); - index = gtk_tree_view_append_column(GTK_TREE_VIEW(vf->listview), column); + gtk_tree_view_append_column(GTK_TREE_VIEW(vf->listview), column); gtk_tree_view_column_set_fixed_width(column, 22); gtk_tree_view_column_set_visible(column, vf->marks_enabled); @@ -1959,7 +1909,7 @@ gboolean vflist_set_fd(ViewFile *vf, FileData *dir_fd) vf->dir_fd = file_data_ref(dir_fd); /* force complete reload */ - vflist_store_clear(vf); + vflist_store_clear(vf, TRUE); filelist_free(vf->list); vf->list = NULL; @@ -1991,7 +1941,7 @@ ViewFile *vflist_new(ViewFile *vf, FileData *dir_fd) gint column; vf->info = g_new0(ViewFileInfoList, 1); - + flist_types[FILE_COLUMN_POINTER] = G_TYPE_POINTER; flist_types[FILE_COLUMN_VERSION] = G_TYPE_INT; flist_types[FILE_COLUMN_THUMB] = GDK_TYPE_PIXBUF; @@ -2035,7 +1985,7 @@ ViewFile *vflist_new(ViewFile *vf, FileData *dir_fd) vflist_listview_add_column(vf, FILE_COLUMN_THUMB, "", TRUE, FALSE, FALSE); g_assert(column == FILE_VIEW_COLUMN_THUMB); column++; - + vflist_listview_add_column(vf, FILE_COLUMN_FORMATTED, _("Name"), FALSE, FALSE, TRUE); g_assert(column == FILE_VIEW_COLUMN_FORMATTED); column++; @@ -2057,12 +2007,12 @@ void vflist_thumb_set(ViewFile *vf, gboolean enable) if (VFLIST(vf)->thumbs_enabled == enable) return; VFLIST(vf)->thumbs_enabled = enable; - + /* vflist_populate_view is better than vf_refresh: - no need to re-read the directory - force update because the formatted string has changed */ - if (vf->layout) + if (vf->layout) { vflist_populate_view(vf, TRUE); gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview)); @@ -2086,8 +2036,17 @@ void vflist_marks_set(ViewFile *vf, gboolean enable) gtk_tree_view_column_set_visible(column, enable); } + if (enable) + { + // Previously disabled, which means that vf->list is complete + file_data_lock_list(vf->list); + } + else + { + // Previously enabled, which means that vf->list is incomplete + } + g_list_free(columns); - //vf_refresh(vf); } /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */