Mercurial > geeqie.yaz
annotate src/view_dir_list.c @ 1321:50b325a2386e
fixed filter initialization
author | nadvornik |
---|---|
date | Wed, 25 Feb 2009 18:21:20 +0000 |
parents | 8b89e3ff286b |
children | 249bf204004a |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
281 | 13 #include "main.h" |
9 | 14 #include "view_dir_list.h" |
15 | |
16 #include "dnd.h" | |
17 #include "dupe.h" | |
586 | 18 #include "filedata.h" |
9 | 19 #include "layout.h" |
20 #include "layout_image.h" | |
21 #include "layout_util.h" | |
22 #include "utilops.h" | |
23 #include "ui_fileops.h" | |
24 #include "ui_menu.h" | |
25 #include "ui_tree_edit.h" | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
373
diff
changeset
|
26 #include "view_dir.h" |
9 | 27 |
28 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
29 | |
30 | |
979 | 31 #define VDLIST(_vd_) ((ViewDirInfoList *)(_vd_->info)) |
9 | 32 |
33 | |
34 /* | |
35 *----------------------------------------------------------------------------- | |
36 * misc | |
37 *----------------------------------------------------------------------------- | |
38 */ | |
39 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
40 gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter) |
9 | 41 { |
42 GtkTreeModel *store; | |
43 gint valid; | |
44 gint row = 0; | |
45 | |
381 | 46 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 47 valid = gtk_tree_model_get_iter_first(store, iter); |
48 while (valid) | |
49 { | |
50 FileData *fd_n; | |
51 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &fd_n, -1); | |
52 if (fd_n == fd) return row; | |
53 | |
54 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
55 row++; | |
56 } | |
57 | |
58 return -1; | |
59 } | |
60 | |
61 | |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
62 FileData *vdlist_row_by_path(ViewDir *vd, const gchar *path, gint *row) |
9 | 63 { |
64 GList *work; | |
65 gint n; | |
66 | |
67 if (!path) | |
68 { | |
69 if (row) *row = -1; | |
70 return NULL; | |
71 } | |
72 | |
73 n = 0; | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
74 work = VDLIST(vd)->list; |
9 | 75 while (work) |
76 { | |
77 FileData *fd = work->data; | |
78 if (strcmp(fd->path, path) == 0) | |
79 { | |
80 if (row) *row = n; | |
81 return fd; | |
82 } | |
83 work = work->next; | |
84 n++; | |
85 } | |
86 | |
87 if (row) *row = -1; | |
88 return NULL; | |
89 } | |
90 | |
91 /* | |
92 *----------------------------------------------------------------------------- | |
93 * dnd | |
94 *----------------------------------------------------------------------------- | |
95 */ | |
96 | |
381 | 97 static void vdlist_scroll_to_row(ViewDir *vd, FileData *fd, gfloat y_align) |
9 | 98 { |
99 GtkTreeIter iter; | |
100 | |
394 | 101 if (GTK_WIDGET_REALIZED(vd->view) && vd_find_row(vd, fd, &iter) >= 0) |
9 | 102 { |
103 GtkTreeModel *store; | |
104 GtkTreePath *tpath; | |
105 | |
381 | 106 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 107 tpath = gtk_tree_model_get_path(store, &iter); |
381 | 108 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vd->view), tpath, NULL, TRUE, y_align, 0.0); |
109 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE); | |
9 | 110 gtk_tree_path_free(tpath); |
111 | |
381 | 112 if (!GTK_WIDGET_HAS_FOCUS(vd->view)) gtk_widget_grab_focus(vd->view); |
9 | 113 } |
114 } | |
115 | |
116 /* | |
117 *----------------------------------------------------------------------------- | |
118 * main | |
119 *----------------------------------------------------------------------------- | |
442 | 120 */ |
9 | 121 |
396 | 122 void vdlist_select_row(ViewDir *vd, FileData *fd) |
9 | 123 { |
381 | 124 if (fd && vd->select_func) |
9 | 125 { |
126 gchar *path; | |
127 | |
128 path = g_strdup(fd->path); | |
381 | 129 vd->select_func(vd, path, vd->select_data); |
9 | 130 g_free(path); |
131 } | |
132 } | |
133 | |
381 | 134 const gchar *vdlist_row_get_path(ViewDir *vd, gint row) |
9 | 135 { |
136 FileData *fd; | |
137 | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
138 fd = g_list_nth_data(VDLIST(vd)->list, row); |
9 | 139 |
140 if (fd) return fd->path; | |
141 | |
142 return NULL; | |
143 } | |
144 | |
973 | 145 static gint vdlist_populate(ViewDir *vd, gboolean clear) |
9 | 146 { |
147 GtkListStore *store; | |
148 GList *work; | |
973 | 149 GtkTreeIter iter; |
150 gint valid; | |
151 gchar *filepath; | |
152 GList *old_list; | |
153 gint ret; | |
154 FileData *fd; | |
155 | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
156 old_list = VDLIST(vd)->list; |
973 | 157 |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
158 ret = filelist_read(vd->dir_fd, NULL, &VDLIST(vd)->list); |
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
159 VDLIST(vd)->list = filelist_sort(VDLIST(vd)->list, SORT_NAME, TRUE); |
973 | 160 |
161 /* add . and .. */ | |
162 | |
163 if (strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) != 0) | |
164 { | |
165 filepath = g_build_filename(vd->dir_fd->path, "..", NULL); | |
166 fd = file_data_new_simple(filepath); | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
167 VDLIST(vd)->list = g_list_prepend(VDLIST(vd)->list, fd); |
973 | 168 g_free(filepath); |
169 } | |
170 | |
171 if (options->file_filter.show_dot_directory) | |
172 { | |
173 filepath = g_build_filename(vd->dir_fd->path, ".", NULL); | |
174 fd = file_data_new_simple(filepath); | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
175 VDLIST(vd)->list = g_list_prepend(VDLIST(vd)->list, fd); |
973 | 176 g_free(filepath); |
177 } | |
9 | 178 |
381 | 179 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view))); |
973 | 180 if (clear) gtk_list_store_clear(store); |
181 | |
182 valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(store), &iter, NULL); | |
9 | 183 |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
184 work = VDLIST(vd)->list; |
9 | 185 while (work) |
186 { | |
973 | 187 gint match; |
9 | 188 GdkPixbuf *pixbuf; |
825 | 189 const gchar *date = ""; |
9 | 190 fd = work->data; |
973 | 191 gint done = FALSE; |
9 | 192 |
193 if (access_file(fd->path, R_OK | X_OK) && fd->name) | |
194 { | |
195 if (fd->name[0] == '.' && fd->name[1] == '\0') | |
196 { | |
381 | 197 pixbuf = vd->pf->open; |
9 | 198 } |
199 else if (fd->name[0] == '.' && fd->name[1] == '.' && fd->name[2] == '\0') | |
200 { | |
381 | 201 pixbuf = vd->pf->parent; |
9 | 202 } |
203 else | |
204 { | |
381 | 205 pixbuf = vd->pf->close; |
825 | 206 if (options->layout.show_directory_date) |
207 date = text_from_time(fd->date); | |
9 | 208 } |
209 } | |
210 else | |
211 { | |
381 | 212 pixbuf = vd->pf->deny; |
9 | 213 } |
214 | |
973 | 215 while (!done) |
216 { | |
217 FileData *old_fd = NULL; | |
218 | |
219 if (valid) | |
220 { | |
221 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, | |
222 DIR_COLUMN_POINTER, &old_fd, | |
223 -1); | |
224 | |
225 if (fd == old_fd) | |
226 { | |
227 match = 0; | |
228 } | |
229 else | |
230 { | |
995 | 231 match = filelist_sort_compare_filedata_full(fd, old_fd, SORT_NAME, TRUE); |
973 | 232 |
233 if (match == 0) g_warning("multiple fd for the same path"); | |
234 } | |
235 | |
236 } | |
237 else | |
238 { | |
239 match = -1; | |
240 } | |
241 | |
242 if (match < 0) | |
243 { | |
244 GtkTreeIter new; | |
9 | 245 |
973 | 246 if (valid) |
247 { | |
248 gtk_list_store_insert_before(store, &new, &iter); | |
249 } | |
250 else | |
251 { | |
252 gtk_list_store_append(store, &new); | |
253 } | |
254 | |
255 gtk_list_store_set(store, &new, | |
256 DIR_COLUMN_POINTER, fd, | |
257 DIR_COLUMN_ICON, pixbuf, | |
258 DIR_COLUMN_NAME, fd->name, | |
259 DIR_COLUMN_DATE, date, | |
260 -1); | |
261 | |
262 done = TRUE; | |
263 } | |
264 else if (match > 0) | |
265 { | |
266 valid = gtk_list_store_remove(store, &iter); | |
267 } | |
268 else | |
269 { | |
270 gtk_list_store_set(store, &iter, | |
271 DIR_COLUMN_ICON, pixbuf, | |
272 DIR_COLUMN_NAME, fd->name, | |
273 DIR_COLUMN_DATE, date, | |
274 -1); | |
275 | |
276 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
277 | |
278 done = TRUE; | |
279 } | |
280 } | |
9 | 281 work = work->next; |
282 } | |
283 | |
973 | 284 while (valid) |
285 { | |
286 FileData *old_fd; | |
287 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DIR_COLUMN_POINTER, &old_fd, -1); | |
288 | |
289 valid = gtk_list_store_remove(store, &iter); | |
290 } | |
291 | |
292 | |
381 | 293 vd->click_fd = NULL; |
294 vd->drop_fd = NULL; | |
973 | 295 |
296 filelist_free(old_list); | |
297 return ret; | |
9 | 298 } |
299 | |
783 | 300 gint vdlist_set_fd(ViewDir *vd, FileData *dir_fd) |
9 | 301 { |
302 gint ret; | |
303 gchar *old_path = NULL; | |
304 | |
783 | 305 if (!dir_fd) return FALSE; |
306 if (vd->dir_fd == dir_fd) return TRUE; | |
9 | 307 |
783 | 308 if (vd->dir_fd) |
9 | 309 { |
310 gchar *base; | |
311 | |
783 | 312 base = remove_level_from_path(vd->dir_fd->path); |
313 if (strcmp(base, dir_fd->path) == 0) | |
9 | 314 { |
783 | 315 old_path = g_strdup(vd->dir_fd->name); |
9 | 316 } |
317 g_free(base); | |
318 } | |
319 | |
783 | 320 file_data_unref(vd->dir_fd); |
321 vd->dir_fd = file_data_ref(dir_fd); | |
9 | 322 |
973 | 323 ret = vdlist_populate(vd, TRUE); |
9 | 324 |
325 if (old_path) | |
326 { | |
327 /* scroll to make last path visible */ | |
328 FileData *found = NULL; | |
329 GList *work; | |
330 | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
331 work = VDLIST(vd)->list; |
9 | 332 while (work && !found) |
333 { | |
334 FileData *fd = work->data; | |
335 if (strcmp(old_path, fd->name) == 0) found = fd; | |
336 work = work->next; | |
337 } | |
338 | |
381 | 339 if (found) vdlist_scroll_to_row(vd, found, 0.5); |
9 | 340 |
341 g_free(old_path); | |
342 return ret; | |
343 } | |
344 | |
381 | 345 if (GTK_WIDGET_REALIZED(vd->view)) |
9 | 346 { |
381 | 347 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vd->view), 0, 0); |
9 | 348 } |
349 | |
350 return ret; | |
351 } | |
352 | |
381 | 353 void vdlist_refresh(ViewDir *vd) |
9 | 354 { |
973 | 355 vdlist_populate(vd, FALSE); |
9 | 356 } |
357 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
358 gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 359 { |
381 | 360 ViewDir *vd = data; |
9 | 361 GtkTreePath *tpath; |
442 | 362 |
9 | 363 if (event->keyval != GDK_Menu) return FALSE; |
364 | |
381 | 365 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
9 | 366 if (tpath) |
367 { | |
368 GtkTreeModel *store; | |
369 GtkTreeIter iter; | |
370 | |
371 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
372 gtk_tree_model_get_iter(store, &iter, tpath); | |
381 | 373 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &vd->click_fd, -1); |
442 | 374 |
9 | 375 gtk_tree_path_free(tpath); |
376 } | |
377 else | |
378 { | |
381 | 379 vd->click_fd = NULL; |
9 | 380 } |
381 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
382 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 383 |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
384 vd->popup = vd_pop_menu(vd, vd->click_fd); |
9 | 385 |
395 | 386 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vd_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
9 | 387 |
388 return TRUE; | |
389 } | |
390 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
391 gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 392 { |
381 | 393 ViewDir *vd = data; |
9 | 394 GtkTreePath *tpath; |
395 GtkTreeIter iter; | |
396 FileData *fd = NULL; | |
397 | |
398 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
399 &tpath, NULL, NULL, NULL)) | |
400 { | |
401 GtkTreeModel *store; | |
402 | |
403 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
404 gtk_tree_model_get_iter(store, &iter, tpath); | |
405 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
406 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
407 gtk_tree_path_free(tpath); | |
408 } | |
409 | |
381 | 410 vd->click_fd = fd; |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
411 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 412 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
413 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 414 { |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
415 vd->popup = vd_pop_menu(vd, vd->click_fd); |
381 | 416 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
9 | 417 bevent->button, bevent->time); |
418 } | |
419 | |
420 return TRUE; | |
421 } | |
422 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
423 void vdlist_destroy_cb(GtkWidget *widget, gpointer data) |
9 | 424 { |
381 | 425 ViewDir *vd = data; |
9 | 426 |
394 | 427 vd_dnd_drop_scroll_cancel(vd); |
381 | 428 widget_auto_scroll_stop(vd->view); |
9 | 429 |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
430 filelist_free(VDLIST(vd)->list); |
9 | 431 } |
432 | |
783 | 433 ViewDir *vdlist_new(ViewDir *vd, FileData *dir_fd) |
9 | 434 { |
435 GtkListStore *store; | |
436 GtkTreeSelection *selection; | |
437 GtkTreeViewColumn *column; | |
438 GtkCellRenderer *renderer; | |
439 | |
381 | 440 vd->info = g_new0(ViewDirInfoList, 1); |
441 vd->type = DIRVIEW_LIST; | |
9 | 442 |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
443 VDLIST(vd)->list = NULL; |
9 | 444 |
825 | 445 store = gtk_list_store_new(5, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING); |
381 | 446 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 447 g_object_unref(store); |
448 | |
381 | 449 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
450 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
9 | 451 |
381 | 452 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 453 gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); |
454 | |
455 column = gtk_tree_view_column_new(); | |
456 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
457 | |
458 renderer = gtk_cell_renderer_pixbuf_new(); | |
459 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
460 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
396 | 461 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 462 |
463 renderer = gtk_cell_renderer_text_new(); | |
464 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
465 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
396 | 466 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 467 |
825 | 468 renderer = gtk_cell_renderer_text_new(); |
469 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
470 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_DATE); | |
471 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); | |
472 | |
381 | 473 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
9 | 474 |
381 | 475 return vd; |
9 | 476 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
995
diff
changeset
|
477 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |