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