Mercurial > geeqie.yaz
annotate src/view_dir_tree.c @ 810:602cec932587
optimized vficon_refresh_real
author | nadvornik |
---|---|
date | Mon, 09 Jun 2008 18:28:28 +0000 |
parents | 548b193c084c |
children | c90eb9539f6e |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
3 * (C) 2006 John Ellis |
475 | 4 * Copyright (C) 2008 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_tree.h" |
15 | |
16 | |
17 #include "dnd.h" | |
18 #include "dupe.h" | |
586 | 19 #include "filedata.h" |
9 | 20 #include "layout.h" |
21 #include "layout_image.h" | |
22 #include "layout_util.h" | |
23 #include "utilops.h" | |
24 #include "ui_bookmark.h" | |
25 #include "ui_fileops.h" | |
26 #include "ui_menu.h" | |
27 #include "ui_tree_edit.h" | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
356
diff
changeset
|
28 #include "view_dir.h" |
9 | 29 |
30 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
31 | |
32 | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
356
diff
changeset
|
33 #define VDTREE_INFO(_vd_, _part_) (((ViewDirInfoTree *)(_vd_->info))->_part_) |
9 | 34 |
35 | |
36 typedef struct _PathData PathData; | |
37 struct _PathData | |
38 { | |
39 gchar *name; | |
40 FileData *node; | |
41 }; | |
42 | |
43 | |
44 | |
783 | 45 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd); |
9 | 46 |
47 | |
48 /* | |
49 *---------------------------------------------------------------------------- | |
50 * utils | |
51 *---------------------------------------------------------------------------- | |
52 */ | |
53 | |
54 static void set_cursor(GtkWidget *widget, GdkCursorType cursor_type) | |
55 { | |
56 GdkCursor *cursor = NULL; | |
57 | |
58 if (!widget || !widget->window) return; | |
59 | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
60 if (cursor_type > -1) cursor = gdk_cursor_new(cursor_type); |
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
61 gdk_window_set_cursor(widget->window, cursor); |
9 | 62 if (cursor) gdk_cursor_unref(cursor); |
63 gdk_flush(); | |
64 } | |
65 | |
382 | 66 static void vdtree_busy_push(ViewDir *vd) |
9 | 67 { |
382 | 68 if (VDTREE_INFO(vd, busy_ref) == 0) set_cursor(vd->view, GDK_WATCH); |
69 VDTREE_INFO(vd, busy_ref)++; | |
9 | 70 } |
71 | |
382 | 72 static void vdtree_busy_pop(ViewDir *vd) |
9 | 73 { |
382 | 74 if (VDTREE_INFO(vd, busy_ref) == 1) set_cursor(vd->view, -1); |
75 if (VDTREE_INFO(vd, busy_ref) > 0) VDTREE_INFO(vd, busy_ref)--; | |
9 | 76 } |
77 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
382
diff
changeset
|
78 gint vdtree_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent) |
9 | 79 { |
80 GtkTreeModel *store; | |
81 gint valid; | |
82 | |
382 | 83 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 84 if (parent) |
85 { | |
86 valid = gtk_tree_model_iter_children(store, iter, parent); | |
87 } | |
88 else | |
89 { | |
90 valid = gtk_tree_model_get_iter_first(store, iter); | |
91 } | |
92 while (valid) | |
93 { | |
94 NodeData *nd; | |
95 GtkTreeIter found; | |
96 | |
97 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &nd, -1); | |
98 if (nd->fd == fd) return TRUE; | |
99 | |
382 | 100 if (vdtree_find_row(vd, fd, &found, iter)) |
9 | 101 { |
102 memcpy(iter, &found, sizeof(found)); | |
103 return TRUE; | |
104 } | |
105 | |
106 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
107 } | |
108 | |
109 return FALSE; | |
110 } | |
111 | |
382 | 112 static void vdtree_icon_set_by_iter(ViewDir *vd, GtkTreeIter *iter, GdkPixbuf *pixbuf) |
9 | 113 { |
114 GtkTreeModel *store; | |
115 GdkPixbuf *old; | |
116 | |
382 | 117 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 118 gtk_tree_model_get(store, iter, DIR_COLUMN_ICON, &old, -1); |
382 | 119 if (old != vd->pf->deny) |
9 | 120 { |
121 gtk_tree_store_set(GTK_TREE_STORE(store), iter, DIR_COLUMN_ICON, pixbuf, -1); | |
122 } | |
123 } | |
124 | |
382 | 125 static void vdtree_expand_by_iter(ViewDir *vd, GtkTreeIter *iter, gint expand) |
9 | 126 { |
127 GtkTreeModel *store; | |
128 GtkTreePath *tpath; | |
129 | |
382 | 130 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 131 tpath = gtk_tree_model_get_path(store, iter); |
132 if (expand) | |
133 { | |
382 | 134 gtk_tree_view_expand_row(GTK_TREE_VIEW(vd->view), tpath, FALSE); |
135 vdtree_icon_set_by_iter(vd, iter, vd->pf->open); | |
9 | 136 } |
137 else | |
138 { | |
382 | 139 gtk_tree_view_collapse_row(GTK_TREE_VIEW(vd->view), tpath); |
9 | 140 } |
141 gtk_tree_path_free(tpath); | |
142 } | |
143 | |
382 | 144 static void vdtree_expand_by_data(ViewDir *vd, FileData *fd, gint expand) |
9 | 145 { |
146 GtkTreeIter iter; | |
147 | |
389 | 148 if (vd_find_row(vd, fd, &iter)) |
9 | 149 { |
382 | 150 vdtree_expand_by_iter(vd, &iter, expand); |
9 | 151 } |
152 } | |
153 | |
154 static void vdtree_node_free(NodeData *nd) | |
155 { | |
156 if (!nd) return; | |
157 | |
138 | 158 file_data_unref(nd->fd); |
9 | 159 g_free(nd); |
160 } | |
161 | |
162 /* | |
163 *---------------------------------------------------------------------------- | |
164 * dnd | |
165 *---------------------------------------------------------------------------- | |
166 */ | |
167 | |
168 static gint vdtree_dnd_drop_expand_cb(gpointer data) | |
169 { | |
382 | 170 ViewDir *vd = data; |
9 | 171 GtkTreeIter iter; |
172 | |
394 | 173 if (vd->drop_fd && vd_find_row(vd, vd->drop_fd, &iter)) |
9 | 174 { |
783 | 175 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
382 | 176 vdtree_expand_by_data(vd, vd->drop_fd, TRUE); |
9 | 177 } |
178 | |
382 | 179 VDTREE_INFO(vd, drop_expand_id) = -1; |
9 | 180 return FALSE; |
181 } | |
182 | |
407 | 183 static void vdtree_dnd_drop_expand_cancel(ViewDir *vd) |
9 | 184 { |
382 | 185 if (VDTREE_INFO(vd, drop_expand_id) != -1) g_source_remove(VDTREE_INFO(vd, drop_expand_id)); |
186 VDTREE_INFO(vd, drop_expand_id) = -1; | |
9 | 187 } |
188 | |
407 | 189 static void vdtree_dnd_drop_expand(ViewDir *vd) |
9 | 190 { |
382 | 191 vdtree_dnd_drop_expand_cancel(vd); |
192 VDTREE_INFO(vd, drop_expand_id) = g_timeout_add(1000, vdtree_dnd_drop_expand_cb, vd); | |
9 | 193 } |
194 | |
195 /* | |
196 *---------------------------------------------------------------------------- | |
197 * parts lists | |
198 *---------------------------------------------------------------------------- | |
199 */ | |
200 | |
201 static GList *parts_list(const gchar *path) | |
202 { | |
203 GList *list = NULL; | |
204 const gchar *strb, *strp; | |
205 gint l; | |
206 | |
207 strp = path; | |
208 | |
726 | 209 if (*strp != G_DIR_SEPARATOR) return NULL; |
9 | 210 |
211 strp++; | |
212 strb = strp; | |
213 l = 0; | |
214 | |
215 while (*strp != '\0') | |
216 { | |
726 | 217 if (*strp == G_DIR_SEPARATOR) |
9 | 218 { |
219 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
220 strp++; | |
221 strb = strp; | |
222 l = 0; | |
223 } | |
224 else | |
225 { | |
226 strp++; | |
227 l++; | |
228 } | |
229 } | |
230 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
231 | |
232 list = g_list_reverse(list); | |
233 | |
725 | 234 list = g_list_prepend(list, g_strdup(G_DIR_SEPARATOR_S)); |
9 | 235 |
236 return list; | |
237 } | |
238 | |
239 static void parts_list_free(GList *list) | |
240 { | |
241 GList *work = list; | |
242 while (work) | |
243 { | |
244 PathData *pd = work->data; | |
245 g_free(pd->name); | |
246 g_free(pd); | |
247 work = work->next; | |
248 } | |
249 | |
250 g_list_free(list); | |
251 } | |
252 | |
382 | 253 static GList *parts_list_add_node_points(ViewDir *vd, GList *list) |
9 | 254 { |
255 GList *work; | |
256 GtkTreeModel *store; | |
257 GtkTreeIter iter; | |
258 gint valid; | |
259 | |
382 | 260 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 261 valid = gtk_tree_model_get_iter_first(store, &iter); |
262 | |
263 work = list; | |
264 while (work) | |
265 { | |
266 PathData *pd; | |
267 FileData *fd = NULL; | |
268 | |
269 pd = g_new0(PathData, 1); | |
270 pd->name = work->data; | |
271 | |
272 while (valid && !fd) | |
273 { | |
274 NodeData *nd; | |
275 | |
276 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
277 if (strcmp(nd->fd->name, pd->name) == 0) | |
278 { | |
279 fd = nd->fd; | |
280 } | |
281 else | |
282 { | |
283 valid = gtk_tree_model_iter_next(store, &iter); | |
284 } | |
285 } | |
286 | |
287 pd->node = fd; | |
288 work->data = pd; | |
289 | |
290 if (fd) | |
291 { | |
292 GtkTreeIter parent; | |
293 memcpy(&parent, &iter, sizeof(parent)); | |
294 valid = gtk_tree_model_iter_children(store, &iter, &parent); | |
295 } | |
296 | |
297 work = work->next; | |
298 } | |
299 | |
300 return list; | |
301 } | |
302 | |
303 /* | |
304 *---------------------------------------------------------------------------- | |
305 * misc | |
306 *---------------------------------------------------------------------------- | |
307 */ | |
308 | |
309 #if 0 | |
310 static void vdtree_row_deleted_cb(GtkTreeModel *tree_model, GtkTreePath *tpath, gpointer data) | |
311 { | |
312 GtkTreeIter iter; | |
313 NodeData *nd; | |
314 | |
315 gtk_tree_model_get_iter(tree_model, &iter, tpath); | |
316 gtk_tree_model_get(tree_model, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
317 | |
318 if (!nd) return; | |
319 | |
138 | 320 file_data_unref(nd->fd); |
9 | 321 g_free(nd); |
322 } | |
323 #endif | |
324 | |
325 /* | |
326 *---------------------------------------------------------------------------- | |
327 * node traversal, management | |
328 *---------------------------------------------------------------------------- | |
329 */ | |
330 | |
382 | 331 static gint vdtree_find_iter_by_data(ViewDir *vd, GtkTreeIter *parent, NodeData *nd, GtkTreeIter *iter) |
9 | 332 { |
333 GtkTreeModel *store; | |
334 | |
382 | 335 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 336 if (!nd || !gtk_tree_model_iter_children(store, iter, parent)) return -1; |
337 do { | |
338 NodeData *cnd; | |
339 | |
340 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &cnd, -1); | |
341 if (cnd == nd) return TRUE; | |
342 } while (gtk_tree_model_iter_next(store, iter)); | |
343 | |
344 return FALSE; | |
345 } | |
346 | |
382 | 347 static NodeData *vdtree_find_iter_by_name(ViewDir *vd, GtkTreeIter *parent, const gchar *name, GtkTreeIter *iter) |
9 | 348 { |
349 GtkTreeModel *store; | |
350 | |
382 | 351 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 352 if (!name || !gtk_tree_model_iter_children(store, iter, parent)) return NULL; |
353 do { | |
354 NodeData *nd; | |
355 | |
356 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
357 if (nd && strcmp(nd->fd->name, name) == 0) return nd; | |
358 } while (gtk_tree_model_iter_next(store, iter)); | |
359 | |
360 return NULL; | |
361 } | |
362 | |
382 | 363 static void vdtree_add_by_data(ViewDir *vd, FileData *fd, GtkTreeIter *parent) |
9 | 364 { |
365 GtkTreeStore *store; | |
366 GtkTreeIter child; | |
367 NodeData *nd; | |
368 GdkPixbuf *pixbuf; | |
369 NodeData *end; | |
370 GtkTreeIter empty; | |
371 | |
372 if (!fd) return; | |
373 | |
374 if (access_file(fd->path, R_OK | X_OK)) | |
375 { | |
382 | 376 pixbuf = vd->pf->close; |
9 | 377 } |
378 else | |
379 { | |
382 | 380 pixbuf = vd->pf->deny; |
9 | 381 } |
382 | |
383 nd = g_new0(NodeData, 1); | |
384 nd->fd = fd; | |
385 nd->expanded = FALSE; | |
386 nd->last_update = time(NULL); | |
387 | |
382 | 388 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view))); |
9 | 389 gtk_tree_store_append(store, &child, parent); |
390 gtk_tree_store_set(store, &child, DIR_COLUMN_POINTER, nd, | |
391 DIR_COLUMN_ICON, pixbuf, | |
392 DIR_COLUMN_NAME, nd->fd->name, | |
393 DIR_COLUMN_COLOR, FALSE, -1); | |
394 | |
395 /* all nodes are created with an "empty" node, so that the expander is shown | |
396 * this is removed when the child is populated */ | |
397 end = g_new0(NodeData, 1); | |
138 | 398 end->fd = file_data_new_simple(""); |
9 | 399 end->expanded = TRUE; |
400 | |
401 gtk_tree_store_append(store, &empty, &child); | |
402 gtk_tree_store_set(store, &empty, DIR_COLUMN_POINTER, end, | |
403 DIR_COLUMN_NAME, "empty", -1); | |
404 | |
405 if (parent) | |
406 { | |
407 NodeData *pnd; | |
408 GtkTreePath *tpath; | |
409 | |
410 gtk_tree_model_get(GTK_TREE_MODEL(store), parent, DIR_COLUMN_POINTER, &pnd, -1); | |
411 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent); | |
320 | 412 if (options->tree_descend_subdirs && |
382 | 413 gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath) && |
9 | 414 !nd->expanded) |
415 { | |
783 | 416 vdtree_populate_path_by_iter(vd, &child, FALSE, vd->dir_fd); |
9 | 417 } |
418 gtk_tree_path_free(tpath); | |
419 } | |
420 } | |
421 | |
783 | 422 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd) |
9 | 423 { |
424 GtkTreeModel *store; | |
425 GList *list; | |
426 GList *work; | |
427 GList *old; | |
428 time_t current_time; | |
429 GtkTreeIter child; | |
430 NodeData *nd; | |
431 | |
382 | 432 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 433 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); |
434 | |
435 if (!nd) return FALSE; | |
436 | |
437 current_time = time(NULL); | |
442 | 438 |
9 | 439 if (nd->expanded) |
440 { | |
441 if (!force && current_time - nd->last_update < 10) return TRUE; | |
442 if (!isdir(nd->fd->path)) | |
443 { | |
382 | 444 if (vd->click_fd == nd->fd) vd->click_fd = NULL; |
445 if (vd->drop_fd == nd->fd) vd->drop_fd = NULL; | |
9 | 446 gtk_tree_store_remove(GTK_TREE_STORE(store), iter); |
447 vdtree_node_free(nd); | |
448 return FALSE; | |
449 } | |
450 if (!force && filetime(nd->fd->path) == nd->fd->date) return TRUE; | |
451 } | |
452 | |
382 | 453 vdtree_busy_push(vd); |
9 | 454 |
783 | 455 filelist_read(nd->fd, NULL, &list); |
9 | 456 |
457 /* when hidden files are not enabled, and the user enters a hidden path, | |
458 * allow the tree to display that path by specifically inserting the hidden entries | |
459 */ | |
356 | 460 if (!options->file_filter.show_hidden_files && |
783 | 461 target_fd && |
462 strncmp(nd->fd->path, target_fd->path, strlen(nd->fd->path)) == 0) | |
9 | 463 { |
464 gint n; | |
465 | |
466 n = strlen(nd->fd->path); | |
783 | 467 if (target_fd->path[n] == G_DIR_SEPARATOR && target_fd->path[n+1] == '.') |
9 | 468 { |
469 gchar *name8; | |
470 struct stat sbuf; | |
471 | |
472 n++; | |
473 | |
783 | 474 while (target_fd->path[n] != '\0' && target_fd->path[n] != G_DIR_SEPARATOR) n++; |
475 name8 = g_strndup(target_fd->path, n); | |
9 | 476 |
477 if (stat_utf8(name8, &sbuf)) | |
478 { | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
138
diff
changeset
|
479 list = g_list_prepend(list, file_data_new_simple(name8)); |
9 | 480 } |
481 | |
482 g_free(name8); | |
483 } | |
484 } | |
485 | |
486 old = NULL; | |
487 if (gtk_tree_model_iter_children(store, &child, iter)) | |
488 { | |
489 do { | |
490 NodeData *cnd; | |
491 | |
492 gtk_tree_model_get(store, &child, DIR_COLUMN_POINTER, &cnd, -1); | |
493 old = g_list_prepend(old, cnd); | |
494 } while (gtk_tree_model_iter_next(store, &child)); | |
495 } | |
496 | |
497 work = list; | |
498 while (work) | |
499 { | |
500 FileData *fd; | |
501 | |
502 fd = work->data; | |
503 work = work->next; | |
504 | |
505 if (strcmp(fd->name, ".") == 0 || strcmp(fd->name, "..") == 0) | |
506 { | |
138 | 507 file_data_unref(fd); |
9 | 508 } |
509 else | |
510 { | |
511 NodeData *cnd; | |
512 | |
382 | 513 cnd = vdtree_find_iter_by_name(vd, iter, fd->name, &child); |
9 | 514 if (cnd) |
515 { | |
516 old = g_list_remove(old, cnd); | |
517 if (cnd->expanded && cnd->fd->date != fd->date && | |
783 | 518 vdtree_populate_path_by_iter(vd, &child, FALSE, target_fd)) |
9 | 519 { |
520 cnd->fd->size = fd->size; | |
521 cnd->fd->date = fd->date; | |
522 } | |
523 | |
138 | 524 file_data_unref(fd); |
9 | 525 } |
526 else | |
527 { | |
382 | 528 vdtree_add_by_data(vd, fd, iter); |
9 | 529 } |
530 } | |
531 } | |
532 | |
533 work = old; | |
534 while (work) | |
535 { | |
536 NodeData *cnd = work->data; | |
537 work = work->next; | |
538 | |
382 | 539 if (vd->click_fd == cnd->fd) vd->click_fd = NULL; |
540 if (vd->drop_fd == cnd->fd) vd->drop_fd = NULL; | |
9 | 541 |
382 | 542 if (vdtree_find_iter_by_data(vd, iter, cnd, &child)) |
9 | 543 { |
544 gtk_tree_store_remove(GTK_TREE_STORE(store), &child); | |
545 vdtree_node_free(cnd); | |
546 } | |
547 } | |
548 | |
549 g_list_free(old); | |
550 g_list_free(list); | |
551 | |
382 | 552 vdtree_busy_pop(vd); |
9 | 553 |
554 nd->expanded = TRUE; | |
555 nd->last_update = current_time; | |
556 | |
557 return TRUE; | |
558 } | |
559 | |
783 | 560 FileData *vdtree_populate_path(ViewDir *vd, FileData *target_fd, gint expand, gint force) |
9 | 561 { |
562 GList *list; | |
563 GList *work; | |
564 FileData *fd = NULL; | |
565 | |
783 | 566 if (!target_fd) return NULL; |
9 | 567 |
382 | 568 vdtree_busy_push(vd); |
9 | 569 |
783 | 570 list = parts_list(target_fd->path); |
382 | 571 list = parts_list_add_node_points(vd, list); |
9 | 572 |
573 work = list; | |
574 while (work) | |
575 { | |
576 PathData *pd = work->data; | |
577 if (pd->node == NULL) | |
578 { | |
579 PathData *parent_pd; | |
580 GtkTreeIter parent_iter; | |
581 GtkTreeIter iter; | |
582 NodeData *nd; | |
583 | |
584 if (work == list) | |
585 { | |
586 /* should not happen */ | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
586
diff
changeset
|
587 log_printf("vdtree warning, root node not found\n"); |
9 | 588 parts_list_free(list); |
382 | 589 vdtree_busy_pop(vd); |
9 | 590 return NULL; |
591 } | |
592 | |
593 parent_pd = work->prev->data; | |
594 | |
389 | 595 if (!vd_find_row(vd, parent_pd->node, &parent_iter) || |
783 | 596 !vdtree_populate_path_by_iter(vd, &parent_iter, force, target_fd) || |
382 | 597 (nd = vdtree_find_iter_by_name(vd, &parent_iter, pd->name, &iter)) == NULL) |
9 | 598 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
586
diff
changeset
|
599 log_printf("vdtree warning, aborted at %s\n", parent_pd->name); |
9 | 600 parts_list_free(list); |
382 | 601 vdtree_busy_pop(vd); |
9 | 602 return NULL; |
603 } | |
604 | |
605 pd->node = nd->fd; | |
606 | |
607 if (pd->node) | |
608 { | |
609 if (expand) | |
610 { | |
382 | 611 vdtree_expand_by_iter(vd, &parent_iter, TRUE); |
612 vdtree_expand_by_iter(vd, &iter, TRUE); | |
9 | 613 } |
783 | 614 vdtree_populate_path_by_iter(vd, &iter, force, target_fd); |
9 | 615 } |
616 } | |
617 else | |
618 { | |
619 GtkTreeIter iter; | |
620 | |
389 | 621 if (vd_find_row(vd, pd->node, &iter)) |
9 | 622 { |
382 | 623 if (expand) vdtree_expand_by_iter(vd, &iter, TRUE); |
783 | 624 vdtree_populate_path_by_iter(vd, &iter, force, target_fd); |
9 | 625 } |
626 } | |
627 | |
628 work = work->next; | |
629 } | |
630 | |
631 work = g_list_last(list); | |
632 if (work) | |
633 { | |
634 PathData *pd = work->data; | |
635 fd = pd->node; | |
636 } | |
637 parts_list_free(list); | |
638 | |
382 | 639 vdtree_busy_pop(vd); |
9 | 640 |
641 return fd; | |
642 } | |
643 | |
644 /* | |
645 *---------------------------------------------------------------------------- | |
646 * access | |
647 *---------------------------------------------------------------------------- | |
648 */ | |
649 | |
650 static gint selection_is_ok = FALSE; | |
651 | |
652 static gboolean vdtree_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
442 | 653 gboolean path_currently_selected, gpointer data) |
9 | 654 { |
655 return selection_is_ok; | |
656 } | |
657 | |
396 | 658 void vdtree_select_row(ViewDir *vd, FileData *fd) |
9 | 659 { |
660 GtkTreeSelection *selection; | |
661 GtkTreeIter iter; | |
442 | 662 |
389 | 663 if (!vd_find_row(vd, fd, &iter)) return; |
382 | 664 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 665 |
666 /* hack, such that selection is only allowed to be changed from here */ | |
667 selection_is_ok = TRUE; | |
668 gtk_tree_selection_select_iter(selection, &iter); | |
669 selection_is_ok = FALSE; | |
670 | |
783 | 671 if (!vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd)) return; |
9 | 672 |
382 | 673 vdtree_expand_by_iter(vd, &iter, TRUE); |
9 | 674 |
442 | 675 if (fd && vd->select_func) |
676 { | |
677 vd->select_func(vd, fd->path, vd->select_data); | |
678 } | |
9 | 679 } |
680 | |
783 | 681 gint vdtree_set_fd(ViewDir *vd, FileData *dir_fd) |
9 | 682 { |
683 FileData *fd; | |
684 GtkTreeIter iter; | |
685 | |
783 | 686 if (!dir_fd) return FALSE; |
687 if (vd->dir_fd == dir_fd) return TRUE; | |
9 | 688 |
783 | 689 file_data_unref(vd->dir_fd); |
690 vd->dir_fd = file_data_ref(dir_fd);; | |
9 | 691 |
783 | 692 fd = vdtree_populate_path(vd, vd->dir_fd, TRUE, FALSE); |
9 | 693 |
694 if (!fd) return FALSE; | |
695 | |
389 | 696 if (vd_find_row(vd, fd, &iter)) |
9 | 697 { |
698 GtkTreeModel *store; | |
699 GtkTreePath *tpath; | |
700 | |
382 | 701 tree_view_row_make_visible(GTK_TREE_VIEW(vd->view), &iter, TRUE); |
9 | 702 |
382 | 703 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 704 tpath = gtk_tree_model_get_path(store, &iter); |
382 | 705 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE); |
9 | 706 gtk_tree_path_free(tpath); |
707 | |
382 | 708 vdtree_select_row(vd, fd); |
9 | 709 } |
710 | |
711 return TRUE; | |
712 } | |
713 | |
714 #if 0 | |
382 | 715 const gchar *vdtree_get_path(ViewDir *vd) |
9 | 716 { |
382 | 717 return vd->path; |
9 | 718 } |
719 #endif | |
720 | |
382 | 721 void vdtree_refresh(ViewDir *vd) |
9 | 722 { |
783 | 723 vdtree_populate_path(vd, vd->dir_fd, FALSE, TRUE); |
9 | 724 } |
725 | |
382 | 726 const gchar *vdtree_row_get_path(ViewDir *vd, gint row) |
9 | 727 { |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
586
diff
changeset
|
728 log_printf("FIXME: no get row path\n"); |
9 | 729 return NULL; |
730 } | |
731 | |
732 /* | |
733 *---------------------------------------------------------------------------- | |
734 * callbacks | |
735 *---------------------------------------------------------------------------- | |
736 */ | |
737 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
738 gint vdtree_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 739 { |
382 | 740 ViewDir *vd = data; |
9 | 741 GtkTreePath *tpath; |
742 GtkTreeIter iter; | |
743 FileData *fd = NULL; | |
744 | |
382 | 745 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
9 | 746 if (tpath) |
747 { | |
748 GtkTreeModel *store; | |
749 NodeData *nd; | |
750 | |
751 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
752 gtk_tree_model_get_iter(store, &iter, tpath); | |
753 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
754 | |
755 gtk_tree_path_free(tpath); | |
756 | |
757 fd = (nd) ? nd->fd : NULL; | |
758 } | |
759 | |
760 switch (event->keyval) | |
761 { | |
762 case GDK_Menu: | |
382 | 763 vd->click_fd = fd; |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
382
diff
changeset
|
764 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 765 |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
384
diff
changeset
|
766 vd->popup = vd_pop_menu(vd, vd->click_fd); |
395 | 767 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vd_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
9 | 768 |
769 return TRUE; | |
770 break; | |
771 case GDK_plus: | |
772 case GDK_Right: | |
773 case GDK_KP_Add: | |
774 if (fd) | |
775 { | |
783 | 776 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
382 | 777 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); |
9 | 778 } |
779 break; | |
780 } | |
781 | |
782 return FALSE; | |
783 } | |
784 | |
785 static gint vdtree_clicked_on_expander(GtkTreeView *treeview, GtkTreePath *tpath, | |
786 GtkTreeViewColumn *column, gint x, gint y, gint *left_of_expander) | |
787 { | |
788 gint depth; | |
789 gint size; | |
790 gint sep; | |
791 gint exp_width; | |
792 | |
793 if (column != gtk_tree_view_get_expander_column(treeview)) return FALSE; | |
794 | |
795 gtk_widget_style_get(GTK_WIDGET(treeview), "expander-size", &size, "horizontal-separator", &sep, NULL); | |
796 depth = gtk_tree_path_get_depth(tpath); | |
797 | |
798 exp_width = sep + size + sep; | |
799 | |
800 if (x <= depth * exp_width) | |
801 { | |
802 if (left_of_expander) *left_of_expander = !(x >= (depth - 1) * exp_width); | |
803 return TRUE; | |
804 } | |
805 | |
806 return FALSE; | |
807 } | |
808 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
809 gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 810 { |
382 | 811 ViewDir *vd = data; |
9 | 812 GtkTreePath *tpath; |
813 GtkTreeViewColumn *column; | |
814 GtkTreeIter iter; | |
815 NodeData *nd = NULL; | |
816 | |
817 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
818 &tpath, &column, NULL, NULL)) | |
819 { | |
820 GtkTreeModel *store; | |
821 gint left_of_expander; | |
822 | |
823 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
824 gtk_tree_model_get_iter(store, &iter, tpath); | |
825 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
826 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
827 | |
828 if (vdtree_clicked_on_expander(GTK_TREE_VIEW(widget), tpath, column, bevent->x, bevent->y, &left_of_expander)) | |
829 { | |
382 | 830 vd->click_fd = NULL; |
9 | 831 |
832 /* clicking this region should automatically reveal an expander, if necessary | |
833 * treeview bug: the expander will not expand until a button_motion_event highlights it. | |
834 */ | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
835 if (bevent->button == MOUSE_BUTTON_LEFT && |
9 | 836 !left_of_expander && |
382 | 837 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath)) |
9 | 838 { |
783 | 839 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
382 | 840 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); |
9 | 841 } |
842 | |
843 gtk_tree_path_free(tpath); | |
844 return FALSE; | |
845 } | |
846 | |
847 gtk_tree_path_free(tpath); | |
848 } | |
849 | |
382 | 850 vd->click_fd = (nd) ? nd->fd : NULL; |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
382
diff
changeset
|
851 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 852 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
853 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 854 { |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
384
diff
changeset
|
855 vd->popup = vd_pop_menu(vd, vd->click_fd); |
382 | 856 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
9 | 857 bevent->button, bevent->time); |
858 } | |
859 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
860 return (bevent->button != MOUSE_BUTTON_LEFT); |
9 | 861 } |
862 | |
863 static void vdtree_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
864 { | |
382 | 865 ViewDir *vd = data; |
9 | 866 |
382 | 867 vdtree_populate_path_by_iter(vd, iter, FALSE, NULL); |
868 vdtree_icon_set_by_iter(vd, iter, vd->pf->open); | |
9 | 869 } |
870 | |
871 static void vdtree_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
872 { | |
382 | 873 ViewDir *vd = data; |
9 | 874 |
382 | 875 vdtree_icon_set_by_iter(vd, iter, vd->pf->close); |
9 | 876 } |
877 | |
878 static gint vdtree_sort_cb(GtkTreeModel *store, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
879 { | |
880 NodeData *nda; | |
881 NodeData *ndb; | |
882 | |
883 gtk_tree_model_get(store, a, DIR_COLUMN_POINTER, &nda, -1); | |
884 gtk_tree_model_get(store, b, DIR_COLUMN_POINTER, &ndb, -1); | |
885 | |
785 | 886 if (options->file_sort.case_sensitive) |
887 return strcmp(nda->fd->collate_key_name, nda->fd->collate_key_name); | |
888 else | |
889 return strcmp(nda->fd->collate_key_name_nocase, nda->fd->collate_key_name_nocase); | |
9 | 890 } |
891 | |
892 /* | |
893 *---------------------------------------------------------------------------- | |
894 * core | |
895 *---------------------------------------------------------------------------- | |
896 */ | |
897 | |
382 | 898 static void vdtree_setup_root(ViewDir *vd) |
9 | 899 { |
725 | 900 const gchar *path = G_DIR_SEPARATOR_S; |
9 | 901 FileData *fd; |
902 | |
138 | 903 |
904 fd = file_data_new_simple(path); | |
382 | 905 vdtree_add_by_data(vd, fd, NULL); |
9 | 906 |
382 | 907 vdtree_expand_by_data(vd, fd, TRUE); |
783 | 908 vdtree_populate_path(vd, fd, FALSE, FALSE); |
9 | 909 } |
910 | |
911 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
912 { | |
913 NodeData *nd; | |
914 | |
915 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
916 vdtree_node_free(nd); | |
917 | |
918 return FALSE; | |
919 } | |
920 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
921 void vdtree_destroy_cb(GtkWidget *widget, gpointer data) |
9 | 922 { |
382 | 923 ViewDir *vd = data; |
9 | 924 GtkTreeModel *store; |
925 | |
382 | 926 vdtree_dnd_drop_expand_cancel(vd); |
394 | 927 vd_dnd_drop_scroll_cancel(vd); |
382 | 928 widget_auto_scroll_stop(vd->view); |
9 | 929 |
382 | 930 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
931 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vd); | |
9 | 932 } |
933 | |
783 | 934 ViewDir *vdtree_new(ViewDir *vd, FileData *dir_fd) |
9 | 935 { |
936 GtkTreeStore *store; | |
937 GtkTreeSelection *selection; | |
938 GtkTreeViewColumn *column; | |
939 GtkCellRenderer *renderer; | |
940 | |
382 | 941 vd->info = g_new0(ViewDirInfoTree, 1); |
942 vd->type = DIRVIEW_TREE; | |
9 | 943 |
382 | 944 VDTREE_INFO(vd, drop_expand_id) = -1; |
945 VDTREE_INFO(vd, busy_ref) = 0; | |
442 | 946 |
407 | 947 vd->dnd_drop_leave_func = vdtree_dnd_drop_expand_cancel; |
948 vd->dnd_drop_update_func = vdtree_dnd_drop_expand; | |
9 | 949 |
950 store = gtk_tree_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); | |
382 | 951 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 952 g_object_unref(store); |
953 | |
382 | 954 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
955 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
956 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vd, NULL); | |
9 | 957 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), |
958 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); | |
959 | |
382 | 960 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 961 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); |
382 | 962 gtk_tree_selection_set_select_function(selection, vdtree_select_cb, vd, NULL); |
9 | 963 |
964 column = gtk_tree_view_column_new(); | |
965 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
966 | |
967 renderer = gtk_cell_renderer_pixbuf_new(); | |
968 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
969 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
396 | 970 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 971 |
972 renderer = gtk_cell_renderer_text_new(); | |
973 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
974 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
396 | 975 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 976 |
382 | 977 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
9 | 978 |
382 | 979 vdtree_setup_root(vd); |
9 | 980 |
405 | 981 g_signal_connect(G_OBJECT(vd->view), "row_expanded", |
982 G_CALLBACK(vdtree_row_expanded), vd); | |
983 g_signal_connect(G_OBJECT(vd->view), "row_collapsed", | |
984 G_CALLBACK(vdtree_row_collapsed), vd); | |
9 | 985 |
382 | 986 return vd; |
9 | 987 } |