Mercurial > geeqie.yaz
annotate src/view_dir_tree.c @ 641:81441380d3be
When an option was successfully read, just continue to next line.
author | zas_ |
---|---|
date | Mon, 12 May 2008 10:46:23 +0000 |
parents | 905688aa2317 |
children | fbebf5cf4a55 |
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 | |
382 | 45 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, const gchar *target_path); |
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 { |
382 | 175 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path); |
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 | |
209 if (*strp != '/') return NULL; | |
210 | |
211 strp++; | |
212 strb = strp; | |
213 l = 0; | |
214 | |
215 while (*strp != '\0') | |
216 { | |
217 if (*strp == '/') | |
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 | |
234 list = g_list_prepend(list, g_strdup("/")); | |
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 { | |
382 | 416 vdtree_populate_path_by_iter(vd, &child, FALSE, vd->path); |
9 | 417 } |
418 gtk_tree_path_free(tpath); | |
419 } | |
420 } | |
421 | |
382 | 422 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, const gchar *target_path) |
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 |
455 list = NULL; | |
456 filelist_read(nd->fd->path, NULL, &list); | |
457 | |
458 /* when hidden files are not enabled, and the user enters a hidden path, | |
459 * allow the tree to display that path by specifically inserting the hidden entries | |
460 */ | |
356 | 461 if (!options->file_filter.show_hidden_files && |
9 | 462 target_path && |
463 strncmp(nd->fd->path, target_path, strlen(nd->fd->path)) == 0) | |
464 { | |
465 gint n; | |
466 | |
467 n = strlen(nd->fd->path); | |
468 if (target_path[n] == '/' && target_path[n+1] == '.') | |
469 { | |
470 gchar *name8; | |
471 struct stat sbuf; | |
472 | |
473 n++; | |
474 | |
475 while (target_path[n] != '\0' && target_path[n] != '/') n++; | |
476 name8 = g_strndup(target_path, n); | |
477 | |
478 if (stat_utf8(name8, &sbuf)) | |
479 { | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
138
diff
changeset
|
480 list = g_list_prepend(list, file_data_new_simple(name8)); |
9 | 481 } |
482 | |
483 g_free(name8); | |
484 } | |
485 } | |
486 | |
487 old = NULL; | |
488 if (gtk_tree_model_iter_children(store, &child, iter)) | |
489 { | |
490 do { | |
491 NodeData *cnd; | |
492 | |
493 gtk_tree_model_get(store, &child, DIR_COLUMN_POINTER, &cnd, -1); | |
494 old = g_list_prepend(old, cnd); | |
495 } while (gtk_tree_model_iter_next(store, &child)); | |
496 } | |
497 | |
498 work = list; | |
499 while (work) | |
500 { | |
501 FileData *fd; | |
502 | |
503 fd = work->data; | |
504 work = work->next; | |
505 | |
506 if (strcmp(fd->name, ".") == 0 || strcmp(fd->name, "..") == 0) | |
507 { | |
138 | 508 file_data_unref(fd); |
9 | 509 } |
510 else | |
511 { | |
512 NodeData *cnd; | |
513 | |
382 | 514 cnd = vdtree_find_iter_by_name(vd, iter, fd->name, &child); |
9 | 515 if (cnd) |
516 { | |
517 old = g_list_remove(old, cnd); | |
518 if (cnd->expanded && cnd->fd->date != fd->date && | |
382 | 519 vdtree_populate_path_by_iter(vd, &child, FALSE, target_path)) |
9 | 520 { |
521 cnd->fd->size = fd->size; | |
522 cnd->fd->date = fd->date; | |
523 } | |
524 | |
138 | 525 file_data_unref(fd); |
9 | 526 } |
527 else | |
528 { | |
382 | 529 vdtree_add_by_data(vd, fd, iter); |
9 | 530 } |
531 } | |
532 } | |
533 | |
534 work = old; | |
535 while (work) | |
536 { | |
537 NodeData *cnd = work->data; | |
538 work = work->next; | |
539 | |
382 | 540 if (vd->click_fd == cnd->fd) vd->click_fd = NULL; |
541 if (vd->drop_fd == cnd->fd) vd->drop_fd = NULL; | |
9 | 542 |
382 | 543 if (vdtree_find_iter_by_data(vd, iter, cnd, &child)) |
9 | 544 { |
545 gtk_tree_store_remove(GTK_TREE_STORE(store), &child); | |
546 vdtree_node_free(cnd); | |
547 } | |
548 } | |
549 | |
550 g_list_free(old); | |
551 g_list_free(list); | |
552 | |
382 | 553 vdtree_busy_pop(vd); |
9 | 554 |
555 nd->expanded = TRUE; | |
556 nd->last_update = current_time; | |
557 | |
558 return TRUE; | |
559 } | |
560 | |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
384
diff
changeset
|
561 FileData *vdtree_populate_path(ViewDir *vd, const gchar *path, gint expand, gint force) |
9 | 562 { |
563 GList *list; | |
564 GList *work; | |
565 FileData *fd = NULL; | |
566 | |
567 if (!path) return NULL; | |
568 | |
382 | 569 vdtree_busy_push(vd); |
9 | 570 |
571 list = parts_list(path); | |
382 | 572 list = parts_list_add_node_points(vd, list); |
9 | 573 |
574 work = list; | |
575 while (work) | |
576 { | |
577 PathData *pd = work->data; | |
578 if (pd->node == NULL) | |
579 { | |
580 PathData *parent_pd; | |
581 GtkTreeIter parent_iter; | |
582 GtkTreeIter iter; | |
583 NodeData *nd; | |
584 | |
585 if (work == list) | |
586 { | |
587 /* should not happen */ | |
588 printf("vdtree warning, root node not found\n"); | |
589 parts_list_free(list); | |
382 | 590 vdtree_busy_pop(vd); |
9 | 591 return NULL; |
592 } | |
593 | |
594 parent_pd = work->prev->data; | |
595 | |
389 | 596 if (!vd_find_row(vd, parent_pd->node, &parent_iter) || |
382 | 597 !vdtree_populate_path_by_iter(vd, &parent_iter, force, path) || |
598 (nd = vdtree_find_iter_by_name(vd, &parent_iter, pd->name, &iter)) == NULL) | |
9 | 599 { |
600 printf("vdtree warning, aborted at %s\n", parent_pd->name); | |
601 parts_list_free(list); | |
382 | 602 vdtree_busy_pop(vd); |
9 | 603 return NULL; |
604 } | |
605 | |
606 pd->node = nd->fd; | |
607 | |
608 if (pd->node) | |
609 { | |
610 if (expand) | |
611 { | |
382 | 612 vdtree_expand_by_iter(vd, &parent_iter, TRUE); |
613 vdtree_expand_by_iter(vd, &iter, TRUE); | |
9 | 614 } |
382 | 615 vdtree_populate_path_by_iter(vd, &iter, force, path); |
9 | 616 } |
617 } | |
618 else | |
619 { | |
620 GtkTreeIter iter; | |
621 | |
389 | 622 if (vd_find_row(vd, pd->node, &iter)) |
9 | 623 { |
382 | 624 if (expand) vdtree_expand_by_iter(vd, &iter, TRUE); |
625 vdtree_populate_path_by_iter(vd, &iter, force, path); | |
9 | 626 } |
627 } | |
628 | |
629 work = work->next; | |
630 } | |
631 | |
632 work = g_list_last(list); | |
633 if (work) | |
634 { | |
635 PathData *pd = work->data; | |
636 fd = pd->node; | |
637 } | |
638 parts_list_free(list); | |
639 | |
382 | 640 vdtree_busy_pop(vd); |
9 | 641 |
642 return fd; | |
643 } | |
644 | |
645 /* | |
646 *---------------------------------------------------------------------------- | |
647 * access | |
648 *---------------------------------------------------------------------------- | |
649 */ | |
650 | |
651 static gint selection_is_ok = FALSE; | |
652 | |
653 static gboolean vdtree_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
442 | 654 gboolean path_currently_selected, gpointer data) |
9 | 655 { |
656 return selection_is_ok; | |
657 } | |
658 | |
396 | 659 void vdtree_select_row(ViewDir *vd, FileData *fd) |
9 | 660 { |
661 GtkTreeSelection *selection; | |
662 GtkTreeIter iter; | |
442 | 663 |
389 | 664 if (!vd_find_row(vd, fd, &iter)) return; |
382 | 665 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 666 |
667 /* hack, such that selection is only allowed to be changed from here */ | |
668 selection_is_ok = TRUE; | |
669 gtk_tree_selection_select_iter(selection, &iter); | |
670 selection_is_ok = FALSE; | |
671 | |
382 | 672 if (!vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path)) return; |
9 | 673 |
382 | 674 vdtree_expand_by_iter(vd, &iter, TRUE); |
9 | 675 |
442 | 676 if (fd && vd->select_func) |
677 { | |
678 vd->select_func(vd, fd->path, vd->select_data); | |
679 } | |
9 | 680 } |
681 | |
382 | 682 gint vdtree_set_path(ViewDir *vd, const gchar *path) |
9 | 683 { |
684 FileData *fd; | |
685 GtkTreeIter iter; | |
686 | |
687 if (!path) return FALSE; | |
382 | 688 if (vd->path && strcmp(path, vd->path) == 0) return TRUE; |
9 | 689 |
382 | 690 g_free(vd->path); |
691 vd->path = g_strdup(path); | |
9 | 692 |
382 | 693 fd = vdtree_populate_path(vd, vd->path, TRUE, FALSE); |
9 | 694 |
695 if (!fd) return FALSE; | |
696 | |
389 | 697 if (vd_find_row(vd, fd, &iter)) |
9 | 698 { |
699 GtkTreeModel *store; | |
700 GtkTreePath *tpath; | |
701 | |
382 | 702 tree_view_row_make_visible(GTK_TREE_VIEW(vd->view), &iter, TRUE); |
9 | 703 |
382 | 704 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 705 tpath = gtk_tree_model_get_path(store, &iter); |
382 | 706 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE); |
9 | 707 gtk_tree_path_free(tpath); |
708 | |
382 | 709 vdtree_select_row(vd, fd); |
9 | 710 } |
711 | |
712 return TRUE; | |
713 } | |
714 | |
715 #if 0 | |
382 | 716 const gchar *vdtree_get_path(ViewDir *vd) |
9 | 717 { |
382 | 718 return vd->path; |
9 | 719 } |
720 #endif | |
721 | |
382 | 722 void vdtree_refresh(ViewDir *vd) |
9 | 723 { |
382 | 724 vdtree_populate_path(vd, vd->path, FALSE, TRUE); |
9 | 725 } |
726 | |
382 | 727 const gchar *vdtree_row_get_path(ViewDir *vd, gint row) |
9 | 728 { |
729 printf("FIXME: no get row path\n"); | |
730 return NULL; | |
731 } | |
732 | |
733 /* | |
734 *---------------------------------------------------------------------------- | |
735 * callbacks | |
736 *---------------------------------------------------------------------------- | |
737 */ | |
738 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
739 gint vdtree_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 740 { |
382 | 741 ViewDir *vd = data; |
9 | 742 GtkTreePath *tpath; |
743 GtkTreeIter iter; | |
744 FileData *fd = NULL; | |
745 | |
382 | 746 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
9 | 747 if (tpath) |
748 { | |
749 GtkTreeModel *store; | |
750 NodeData *nd; | |
751 | |
752 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
753 gtk_tree_model_get_iter(store, &iter, tpath); | |
754 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
755 | |
756 gtk_tree_path_free(tpath); | |
757 | |
758 fd = (nd) ? nd->fd : NULL; | |
759 } | |
760 | |
761 switch (event->keyval) | |
762 { | |
763 case GDK_Menu: | |
382 | 764 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
|
765 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 766 |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
384
diff
changeset
|
767 vd->popup = vd_pop_menu(vd, vd->click_fd); |
395 | 768 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vd_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
9 | 769 |
770 return TRUE; | |
771 break; | |
772 case GDK_plus: | |
773 case GDK_Right: | |
774 case GDK_KP_Add: | |
775 if (fd) | |
776 { | |
382 | 777 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path); |
778 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); | |
9 | 779 } |
780 break; | |
781 } | |
782 | |
783 return FALSE; | |
784 } | |
785 | |
786 static gint vdtree_clicked_on_expander(GtkTreeView *treeview, GtkTreePath *tpath, | |
787 GtkTreeViewColumn *column, gint x, gint y, gint *left_of_expander) | |
788 { | |
789 gint depth; | |
790 gint size; | |
791 gint sep; | |
792 gint exp_width; | |
793 | |
794 if (column != gtk_tree_view_get_expander_column(treeview)) return FALSE; | |
795 | |
796 gtk_widget_style_get(GTK_WIDGET(treeview), "expander-size", &size, "horizontal-separator", &sep, NULL); | |
797 depth = gtk_tree_path_get_depth(tpath); | |
798 | |
799 exp_width = sep + size + sep; | |
800 | |
801 if (x <= depth * exp_width) | |
802 { | |
803 if (left_of_expander) *left_of_expander = !(x >= (depth - 1) * exp_width); | |
804 return TRUE; | |
805 } | |
806 | |
807 return FALSE; | |
808 } | |
809 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
810 gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 811 { |
382 | 812 ViewDir *vd = data; |
9 | 813 GtkTreePath *tpath; |
814 GtkTreeViewColumn *column; | |
815 GtkTreeIter iter; | |
816 NodeData *nd = NULL; | |
817 | |
818 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
819 &tpath, &column, NULL, NULL)) | |
820 { | |
821 GtkTreeModel *store; | |
822 gint left_of_expander; | |
823 | |
824 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
825 gtk_tree_model_get_iter(store, &iter, tpath); | |
826 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
827 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
828 | |
829 if (vdtree_clicked_on_expander(GTK_TREE_VIEW(widget), tpath, column, bevent->x, bevent->y, &left_of_expander)) | |
830 { | |
382 | 831 vd->click_fd = NULL; |
9 | 832 |
833 /* clicking this region should automatically reveal an expander, if necessary | |
834 * treeview bug: the expander will not expand until a button_motion_event highlights it. | |
835 */ | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
836 if (bevent->button == MOUSE_BUTTON_LEFT && |
9 | 837 !left_of_expander && |
382 | 838 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath)) |
9 | 839 { |
382 | 840 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path); |
841 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); | |
9 | 842 } |
843 | |
844 gtk_tree_path_free(tpath); | |
845 return FALSE; | |
846 } | |
847 | |
848 gtk_tree_path_free(tpath); | |
849 } | |
850 | |
382 | 851 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
|
852 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 853 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
854 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 855 { |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
384
diff
changeset
|
856 vd->popup = vd_pop_menu(vd, vd->click_fd); |
382 | 857 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
9 | 858 bevent->button, bevent->time); |
859 } | |
860 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
861 return (bevent->button != MOUSE_BUTTON_LEFT); |
9 | 862 } |
863 | |
864 static void vdtree_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
865 { | |
382 | 866 ViewDir *vd = data; |
9 | 867 |
382 | 868 vdtree_populate_path_by_iter(vd, iter, FALSE, NULL); |
869 vdtree_icon_set_by_iter(vd, iter, vd->pf->open); | |
9 | 870 } |
871 | |
872 static void vdtree_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
873 { | |
382 | 874 ViewDir *vd = data; |
9 | 875 |
382 | 876 vdtree_icon_set_by_iter(vd, iter, vd->pf->close); |
9 | 877 } |
878 | |
879 static gint vdtree_sort_cb(GtkTreeModel *store, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
880 { | |
881 NodeData *nda; | |
882 NodeData *ndb; | |
883 | |
884 gtk_tree_model_get(store, a, DIR_COLUMN_POINTER, &nda, -1); | |
885 gtk_tree_model_get(store, b, DIR_COLUMN_POINTER, &ndb, -1); | |
886 | |
887 return CASE_SORT(nda->fd->name, ndb->fd->name); | |
888 } | |
889 | |
890 /* | |
891 *---------------------------------------------------------------------------- | |
892 * core | |
893 *---------------------------------------------------------------------------- | |
894 */ | |
895 | |
382 | 896 static void vdtree_setup_root(ViewDir *vd) |
9 | 897 { |
898 const gchar *path = "/"; | |
899 FileData *fd; | |
900 | |
138 | 901 |
902 fd = file_data_new_simple(path); | |
382 | 903 vdtree_add_by_data(vd, fd, NULL); |
9 | 904 |
382 | 905 vdtree_expand_by_data(vd, fd, TRUE); |
906 vdtree_populate_path(vd, path, FALSE, FALSE); | |
9 | 907 } |
908 | |
909 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
910 { | |
911 NodeData *nd; | |
912 | |
913 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
914 vdtree_node_free(nd); | |
915 | |
916 return FALSE; | |
917 } | |
918 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
919 void vdtree_destroy_cb(GtkWidget *widget, gpointer data) |
9 | 920 { |
382 | 921 ViewDir *vd = data; |
9 | 922 GtkTreeModel *store; |
923 | |
382 | 924 vdtree_dnd_drop_expand_cancel(vd); |
394 | 925 vd_dnd_drop_scroll_cancel(vd); |
382 | 926 widget_auto_scroll_stop(vd->view); |
9 | 927 |
382 | 928 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
929 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vd); | |
9 | 930 } |
931 | |
384
392dd6541d51
Merge parts of view_dir_list/tree constructors/destructors to
zas_
parents:
383
diff
changeset
|
932 ViewDir *vdtree_new(ViewDir *vd, const gchar *path) |
9 | 933 { |
934 GtkTreeStore *store; | |
935 GtkTreeSelection *selection; | |
936 GtkTreeViewColumn *column; | |
937 GtkCellRenderer *renderer; | |
938 | |
382 | 939 vd->info = g_new0(ViewDirInfoTree, 1); |
940 vd->type = DIRVIEW_TREE; | |
9 | 941 |
382 | 942 VDTREE_INFO(vd, drop_expand_id) = -1; |
943 VDTREE_INFO(vd, busy_ref) = 0; | |
442 | 944 |
407 | 945 vd->dnd_drop_leave_func = vdtree_dnd_drop_expand_cancel; |
946 vd->dnd_drop_update_func = vdtree_dnd_drop_expand; | |
9 | 947 |
948 store = gtk_tree_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); | |
382 | 949 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 950 g_object_unref(store); |
951 | |
382 | 952 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
953 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
954 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vd, NULL); | |
9 | 955 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), |
956 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); | |
957 | |
382 | 958 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 959 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); |
382 | 960 gtk_tree_selection_set_select_function(selection, vdtree_select_cb, vd, NULL); |
9 | 961 |
962 column = gtk_tree_view_column_new(); | |
963 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
964 | |
965 renderer = gtk_cell_renderer_pixbuf_new(); | |
966 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
967 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
396 | 968 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 969 |
970 renderer = gtk_cell_renderer_text_new(); | |
971 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
972 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
396 | 973 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 974 |
382 | 975 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
9 | 976 |
382 | 977 vdtree_setup_root(vd); |
9 | 978 |
405 | 979 g_signal_connect(G_OBJECT(vd->view), "row_expanded", |
980 G_CALLBACK(vdtree_row_expanded), vd); | |
981 g_signal_connect(G_OBJECT(vd->view), "row_collapsed", | |
982 G_CALLBACK(vdtree_row_collapsed), vd); | |
9 | 983 |
382 | 984 return vd; |
9 | 985 } |