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