Mercurial > geeqie
annotate src/view_dir_tree.c @ 242:59eac2063093
Fix a segfault occuring when using --without-exiv2 and
concerning exif stuff.
author | zas_ |
---|---|
date | Thu, 03 Apr 2008 21:50:53 +0000 |
parents | f6e307c7bad6 |
children | 22ed43d4c849 |
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 |
9 | 4 * |
5 * Author: John Ellis | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
11 | |
12 #include "gqview.h" | |
13 #include "view_dir_tree.h" | |
14 | |
15 | |
16 #include "dnd.h" | |
17 #include "dupe.h" | |
18 #include "filelist.h" | |
19 #include "layout.h" | |
20 #include "layout_image.h" | |
21 #include "layout_util.h" | |
22 #include "utilops.h" | |
23 #include "ui_bookmark.h" | |
24 #include "ui_fileops.h" | |
25 #include "ui_menu.h" | |
26 #include "ui_tree_edit.h" | |
27 | |
28 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
29 | |
30 | |
31 #define VDTREE_INDENT 14 | |
32 #define VDTREE_PAD 4 | |
33 | |
34 enum { | |
35 DIR_COLUMN_POINTER = 0, | |
36 DIR_COLUMN_ICON, | |
37 DIR_COLUMN_NAME, | |
38 DIR_COLUMN_COLOR, | |
39 DIR_COLUMN_COUNT | |
40 }; | |
41 | |
42 | |
43 typedef struct _PathData PathData; | |
44 struct _PathData | |
45 { | |
46 gchar *name; | |
47 FileData *node; | |
48 }; | |
49 | |
50 typedef struct _NodeData NodeData; | |
51 struct _NodeData | |
52 { | |
53 FileData *fd; | |
54 gint expanded; | |
55 time_t last_update; | |
56 }; | |
57 | |
58 | |
59 static gint vdtree_populate_path_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, gint force, const gchar *target_path); | |
60 static FileData *vdtree_populate_path(ViewDirTree *vdt, const gchar *path, gint expand, gint force); | |
61 | |
62 | |
63 /* | |
64 *---------------------------------------------------------------------------- | |
65 * utils | |
66 *---------------------------------------------------------------------------- | |
67 */ | |
68 | |
69 static void set_cursor(GtkWidget *widget, GdkCursorType cursor_type) | |
70 { | |
71 GdkCursor *cursor = NULL; | |
72 | |
73 if (!widget || !widget->window) return; | |
74 | |
75 if (cursor_type > -1) cursor = gdk_cursor_new (cursor_type); | |
76 gdk_window_set_cursor (widget->window, cursor); | |
77 if (cursor) gdk_cursor_unref(cursor); | |
78 gdk_flush(); | |
79 } | |
80 | |
81 static void vdtree_busy_push(ViewDirTree *vdt) | |
82 { | |
83 if (vdt->busy_ref == 0) set_cursor(vdt->treeview, GDK_WATCH); | |
84 vdt->busy_ref++; | |
85 } | |
86 | |
87 static void vdtree_busy_pop(ViewDirTree *vdt) | |
88 { | |
89 if (vdt->busy_ref == 1) set_cursor(vdt->treeview, -1); | |
90 if (vdt->busy_ref > 0) vdt->busy_ref--; | |
91 } | |
92 | |
93 static gint vdtree_find_row(ViewDirTree *vdt, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent) | |
94 { | |
95 GtkTreeModel *store; | |
96 gint valid; | |
97 | |
98 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
99 if (parent) | |
100 { | |
101 valid = gtk_tree_model_iter_children(store, iter, parent); | |
102 } | |
103 else | |
104 { | |
105 valid = gtk_tree_model_get_iter_first(store, iter); | |
106 } | |
107 while (valid) | |
108 { | |
109 NodeData *nd; | |
110 GtkTreeIter found; | |
111 | |
112 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &nd, -1); | |
113 if (nd->fd == fd) return TRUE; | |
114 | |
115 if (vdtree_find_row(vdt, fd, &found, iter)) | |
116 { | |
117 memcpy(iter, &found, sizeof(found)); | |
118 return TRUE; | |
119 } | |
120 | |
121 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
122 } | |
123 | |
124 return FALSE; | |
125 } | |
126 | |
127 static void vdtree_icon_set_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, GdkPixbuf *pixbuf) | |
128 { | |
129 GtkTreeModel *store; | |
130 GdkPixbuf *old; | |
131 | |
132 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
133 gtk_tree_model_get(store, iter, DIR_COLUMN_ICON, &old, -1); | |
134 if (old != vdt->pf->deny) | |
135 { | |
136 gtk_tree_store_set(GTK_TREE_STORE(store), iter, DIR_COLUMN_ICON, pixbuf, -1); | |
137 } | |
138 } | |
139 | |
140 static void vdtree_expand_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, gint expand) | |
141 { | |
142 GtkTreeModel *store; | |
143 GtkTreePath *tpath; | |
144 | |
145 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
146 tpath = gtk_tree_model_get_path(store, iter); | |
147 if (expand) | |
148 { | |
149 gtk_tree_view_expand_row(GTK_TREE_VIEW(vdt->treeview), tpath, FALSE); | |
150 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->open); | |
151 } | |
152 else | |
153 { | |
154 gtk_tree_view_collapse_row(GTK_TREE_VIEW(vdt->treeview), tpath); | |
155 } | |
156 gtk_tree_path_free(tpath); | |
157 } | |
158 | |
159 static void vdtree_expand_by_data(ViewDirTree *vdt, FileData *fd, gint expand) | |
160 { | |
161 GtkTreeIter iter; | |
162 | |
163 if (vdtree_find_row(vdt, fd, &iter, NULL)) | |
164 { | |
165 vdtree_expand_by_iter(vdt, &iter, expand); | |
166 } | |
167 } | |
168 | |
169 static void vdtree_color_set(ViewDirTree *vdt, FileData *fd, gint color_set) | |
170 { | |
171 GtkTreeModel *store; | |
172 GtkTreeIter iter; | |
173 | |
174 if (!vdtree_find_row(vdt, fd, &iter, NULL)) return; | |
175 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
176 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1); | |
177 } | |
178 | |
179 static gint vdtree_rename_row_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) | |
180 { | |
181 ViewDirTree *vdt = data; | |
182 GtkTreeModel *store; | |
183 GtkTreeIter iter; | |
184 NodeData *nd; | |
185 gchar *old_path; | |
186 gchar *new_path; | |
187 gchar *base; | |
188 | |
189 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
190 if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE; | |
191 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
192 if (!nd) return FALSE; | |
193 | |
194 old_path = g_strdup(nd->fd->path); | |
195 | |
196 base = remove_level_from_path(old_path); | |
197 new_path = concat_dir_and_file(base, new); | |
198 g_free(base); | |
199 | |
138 | 200 if (file_util_rename_dir(nd->fd, new_path, vdt->treeview)) |
9 | 201 { |
202 vdtree_populate_path(vdt, new_path, TRUE, TRUE); | |
203 | |
204 if (vdt->layout && strcmp(vdt->path, old_path) == 0) | |
205 { | |
206 layout_set_path(vdt->layout, new_path); | |
207 } | |
208 } | |
209 | |
210 g_free(old_path); | |
211 g_free(new_path); | |
212 | |
213 return FALSE; | |
214 } | |
215 | |
216 static void vdtree_rename_by_data(ViewDirTree *vdt, FileData *fd) | |
217 { | |
218 GtkTreeModel *store; | |
219 GtkTreePath *tpath; | |
220 GtkTreeIter iter; | |
221 | |
222 if (!fd || | |
223 !vdtree_find_row(vdt, fd, &iter, NULL)) return; | |
224 | |
225 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
226 tpath = gtk_tree_model_get_path(store, &iter); | |
227 | |
228 tree_edit_by_path(GTK_TREE_VIEW(vdt->treeview), tpath, 0, fd->name, | |
229 vdtree_rename_row_cb, vdt); | |
230 gtk_tree_path_free(tpath); | |
231 } | |
232 | |
233 static void vdtree_node_free(NodeData *nd) | |
234 { | |
235 if (!nd) return; | |
236 | |
138 | 237 file_data_unref(nd->fd); |
9 | 238 g_free(nd); |
239 } | |
240 | |
241 static void vdtree_popup_destroy_cb(GtkWidget *widget, gpointer data) | |
242 { | |
243 ViewDirTree *vdt = data; | |
244 | |
245 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
246 vdt->click_fd = NULL; | |
247 vdt->popup = NULL; | |
248 | |
249 vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
138 | 250 filelist_free(vdt->drop_list); |
9 | 251 vdt->drop_list = NULL; |
252 vdt->drop_fd = NULL; | |
253 } | |
254 | |
255 /* | |
256 *----------------------------------------------------------------------------- | |
257 * drop menu (from dnd) | |
258 *----------------------------------------------------------------------------- | |
259 */ | |
260 | |
261 static void vdtree_drop_menu_copy_cb(GtkWidget *widget, gpointer data) | |
262 { | |
263 ViewDirTree *vdt = data; | |
264 const gchar *path; | |
265 GList *list; | |
266 | |
267 if (!vdt->drop_fd) return; | |
268 | |
269 path = vdt->drop_fd->path; | |
270 list = vdt->drop_list; | |
271 | |
272 vdt->drop_list = NULL; | |
273 | |
274 file_util_copy_simple(list, path); | |
275 } | |
276 | |
277 static void vdtree_drop_menu_move_cb(GtkWidget *widget, gpointer data) | |
278 { | |
279 ViewDirTree *vdt = data; | |
280 const gchar *path; | |
281 GList *list; | |
282 | |
283 if (!vdt->drop_fd) return; | |
284 | |
285 path = vdt->drop_fd->path; | |
286 list = vdt->drop_list; | |
287 | |
288 vdt->drop_list = NULL; | |
289 | |
290 file_util_move_simple(list, path); | |
291 } | |
292 | |
293 static GtkWidget *vdtree_drop_menu(ViewDirTree *vdt, gint active) | |
294 { | |
295 GtkWidget *menu; | |
296 | |
297 menu = popup_menu_short_lived(); | |
298 g_signal_connect(G_OBJECT(menu), "destroy", | |
299 G_CALLBACK(vdtree_popup_destroy_cb), vdt); | |
300 | |
301 menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active, | |
302 G_CALLBACK(vdtree_drop_menu_copy_cb), vdt); | |
303 menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vdtree_drop_menu_move_cb), vdt); | |
304 | |
305 menu_item_add_divider(menu); | |
306 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vdt); | |
307 | |
308 return menu; | |
309 } | |
310 | |
311 /* | |
312 *----------------------------------------------------------------------------- | |
313 * pop-up menu | |
314 *----------------------------------------------------------------------------- | |
315 */ | |
316 | |
317 static void vdtree_pop_menu_up_cb(GtkWidget *widget, gpointer data) | |
318 { | |
319 ViewDirTree *vdt = data; | |
320 gchar *path; | |
321 | |
322 if (!vdt->path || strcmp(vdt->path, "/") == 0) return; | |
323 path = remove_level_from_path(vdt->path); | |
324 | |
325 if (vdt->select_func) | |
326 { | |
327 vdt->select_func(vdt, path, vdt->select_data); | |
328 } | |
329 | |
330 g_free(path); | |
331 } | |
332 | |
333 static void vdtree_pop_menu_slide_cb(GtkWidget *widget, gpointer data) | |
334 { | |
335 ViewDirTree *vdt = data; | |
336 gchar *path; | |
337 | |
338 if (!vdt->layout) return; | |
339 | |
340 if (!vdt->click_fd) return; | |
138 | 341 path = vdt->click_fd->path; |
9 | 342 |
343 layout_set_path(vdt->layout, path); | |
344 layout_select_none(vdt->layout); | |
345 layout_image_slideshow_stop(vdt->layout); | |
346 layout_image_slideshow_start(vdt->layout); | |
347 } | |
348 | |
349 static void vdtree_pop_menu_slide_rec_cb(GtkWidget *widget, gpointer data) | |
350 { | |
351 ViewDirTree *vdt = data; | |
352 gchar *path; | |
353 GList *list; | |
354 | |
355 if (!vdt->layout) return; | |
356 | |
357 if (!vdt->click_fd) return; | |
138 | 358 path = vdt->click_fd->path; |
9 | 359 |
138 | 360 list = filelist_recursive(path); |
9 | 361 |
362 layout_image_slideshow_stop(vdt->layout); | |
363 layout_image_slideshow_start_from_list(vdt->layout, list); | |
364 } | |
365 | |
366 static void vdtree_pop_menu_dupe(ViewDirTree *vdt, gint recursive) | |
367 { | |
368 DupeWindow *dw; | |
369 GList *list = NULL; | |
370 | |
371 if (!vdt->click_fd) return; | |
372 | |
373 if (recursive) | |
374 { | |
138 | 375 list = g_list_append(list, file_data_ref(vdt->click_fd)); |
9 | 376 } |
377 else | |
378 { | |
138 | 379 filelist_read(vdt->click_fd->path, &list, NULL); |
380 list = filelist_filter(list, FALSE); | |
9 | 381 } |
382 | |
383 dw = dupe_window_new(DUPE_MATCH_NAME); | |
384 dupe_window_add_files(dw, list, recursive); | |
385 | |
138 | 386 filelist_free(list); |
9 | 387 } |
388 | |
389 static void vdtree_pop_menu_dupe_cb(GtkWidget *widget, gpointer data) | |
390 { | |
391 ViewDirTree *vdt = data; | |
392 vdtree_pop_menu_dupe(vdt, FALSE); | |
393 } | |
394 | |
395 static void vdtree_pop_menu_dupe_rec_cb(GtkWidget *widget, gpointer data) | |
396 { | |
397 ViewDirTree *vdt = data; | |
398 vdtree_pop_menu_dupe(vdt, TRUE); | |
399 } | |
400 | |
401 static void vdtree_pop_menu_new_cb(GtkWidget *widget, gpointer data) | |
402 { | |
403 ViewDirTree *vdt = data; | |
404 const gchar *path; | |
405 gchar *new_path; | |
406 gchar *buf; | |
407 | |
408 if (!vdt->click_fd) return; | |
409 path = vdt->click_fd->path; | |
410 | |
411 buf = concat_dir_and_file(path, _("new_folder")); | |
412 new_path = unique_filename(buf, NULL, NULL, FALSE); | |
413 g_free(buf); | |
414 if (!new_path) return; | |
415 | |
416 if (!mkdir_utf8(new_path, 0755)) | |
417 { | |
418 gchar *text; | |
419 | |
420 text = g_strdup_printf(_("Unable to create folder:\n%s"), new_path); | |
421 file_util_warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, vdt->treeview); | |
422 g_free(text); | |
423 } | |
424 else | |
425 { | |
426 FileData *fd; | |
427 | |
428 fd = vdtree_populate_path(vdt, new_path, TRUE, TRUE); | |
429 | |
430 vdtree_rename_by_data(vdt, fd); | |
431 } | |
432 | |
433 g_free(new_path); | |
434 } | |
435 | |
436 static void vdtree_pop_menu_rename_cb(GtkWidget *widget, gpointer data) | |
437 { | |
438 ViewDirTree *vdt = data; | |
439 | |
440 vdtree_rename_by_data(vdt, vdt->click_fd); | |
441 } | |
442 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
443 static void vdtree_pop_menu_delete_cb(GtkWidget *widget, gpointer data) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
444 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
445 ViewDirTree *vdt = data; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
446 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
447 if (!vdt->click_fd) return; |
138 | 448 file_util_delete_dir(vdt->click_fd, vdt->widget); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
449 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
450 |
9 | 451 static void vdtree_pop_menu_tree_cb(GtkWidget *widget, gpointer data) |
452 { | |
453 ViewDirTree *vdt = data; | |
454 | |
455 if (vdt->layout) layout_views_set(vdt->layout, FALSE, vdt->layout->icon_view); | |
456 } | |
457 | |
458 static void vdtree_pop_menu_refresh_cb(GtkWidget *widget, gpointer data) | |
459 { | |
460 ViewDirTree *vdt = data; | |
461 | |
462 if (vdt->layout) layout_refresh(vdt->layout); | |
463 } | |
464 | |
465 static GtkWidget *vdtree_pop_menu(ViewDirTree *vdt, FileData *fd) | |
466 { | |
467 GtkWidget *menu; | |
468 gint active; | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
469 gint parent_active = FALSE; |
9 | 470 |
471 active = (fd != NULL); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
472 if (fd) |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
473 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
474 gchar *parent; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
475 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
476 parent = remove_level_from_path(fd->path); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
477 parent_active = access_file(parent, W_OK | X_OK); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
478 g_free(parent); |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
479 } |
9 | 480 |
481 menu = popup_menu_short_lived(); | |
482 g_signal_connect(G_OBJECT(menu), "destroy", | |
483 G_CALLBACK(vdtree_popup_destroy_cb), vdt); | |
484 | |
485 menu_item_add_stock_sensitive(menu, _("_Up to parent"), GTK_STOCK_GO_UP, | |
486 (vdt->path && strcmp(vdt->path, "/") != 0), | |
487 G_CALLBACK(vdtree_pop_menu_up_cb), vdt); | |
488 | |
489 menu_item_add_divider(menu); | |
490 menu_item_add_sensitive(menu, _("_Slideshow"), active, | |
491 G_CALLBACK(vdtree_pop_menu_slide_cb), vdt); | |
492 menu_item_add_sensitive(menu, _("Slideshow recursive"), active, | |
493 G_CALLBACK(vdtree_pop_menu_slide_rec_cb), vdt); | |
494 | |
495 menu_item_add_divider(menu); | |
496 menu_item_add_stock_sensitive(menu, _("Find _duplicates..."), GTK_STOCK_FIND, active, | |
497 G_CALLBACK(vdtree_pop_menu_dupe_cb), vdt); | |
498 menu_item_add_stock_sensitive(menu, _("Find duplicates recursive..."), GTK_STOCK_FIND, active, | |
499 G_CALLBACK(vdtree_pop_menu_dupe_rec_cb), vdt); | |
500 | |
501 menu_item_add_divider(menu); | |
502 | |
503 active = (fd && | |
504 access_file(fd->path, W_OK | X_OK)); | |
505 menu_item_add_sensitive(menu, _("_New folder..."), active, | |
506 G_CALLBACK(vdtree_pop_menu_new_cb), vdt); | |
507 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
508 menu_item_add_sensitive(menu, _("_Rename..."), parent_active, |
9 | 509 G_CALLBACK(vdtree_pop_menu_rename_cb), vdt); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
510 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, parent_active, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
511 G_CALLBACK(vdtree_pop_menu_delete_cb), vdt); |
9 | 512 |
513 menu_item_add_divider(menu); | |
514 menu_item_add_check(menu, _("View as _tree"), TRUE, | |
515 G_CALLBACK(vdtree_pop_menu_tree_cb), vdt); | |
516 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, | |
517 G_CALLBACK(vdtree_pop_menu_refresh_cb), vdt); | |
518 | |
519 return menu; | |
520 } | |
521 | |
522 /* | |
523 *---------------------------------------------------------------------------- | |
524 * dnd | |
525 *---------------------------------------------------------------------------- | |
526 */ | |
527 | |
528 static GtkTargetEntry vdtree_dnd_drop_types[] = { | |
529 { "text/uri-list", 0, TARGET_URI_LIST } | |
530 }; | |
531 static gint vdtree_dnd_drop_types_count = 1; | |
532 | |
533 | |
534 static void vdtree_dest_set(ViewDirTree *vdt, gint enable) | |
535 { | |
536 if (enable) | |
537 { | |
538 gtk_drag_dest_set(vdt->treeview, | |
539 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, | |
540 vdtree_dnd_drop_types, vdtree_dnd_drop_types_count, | |
541 GDK_ACTION_MOVE | GDK_ACTION_COPY); | |
542 } | |
543 else | |
544 { | |
545 gtk_drag_dest_unset(vdt->treeview); | |
546 } | |
547 } | |
548 | |
549 static void vdtree_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
550 GtkSelectionData *selection_data, guint info, | |
551 guint time, gpointer data) | |
552 { | |
553 ViewDirTree *vdt = data; | |
554 gchar *path; | |
555 GList *list; | |
556 gchar *uri_text = NULL; | |
557 gint length = 0; | |
558 | |
559 if (!vdt->click_fd) return; | |
560 | |
561 switch (info) | |
562 { | |
563 case TARGET_URI_LIST: | |
564 case TARGET_TEXT_PLAIN: | |
138 | 565 list = g_list_prepend(NULL, vdt->click_fd); |
566 uri_text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN)); | |
9 | 567 g_list_free(list); |
568 break; | |
569 } | |
570 | |
571 if (uri_text) | |
572 { | |
573 gtk_selection_data_set(selection_data, selection_data->target, | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
63
diff
changeset
|
574 8, (guchar *)uri_text, length); |
9 | 575 g_free(uri_text); |
576 } | |
577 } | |
578 | |
579 static void vdtree_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
580 { | |
581 ViewDirTree *vdt = data; | |
582 | |
583 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
584 vdtree_dest_set(vdt, FALSE); | |
585 } | |
586 | |
587 static void vdtree_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
588 { | |
589 ViewDirTree *vdt = data; | |
590 | |
591 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
592 vdtree_dest_set(vdt, TRUE); | |
593 } | |
594 | |
595 static void vdtree_dnd_drop_receive(GtkWidget *widget, | |
596 GdkDragContext *context, gint x, gint y, | |
597 GtkSelectionData *selection_data, guint info, | |
598 guint time, gpointer data) | |
599 { | |
600 ViewDirTree *vdt = data; | |
601 GtkTreePath *tpath; | |
602 GtkTreeIter iter; | |
603 FileData *fd = NULL; | |
604 | |
605 vdt->click_fd = NULL; | |
606 | |
607 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, | |
608 &tpath, NULL, NULL, NULL)) | |
609 { | |
610 GtkTreeModel *store; | |
611 NodeData *nd; | |
612 | |
613 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
614 gtk_tree_model_get_iter(store, &iter, tpath); | |
615 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
616 gtk_tree_path_free(tpath); | |
617 | |
618 fd = (nd) ? nd->fd : NULL; | |
619 } | |
620 | |
621 if (!fd) return; | |
622 | |
623 if (info == TARGET_URI_LIST) | |
624 { | |
625 GList *list; | |
626 gint active; | |
627 | |
138 | 628 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); |
9 | 629 if (!list) return; |
630 | |
631 active = access_file(fd->path, W_OK | X_OK); | |
632 | |
633 vdtree_color_set(vdt, fd, TRUE); | |
634 vdt->popup = vdtree_drop_menu(vdt, active); | |
635 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, NULL, NULL, 0, time); | |
636 | |
637 vdt->drop_fd = fd; | |
638 vdt->drop_list = list; | |
639 } | |
640 } | |
641 | |
642 static gint vdtree_dnd_drop_expand_cb(gpointer data) | |
643 { | |
644 ViewDirTree *vdt = data; | |
645 GtkTreeIter iter; | |
646 | |
647 if (vdt->drop_fd && | |
648 vdtree_find_row(vdt, vdt->drop_fd, &iter, NULL)) | |
649 { | |
650 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
651 vdtree_expand_by_data(vdt, vdt->drop_fd, TRUE); | |
652 } | |
653 | |
654 vdt->drop_expand_id = -1; | |
655 return FALSE; | |
656 } | |
657 | |
658 static void vdtree_dnd_drop_expand_cancel(ViewDirTree *vdt) | |
659 { | |
660 if (vdt->drop_expand_id != -1) g_source_remove(vdt->drop_expand_id); | |
661 vdt->drop_expand_id = -1; | |
662 } | |
663 | |
664 static void vdtree_dnd_drop_expand(ViewDirTree *vdt) | |
665 { | |
666 vdtree_dnd_drop_expand_cancel(vdt); | |
667 vdt->drop_expand_id = g_timeout_add(1000, vdtree_dnd_drop_expand_cb, vdt); | |
668 } | |
669 | |
670 static void vdtree_drop_update(ViewDirTree *vdt, gint x, gint y) | |
671 { | |
672 GtkTreePath *tpath; | |
673 GtkTreeIter iter; | |
674 FileData *fd = NULL; | |
675 | |
676 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vdt->treeview), x, y, | |
677 &tpath, NULL, NULL, NULL)) | |
678 { | |
679 GtkTreeModel *store; | |
680 NodeData *nd; | |
681 | |
682 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
683 gtk_tree_model_get_iter(store, &iter, tpath); | |
684 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
685 gtk_tree_path_free(tpath); | |
686 | |
687 fd = (nd) ? nd->fd : NULL; | |
688 } | |
689 | |
690 if (fd != vdt->drop_fd) | |
691 { | |
692 vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
693 vdtree_color_set(vdt, fd, TRUE); | |
694 if (fd) vdtree_dnd_drop_expand(vdt); | |
695 } | |
696 | |
697 vdt->drop_fd = fd; | |
698 } | |
699 | |
700 static void vdtree_dnd_drop_scroll_cancel(ViewDirTree *vdt) | |
701 { | |
702 if (vdt->drop_scroll_id != -1) g_source_remove(vdt->drop_scroll_id); | |
703 vdt->drop_scroll_id = -1; | |
704 } | |
705 | |
706 static gint vdtree_auto_scroll_idle_cb(gpointer data) | |
707 { | |
708 ViewDirTree *vdt = data; | |
709 | |
710 if (vdt->drop_fd) | |
711 { | |
712 GdkWindow *window; | |
713 gint x, y; | |
714 gint w, h; | |
715 | |
716 window = vdt->treeview->window; | |
717 gdk_window_get_pointer(window, &x, &y, NULL); | |
718 gdk_drawable_get_size(window, &w, &h); | |
719 if (x >= 0 && x < w && y >= 0 && y < h) | |
720 { | |
721 vdtree_drop_update(vdt, x, y); | |
722 } | |
723 } | |
724 | |
725 vdt->drop_scroll_id = -1; | |
726 return FALSE; | |
727 } | |
728 | |
729 static gint vdtree_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data) | |
730 { | |
731 ViewDirTree *vdt = data; | |
732 | |
733 if (!vdt->drop_fd || vdt->drop_list) return FALSE; | |
734 | |
735 if (vdt->drop_scroll_id == -1) vdt->drop_scroll_id = g_idle_add(vdtree_auto_scroll_idle_cb, vdt); | |
736 | |
737 return TRUE; | |
738 } | |
739 | |
740 static gint vdtree_dnd_drop_motion(GtkWidget *widget, GdkDragContext *context, | |
741 gint x, gint y, guint time, gpointer data) | |
742 { | |
743 ViewDirTree *vdt = data; | |
744 | |
745 vdt->click_fd = NULL; | |
746 | |
747 if (gtk_drag_get_source_widget(context) == vdt->treeview) | |
748 { | |
749 gdk_drag_status(context, 0, time); | |
750 return TRUE; | |
751 } | |
752 else | |
753 { | |
754 gdk_drag_status(context, context->suggested_action, time); | |
755 } | |
756 | |
757 vdtree_drop_update(vdt, x, y); | |
758 | |
759 if (vdt->drop_fd) | |
760 { | |
761 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vdt->treeview)); | |
762 widget_auto_scroll_start(vdt->treeview, adj, -1, -1, vdtree_auto_scroll_notify_cb, vdt); | |
763 } | |
764 | |
765 return FALSE; | |
766 } | |
767 | |
768 static void vdtree_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | |
769 { | |
770 ViewDirTree *vdt = data; | |
771 | |
772 if (vdt->drop_fd != vdt->click_fd) vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
773 | |
774 vdt->drop_fd = NULL; | |
775 | |
776 vdtree_dnd_drop_expand_cancel(vdt); | |
777 } | |
778 | |
779 static void vdtree_dnd_init(ViewDirTree *vdt) | |
780 { | |
781 gtk_drag_source_set(vdt->treeview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
782 dnd_file_drag_types, dnd_file_drag_types_count, | |
783 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); | |
784 g_signal_connect(G_OBJECT(vdt->treeview), "drag_data_get", | |
785 G_CALLBACK(vdtree_dnd_get), vdt); | |
786 g_signal_connect(G_OBJECT(vdt->treeview), "drag_begin", | |
787 G_CALLBACK(vdtree_dnd_begin), vdt); | |
788 g_signal_connect(G_OBJECT(vdt->treeview), "drag_end", | |
789 G_CALLBACK(vdtree_dnd_end), vdt); | |
790 | |
791 vdtree_dest_set(vdt, TRUE); | |
792 g_signal_connect(G_OBJECT(vdt->treeview), "drag_data_received", | |
793 G_CALLBACK(vdtree_dnd_drop_receive), vdt); | |
794 g_signal_connect(G_OBJECT(vdt->treeview), "drag_motion", | |
795 G_CALLBACK(vdtree_dnd_drop_motion), vdt); | |
796 g_signal_connect(G_OBJECT(vdt->treeview), "drag_leave", | |
797 G_CALLBACK(vdtree_dnd_drop_leave), vdt); | |
798 } | |
799 | |
800 /* | |
801 *---------------------------------------------------------------------------- | |
802 * parts lists | |
803 *---------------------------------------------------------------------------- | |
804 */ | |
805 | |
806 static GList *parts_list(const gchar *path) | |
807 { | |
808 GList *list = NULL; | |
809 const gchar *strb, *strp; | |
810 gint l; | |
811 | |
812 strp = path; | |
813 | |
814 if (*strp != '/') return NULL; | |
815 | |
816 strp++; | |
817 strb = strp; | |
818 l = 0; | |
819 | |
820 while (*strp != '\0') | |
821 { | |
822 if (*strp == '/') | |
823 { | |
824 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
825 strp++; | |
826 strb = strp; | |
827 l = 0; | |
828 } | |
829 else | |
830 { | |
831 strp++; | |
832 l++; | |
833 } | |
834 } | |
835 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
836 | |
837 list = g_list_reverse(list); | |
838 | |
839 list = g_list_prepend(list, g_strdup("/")); | |
840 | |
841 return list; | |
842 } | |
843 | |
844 static void parts_list_free(GList *list) | |
845 { | |
846 GList *work = list; | |
847 while (work) | |
848 { | |
849 PathData *pd = work->data; | |
850 g_free(pd->name); | |
851 g_free(pd); | |
852 work = work->next; | |
853 } | |
854 | |
855 g_list_free(list); | |
856 } | |
857 | |
858 static GList *parts_list_add_node_points(ViewDirTree *vdt, GList *list) | |
859 { | |
860 GList *work; | |
861 GtkTreeModel *store; | |
862 GtkTreeIter iter; | |
863 gint valid; | |
864 | |
865 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
866 valid = gtk_tree_model_get_iter_first(store, &iter); | |
867 | |
868 work = list; | |
869 while (work) | |
870 { | |
871 PathData *pd; | |
872 FileData *fd = NULL; | |
873 | |
874 pd = g_new0(PathData, 1); | |
875 pd->name = work->data; | |
876 | |
877 while (valid && !fd) | |
878 { | |
879 NodeData *nd; | |
880 | |
881 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
882 if (strcmp(nd->fd->name, pd->name) == 0) | |
883 { | |
884 fd = nd->fd; | |
885 } | |
886 else | |
887 { | |
888 valid = gtk_tree_model_iter_next(store, &iter); | |
889 } | |
890 } | |
891 | |
892 pd->node = fd; | |
893 work->data = pd; | |
894 | |
895 if (fd) | |
896 { | |
897 GtkTreeIter parent; | |
898 memcpy(&parent, &iter, sizeof(parent)); | |
899 valid = gtk_tree_model_iter_children(store, &iter, &parent); | |
900 } | |
901 | |
902 work = work->next; | |
903 } | |
904 | |
905 return list; | |
906 } | |
907 | |
908 /* | |
909 *---------------------------------------------------------------------------- | |
910 * misc | |
911 *---------------------------------------------------------------------------- | |
912 */ | |
913 | |
914 #if 0 | |
915 static void vdtree_row_deleted_cb(GtkTreeModel *tree_model, GtkTreePath *tpath, gpointer data) | |
916 { | |
917 GtkTreeIter iter; | |
918 NodeData *nd; | |
919 | |
920 gtk_tree_model_get_iter(tree_model, &iter, tpath); | |
921 gtk_tree_model_get(tree_model, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
922 | |
923 if (!nd) return; | |
924 | |
138 | 925 file_data_unref(nd->fd); |
9 | 926 g_free(nd); |
927 } | |
928 #endif | |
929 | |
930 /* | |
931 *---------------------------------------------------------------------------- | |
932 * node traversal, management | |
933 *---------------------------------------------------------------------------- | |
934 */ | |
935 | |
936 static gint vdtree_find_iter_by_data(ViewDirTree *vdt, GtkTreeIter *parent, NodeData *nd, GtkTreeIter *iter) | |
937 { | |
938 GtkTreeModel *store; | |
939 | |
940 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
941 if (!nd || !gtk_tree_model_iter_children(store, iter, parent)) return -1; | |
942 do { | |
943 NodeData *cnd; | |
944 | |
945 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &cnd, -1); | |
946 if (cnd == nd) return TRUE; | |
947 } while (gtk_tree_model_iter_next(store, iter)); | |
948 | |
949 return FALSE; | |
950 } | |
951 | |
952 static NodeData *vdtree_find_iter_by_name(ViewDirTree *vdt, GtkTreeIter *parent, const gchar *name, GtkTreeIter *iter) | |
953 { | |
954 GtkTreeModel *store; | |
955 | |
956 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
957 if (!name || !gtk_tree_model_iter_children(store, iter, parent)) return NULL; | |
958 do { | |
959 NodeData *nd; | |
960 | |
961 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
962 if (nd && strcmp(nd->fd->name, name) == 0) return nd; | |
963 } while (gtk_tree_model_iter_next(store, iter)); | |
964 | |
965 return NULL; | |
966 } | |
967 | |
968 static void vdtree_add_by_data(ViewDirTree *vdt, FileData *fd, GtkTreeIter *parent) | |
969 { | |
970 GtkTreeStore *store; | |
971 GtkTreeIter child; | |
972 NodeData *nd; | |
973 GdkPixbuf *pixbuf; | |
974 NodeData *end; | |
975 GtkTreeIter empty; | |
976 | |
977 if (!fd) return; | |
978 | |
979 if (access_file(fd->path, R_OK | X_OK)) | |
980 { | |
981 pixbuf = vdt->pf->close; | |
982 } | |
983 else | |
984 { | |
985 pixbuf = vdt->pf->deny; | |
986 } | |
987 | |
988 nd = g_new0(NodeData, 1); | |
989 nd->fd = fd; | |
990 nd->expanded = FALSE; | |
991 nd->last_update = time(NULL); | |
992 | |
993 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview))); | |
994 gtk_tree_store_append(store, &child, parent); | |
995 gtk_tree_store_set(store, &child, DIR_COLUMN_POINTER, nd, | |
996 DIR_COLUMN_ICON, pixbuf, | |
997 DIR_COLUMN_NAME, nd->fd->name, | |
998 DIR_COLUMN_COLOR, FALSE, -1); | |
999 | |
1000 /* all nodes are created with an "empty" node, so that the expander is shown | |
1001 * this is removed when the child is populated */ | |
1002 end = g_new0(NodeData, 1); | |
138 | 1003 end->fd = file_data_new_simple(""); |
9 | 1004 end->expanded = TRUE; |
1005 | |
1006 gtk_tree_store_append(store, &empty, &child); | |
1007 gtk_tree_store_set(store, &empty, DIR_COLUMN_POINTER, end, | |
1008 DIR_COLUMN_NAME, "empty", -1); | |
1009 | |
1010 if (parent) | |
1011 { | |
1012 NodeData *pnd; | |
1013 GtkTreePath *tpath; | |
1014 | |
1015 gtk_tree_model_get(GTK_TREE_MODEL(store), parent, DIR_COLUMN_POINTER, &pnd, -1); | |
1016 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent); | |
1017 if (tree_descend_subdirs && | |
1018 gtk_tree_view_row_expanded(GTK_TREE_VIEW(vdt->treeview), tpath) && | |
1019 !nd->expanded) | |
1020 { | |
1021 vdtree_populate_path_by_iter(vdt, &child, FALSE, vdt->path); | |
1022 } | |
1023 gtk_tree_path_free(tpath); | |
1024 } | |
1025 } | |
1026 | |
1027 static gint vdtree_populate_path_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, gint force, const gchar *target_path) | |
1028 { | |
1029 GtkTreeModel *store; | |
1030 GList *list; | |
1031 GList *work; | |
1032 GList *old; | |
1033 time_t current_time; | |
1034 GtkTreeIter child; | |
1035 NodeData *nd; | |
1036 | |
1037 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1038 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
1039 | |
1040 if (!nd) return FALSE; | |
1041 | |
1042 current_time = time(NULL); | |
1043 | |
1044 if (nd->expanded) | |
1045 { | |
1046 if (!force && current_time - nd->last_update < 10) return TRUE; | |
1047 if (!isdir(nd->fd->path)) | |
1048 { | |
1049 if (vdt->click_fd == nd->fd) vdt->click_fd = NULL; | |
1050 if (vdt->drop_fd == nd->fd) vdt->drop_fd = NULL; | |
1051 gtk_tree_store_remove(GTK_TREE_STORE(store), iter); | |
1052 vdtree_node_free(nd); | |
1053 return FALSE; | |
1054 } | |
1055 if (!force && filetime(nd->fd->path) == nd->fd->date) return TRUE; | |
1056 } | |
1057 | |
1058 vdtree_busy_push(vdt); | |
1059 | |
1060 list = NULL; | |
1061 filelist_read(nd->fd->path, NULL, &list); | |
1062 | |
1063 /* when hidden files are not enabled, and the user enters a hidden path, | |
1064 * allow the tree to display that path by specifically inserting the hidden entries | |
1065 */ | |
1066 if (!show_dot_files && | |
1067 target_path && | |
1068 strncmp(nd->fd->path, target_path, strlen(nd->fd->path)) == 0) | |
1069 { | |
1070 gint n; | |
1071 | |
1072 n = strlen(nd->fd->path); | |
1073 if (target_path[n] == '/' && target_path[n+1] == '.') | |
1074 { | |
1075 gchar *name8; | |
1076 gchar *namel; | |
1077 struct stat sbuf; | |
1078 | |
1079 n++; | |
1080 | |
1081 while (target_path[n] != '\0' && target_path[n] != '/') n++; | |
1082 name8 = g_strndup(target_path, n); | |
1083 | |
1084 if (stat_utf8(name8, &sbuf)) | |
1085 { | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
138
diff
changeset
|
1086 list = g_list_prepend(list, file_data_new_simple(name8)); |
9 | 1087 } |
1088 | |
1089 g_free(name8); | |
1090 } | |
1091 } | |
1092 | |
1093 old = NULL; | |
1094 if (gtk_tree_model_iter_children(store, &child, iter)) | |
1095 { | |
1096 do { | |
1097 NodeData *cnd; | |
1098 | |
1099 gtk_tree_model_get(store, &child, DIR_COLUMN_POINTER, &cnd, -1); | |
1100 old = g_list_prepend(old, cnd); | |
1101 } while (gtk_tree_model_iter_next(store, &child)); | |
1102 } | |
1103 | |
1104 work = list; | |
1105 while (work) | |
1106 { | |
1107 FileData *fd; | |
1108 | |
1109 fd = work->data; | |
1110 work = work->next; | |
1111 | |
1112 if (strcmp(fd->name, ".") == 0 || strcmp(fd->name, "..") == 0) | |
1113 { | |
138 | 1114 file_data_unref(fd); |
9 | 1115 } |
1116 else | |
1117 { | |
1118 NodeData *cnd; | |
1119 | |
1120 cnd = vdtree_find_iter_by_name(vdt, iter, fd->name, &child); | |
1121 if (cnd) | |
1122 { | |
1123 old = g_list_remove(old, cnd); | |
1124 if (cnd->expanded && cnd->fd->date != fd->date && | |
1125 vdtree_populate_path_by_iter(vdt, &child, FALSE, target_path)) | |
1126 { | |
1127 cnd->fd->size = fd->size; | |
1128 cnd->fd->date = fd->date; | |
1129 } | |
1130 | |
138 | 1131 file_data_unref(fd); |
9 | 1132 } |
1133 else | |
1134 { | |
1135 vdtree_add_by_data(vdt, fd, iter); | |
1136 } | |
1137 } | |
1138 } | |
1139 | |
1140 work = old; | |
1141 while (work) | |
1142 { | |
1143 NodeData *cnd = work->data; | |
1144 work = work->next; | |
1145 | |
1146 if (vdt->click_fd == cnd->fd) vdt->click_fd = NULL; | |
1147 if (vdt->drop_fd == cnd->fd) vdt->drop_fd = NULL; | |
1148 | |
1149 if (vdtree_find_iter_by_data(vdt, iter, cnd, &child)) | |
1150 { | |
1151 gtk_tree_store_remove(GTK_TREE_STORE(store), &child); | |
1152 vdtree_node_free(cnd); | |
1153 } | |
1154 } | |
1155 | |
1156 g_list_free(old); | |
1157 g_list_free(list); | |
1158 | |
1159 vdtree_busy_pop(vdt); | |
1160 | |
1161 nd->expanded = TRUE; | |
1162 nd->last_update = current_time; | |
1163 | |
1164 return TRUE; | |
1165 } | |
1166 | |
1167 static FileData *vdtree_populate_path(ViewDirTree *vdt, const gchar *path, gint expand, gint force) | |
1168 { | |
1169 GList *list; | |
1170 GList *work; | |
1171 FileData *fd = NULL; | |
1172 | |
1173 if (!path) return NULL; | |
1174 | |
1175 vdtree_busy_push(vdt); | |
1176 | |
1177 list = parts_list(path); | |
1178 list = parts_list_add_node_points(vdt, list); | |
1179 | |
1180 work = list; | |
1181 while (work) | |
1182 { | |
1183 PathData *pd = work->data; | |
1184 if (pd->node == NULL) | |
1185 { | |
1186 PathData *parent_pd; | |
1187 GtkTreeIter parent_iter; | |
1188 GtkTreeIter iter; | |
1189 NodeData *nd; | |
1190 | |
1191 if (work == list) | |
1192 { | |
1193 /* should not happen */ | |
1194 printf("vdtree warning, root node not found\n"); | |
1195 parts_list_free(list); | |
1196 vdtree_busy_pop(vdt); | |
1197 return NULL; | |
1198 } | |
1199 | |
1200 parent_pd = work->prev->data; | |
1201 | |
1202 if (!vdtree_find_row(vdt, parent_pd->node, &parent_iter, NULL) || | |
1203 !vdtree_populate_path_by_iter(vdt, &parent_iter, force, path) || | |
1204 (nd = vdtree_find_iter_by_name(vdt, &parent_iter, pd->name, &iter)) == NULL) | |
1205 { | |
1206 printf("vdtree warning, aborted at %s\n", parent_pd->name); | |
1207 parts_list_free(list); | |
1208 vdtree_busy_pop(vdt); | |
1209 return NULL; | |
1210 } | |
1211 | |
1212 pd->node = nd->fd; | |
1213 | |
1214 if (pd->node) | |
1215 { | |
1216 if (expand) | |
1217 { | |
1218 vdtree_expand_by_iter(vdt, &parent_iter, TRUE); | |
1219 vdtree_expand_by_iter(vdt, &iter, TRUE); | |
1220 } | |
1221 vdtree_populate_path_by_iter(vdt, &iter, force, path); | |
1222 } | |
1223 } | |
1224 else | |
1225 { | |
1226 GtkTreeIter iter; | |
1227 | |
1228 if (vdtree_find_row(vdt, pd->node, &iter, NULL)) | |
1229 { | |
1230 if (expand) vdtree_expand_by_iter(vdt, &iter, TRUE); | |
1231 vdtree_populate_path_by_iter(vdt, &iter, force, path); | |
1232 } | |
1233 } | |
1234 | |
1235 work = work->next; | |
1236 } | |
1237 | |
1238 work = g_list_last(list); | |
1239 if (work) | |
1240 { | |
1241 PathData *pd = work->data; | |
1242 fd = pd->node; | |
1243 } | |
1244 parts_list_free(list); | |
1245 | |
1246 vdtree_busy_pop(vdt); | |
1247 | |
1248 return fd; | |
1249 } | |
1250 | |
1251 /* | |
1252 *---------------------------------------------------------------------------- | |
1253 * access | |
1254 *---------------------------------------------------------------------------- | |
1255 */ | |
1256 | |
1257 static gint selection_is_ok = FALSE; | |
1258 | |
1259 static gboolean vdtree_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
1260 gboolean path_currently_selected, gpointer data) | |
1261 { | |
1262 return selection_is_ok; | |
1263 } | |
1264 | |
1265 static void vdtree_select_row(ViewDirTree *vdt, FileData *fd) | |
1266 { | |
1267 GtkTreeSelection *selection; | |
1268 GtkTreeIter iter; | |
1269 | |
1270 if (!vdtree_find_row(vdt, fd, &iter, NULL)) return; | |
1271 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdt->treeview)); | |
1272 | |
1273 /* hack, such that selection is only allowed to be changed from here */ | |
1274 selection_is_ok = TRUE; | |
1275 gtk_tree_selection_select_iter(selection, &iter); | |
1276 selection_is_ok = FALSE; | |
1277 | |
1278 if (!vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path)) return; | |
1279 | |
1280 vdtree_expand_by_iter(vdt, &iter, TRUE); | |
1281 | |
1282 if (fd && vdt->select_func) | |
1283 { | |
1284 vdt->select_func(vdt, fd->path, vdt->select_data); | |
1285 } | |
1286 } | |
1287 | |
1288 gint vdtree_set_path(ViewDirTree *vdt, const gchar *path) | |
1289 { | |
1290 FileData *fd; | |
1291 GtkTreeIter iter; | |
1292 | |
1293 if (!path) return FALSE; | |
1294 if (vdt->path && strcmp(path, vdt->path) == 0) return TRUE; | |
1295 | |
1296 g_free(vdt->path); | |
1297 vdt->path = g_strdup(path); | |
1298 | |
63
e29c291e106b
Mon Aug 15 16:35:15 2005 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1299 fd = vdtree_populate_path(vdt, vdt->path, TRUE, FALSE); |
9 | 1300 |
1301 if (!fd) return FALSE; | |
1302 | |
1303 if (vdtree_find_row(vdt, fd, &iter, NULL)) | |
1304 { | |
1305 GtkTreeModel *store; | |
1306 GtkTreePath *tpath; | |
1307 | |
1308 tree_view_row_make_visible(GTK_TREE_VIEW(vdt->treeview), &iter, TRUE); | |
1309 | |
1310 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1311 tpath = gtk_tree_model_get_path(store, &iter); | |
1312 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vdt->treeview), tpath, NULL, FALSE); | |
1313 gtk_tree_path_free(tpath); | |
1314 | |
1315 vdtree_select_row(vdt, fd); | |
1316 } | |
1317 | |
1318 return TRUE; | |
1319 } | |
1320 | |
1321 #if 0 | |
1322 const gchar *vdtree_get_path(ViewDirTree *vdt) | |
1323 { | |
1324 return vdt->path; | |
1325 } | |
1326 #endif | |
1327 | |
1328 void vdtree_refresh(ViewDirTree *vdt) | |
1329 { | |
1330 vdtree_populate_path(vdt, vdt->path, FALSE, TRUE); | |
1331 } | |
1332 | |
1333 const gchar *vdtree_row_get_path(ViewDirTree *vdt, gint row) | |
1334 { | |
1335 printf("FIXME: no get row path\n"); | |
1336 return NULL; | |
1337 } | |
1338 | |
1339 /* | |
1340 *---------------------------------------------------------------------------- | |
1341 * callbacks | |
1342 *---------------------------------------------------------------------------- | |
1343 */ | |
1344 | |
1345 static void vdtree_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
1346 { | |
1347 ViewDirTree *vdt = data; | |
1348 GtkTreeModel *store; | |
1349 GtkTreeIter iter; | |
1350 GtkTreePath *tpath; | |
1351 gint cw, ch; | |
1352 | |
1353 if (vdtree_find_row(vdt, vdt->click_fd, &iter, NULL) < 0) return; | |
1354 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1355 tpath = gtk_tree_model_get_path(store, &iter); | |
1356 tree_view_get_cell_clamped(GTK_TREE_VIEW(vdt->treeview), tpath, 0, TRUE, x, y, &cw, &ch); | |
1357 gtk_tree_path_free(tpath); | |
1358 *y += ch; | |
1359 popup_menu_position_clamp(menu, x, y, 0); | |
1360 } | |
1361 | |
1362 static gint vdtree_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
1363 { | |
1364 ViewDirTree *vdt = data; | |
1365 GtkTreePath *tpath; | |
1366 GtkTreeIter iter; | |
1367 FileData *fd = NULL; | |
1368 | |
1369 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vdt->treeview), &tpath, NULL); | |
1370 if (tpath) | |
1371 { | |
1372 GtkTreeModel *store; | |
1373 NodeData *nd; | |
1374 | |
1375 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1376 gtk_tree_model_get_iter(store, &iter, tpath); | |
1377 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1378 | |
1379 gtk_tree_path_free(tpath); | |
1380 | |
1381 fd = (nd) ? nd->fd : NULL; | |
1382 } | |
1383 | |
1384 switch (event->keyval) | |
1385 { | |
1386 case GDK_Menu: | |
1387 vdt->click_fd = fd; | |
1388 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
1389 | |
1390 vdt->popup = vdtree_pop_menu(vdt, vdt->click_fd); | |
1391 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, vdtree_menu_position_cb, vdt, 0, GDK_CURRENT_TIME); | |
1392 | |
1393 return TRUE; | |
1394 break; | |
1395 case GDK_plus: | |
1396 case GDK_Right: | |
1397 case GDK_KP_Add: | |
1398 if (fd) | |
1399 { | |
1400 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
1401 vdtree_icon_set_by_iter(vdt, &iter, vdt->pf->open); | |
1402 } | |
1403 break; | |
1404 } | |
1405 | |
1406 return FALSE; | |
1407 } | |
1408 | |
1409 static gint vdtree_clicked_on_expander(GtkTreeView *treeview, GtkTreePath *tpath, | |
1410 GtkTreeViewColumn *column, gint x, gint y, gint *left_of_expander) | |
1411 { | |
1412 gint depth; | |
1413 gint size; | |
1414 gint sep; | |
1415 gint exp_width; | |
1416 | |
1417 if (column != gtk_tree_view_get_expander_column(treeview)) return FALSE; | |
1418 | |
1419 gtk_widget_style_get(GTK_WIDGET(treeview), "expander-size", &size, "horizontal-separator", &sep, NULL); | |
1420 depth = gtk_tree_path_get_depth(tpath); | |
1421 | |
1422 exp_width = sep + size + sep; | |
1423 | |
1424 if (x <= depth * exp_width) | |
1425 { | |
1426 if (left_of_expander) *left_of_expander = !(x >= (depth - 1) * exp_width); | |
1427 return TRUE; | |
1428 } | |
1429 | |
1430 return FALSE; | |
1431 } | |
1432 | |
1433 static gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1434 { | |
1435 ViewDirTree *vdt = data; | |
1436 GtkTreePath *tpath; | |
1437 GtkTreeViewColumn *column; | |
1438 GtkTreeIter iter; | |
1439 NodeData *nd = NULL; | |
1440 | |
1441 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1442 &tpath, &column, NULL, NULL)) | |
1443 { | |
1444 GtkTreeModel *store; | |
1445 gint left_of_expander; | |
1446 | |
1447 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1448 gtk_tree_model_get_iter(store, &iter, tpath); | |
1449 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1450 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1451 | |
1452 if (vdtree_clicked_on_expander(GTK_TREE_VIEW(widget), tpath, column, bevent->x, bevent->y, &left_of_expander)) | |
1453 { | |
1454 vdt->click_fd = NULL; | |
1455 | |
1456 /* clicking this region should automatically reveal an expander, if necessary | |
1457 * treeview bug: the expander will not expand until a button_motion_event highlights it. | |
1458 */ | |
1459 if (bevent->button == 1 && | |
1460 !left_of_expander && | |
1461 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vdt->treeview), tpath)) | |
1462 { | |
1463 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
1464 vdtree_icon_set_by_iter(vdt, &iter, vdt->pf->open); | |
1465 } | |
1466 | |
1467 gtk_tree_path_free(tpath); | |
1468 return FALSE; | |
1469 } | |
1470 | |
1471 gtk_tree_path_free(tpath); | |
1472 } | |
1473 | |
1474 vdt->click_fd = (nd) ? nd->fd : NULL; | |
1475 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
1476 | |
1477 if (bevent->button == 3) | |
1478 { | |
1479 vdt->popup = vdtree_pop_menu(vdt, vdt->click_fd); | |
1480 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, NULL, NULL, | |
1481 bevent->button, bevent->time); | |
1482 } | |
1483 | |
1484 return (bevent->button != 1); | |
1485 } | |
1486 | |
1487 static gint vdtree_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1488 { | |
1489 ViewDirTree *vdt = data; | |
1490 GtkTreePath *tpath; | |
1491 GtkTreeIter iter; | |
1492 NodeData *nd = NULL; | |
1493 | |
1494 if (!vdt->click_fd) return FALSE; | |
1495 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
1496 | |
1497 if (bevent->button != 1) return TRUE; | |
1498 | |
1499 if ((bevent->x != 0 || bevent->y != 0) && | |
1500 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1501 &tpath, NULL, NULL, NULL)) | |
1502 { | |
1503 GtkTreeModel *store; | |
1504 | |
1505 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1506 gtk_tree_model_get_iter(store, &iter, tpath); | |
1507 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1508 gtk_tree_path_free(tpath); | |
1509 } | |
1510 | |
1511 if (nd && vdt->click_fd == nd->fd) | |
1512 { | |
1513 vdtree_select_row(vdt, vdt->click_fd); | |
1514 } | |
1515 | |
1516 return FALSE; | |
1517 } | |
1518 | |
1519 static void vdtree_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
1520 { | |
1521 ViewDirTree *vdt = data; | |
1522 | |
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1523 vdtree_populate_path_by_iter(vdt, iter, FALSE, NULL); |
9 | 1524 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->open); |
1525 } | |
1526 | |
1527 static void vdtree_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
1528 { | |
1529 ViewDirTree *vdt = data; | |
1530 | |
1531 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->close); | |
1532 } | |
1533 | |
1534 static gint vdtree_sort_cb(GtkTreeModel *store, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
1535 { | |
1536 NodeData *nda; | |
1537 NodeData *ndb; | |
1538 | |
1539 gtk_tree_model_get(store, a, DIR_COLUMN_POINTER, &nda, -1); | |
1540 gtk_tree_model_get(store, b, DIR_COLUMN_POINTER, &ndb, -1); | |
1541 | |
1542 return CASE_SORT(nda->fd->name, ndb->fd->name); | |
1543 } | |
1544 | |
1545 /* | |
1546 *---------------------------------------------------------------------------- | |
1547 * core | |
1548 *---------------------------------------------------------------------------- | |
1549 */ | |
1550 | |
1551 static void vdtree_setup_root(ViewDirTree *vdt) | |
1552 { | |
1553 const gchar *path = "/"; | |
1554 FileData *fd; | |
1555 | |
138 | 1556 |
1557 fd = file_data_new_simple(path); | |
9 | 1558 vdtree_add_by_data(vdt, fd, NULL); |
1559 | |
1560 vdtree_expand_by_data(vdt, fd, TRUE); | |
1561 vdtree_populate_path(vdt, path, FALSE, FALSE); | |
1562 } | |
1563 | |
1564 static void vdtree_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
1565 { | |
1566 ViewDirTree *vdt = data; | |
1567 GtkTreeModel *store; | |
1568 GtkTreeIter iter; | |
1569 NodeData *nd; | |
1570 | |
1571 store = gtk_tree_view_get_model(tview); | |
1572 gtk_tree_model_get_iter(store, &iter, tpath); | |
1573 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1574 | |
1575 vdtree_select_row(vdt, nd->fd); | |
1576 } | |
1577 | |
1578 static GdkColor *vdtree_color_shifted(GtkWidget *widget) | |
1579 { | |
1580 static GdkColor color; | |
1581 static GtkWidget *done = NULL; | |
1582 | |
1583 if (done != widget) | |
1584 { | |
1585 GtkStyle *style; | |
1586 | |
1587 style = gtk_widget_get_style(widget); | |
1588 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
1589 shift_color(&color, -1, 0); | |
1590 done = widget; | |
1591 } | |
1592 | |
1593 return &color; | |
1594 } | |
1595 | |
1596 static void vdtree_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
1597 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
1598 { | |
1599 ViewDirTree *vdt = data; | |
1600 gboolean set; | |
1601 | |
1602 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1); | |
1603 g_object_set(G_OBJECT(cell), | |
1604 "cell-background-gdk", vdtree_color_shifted(vdt->treeview), | |
1605 "cell-background-set", set, NULL); | |
1606 } | |
1607 | |
1608 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
1609 { | |
1610 NodeData *nd; | |
1611 | |
1612 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
1613 vdtree_node_free(nd); | |
1614 | |
1615 return FALSE; | |
1616 } | |
1617 | |
1618 static void vdtree_destroy_cb(GtkWidget *widget, gpointer data) | |
1619 { | |
1620 ViewDirTree *vdt = data; | |
1621 GtkTreeModel *store; | |
1622 | |
1623 if (vdt->popup) | |
1624 { | |
1625 g_signal_handlers_disconnect_matched(G_OBJECT(vdt->popup), G_SIGNAL_MATCH_DATA, | |
1626 0, 0, 0, NULL, vdt); | |
1627 gtk_widget_destroy(vdt->popup); | |
1628 } | |
1629 | |
1630 vdtree_dnd_drop_expand_cancel(vdt); | |
1631 vdtree_dnd_drop_scroll_cancel(vdt); | |
1632 widget_auto_scroll_stop(vdt->treeview); | |
1633 | |
1634 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1635 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vdt); | |
1636 | |
138 | 1637 filelist_free(vdt->drop_list); |
9 | 1638 |
1639 folder_icons_free(vdt->pf); | |
1640 | |
1641 g_free(vdt->path); | |
1642 g_free(vdt); | |
1643 } | |
1644 | |
1645 ViewDirTree *vdtree_new(const gchar *path, gint expand) | |
1646 { | |
1647 ViewDirTree *vdt; | |
1648 GtkTreeStore *store; | |
1649 GtkTreeSelection *selection; | |
1650 GtkTreeViewColumn *column; | |
1651 GtkCellRenderer *renderer; | |
1652 | |
1653 vdt = g_new0(ViewDirTree, 1); | |
1654 | |
1655 vdt->path = NULL; | |
1656 vdt->click_fd = NULL; | |
1657 | |
1658 vdt->drop_fd = NULL; | |
1659 vdt->drop_list = NULL; | |
1660 vdt->drop_scroll_id = -1; | |
1661 vdt->drop_expand_id = -1; | |
1662 | |
1663 vdt->popup = NULL; | |
1664 | |
1665 vdt->busy_ref = 0; | |
1666 | |
1667 vdt->widget = gtk_scrolled_window_new(NULL, NULL); | |
1668 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vdt->widget), GTK_SHADOW_IN); | |
1669 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vdt->widget), | |
1670 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1671 g_signal_connect(G_OBJECT(vdt->widget), "destroy", | |
1672 G_CALLBACK(vdtree_destroy_cb), vdt); | |
1673 | |
1674 store = gtk_tree_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); | |
1675 vdt->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1676 g_object_unref(store); | |
1677 | |
1678 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vdt->treeview), FALSE); | |
1679 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vdt->treeview), FALSE); | |
1680 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vdt, NULL); | |
1681 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), | |
1682 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); | |
1683 | |
1684 g_signal_connect(G_OBJECT(vdt->treeview), "row_activated", | |
1685 G_CALLBACK(vdtree_activate_cb), vdt); | |
1686 g_signal_connect(G_OBJECT(vdt->treeview), "row_expanded", | |
1687 G_CALLBACK(vdtree_row_expanded), vdt); | |
1688 g_signal_connect(G_OBJECT(vdt->treeview), "row_collapsed", | |
1689 G_CALLBACK(vdtree_row_collapsed), vdt); | |
1690 #if 0 | |
1691 g_signal_connect(G_OBJECT(store), "row_deleted", | |
1692 G_CALLBACK(vdtree_row_deleted_cb), vdt); | |
1693 #endif | |
1694 | |
1695 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdt->treeview)); | |
1696 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
1697 gtk_tree_selection_set_select_function(selection, vdtree_select_cb, vdt, NULL); | |
1698 | |
1699 column = gtk_tree_view_column_new(); | |
1700 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
1701 | |
1702 renderer = gtk_cell_renderer_pixbuf_new(); | |
1703 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1704 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
1705 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vdt, NULL); | |
1706 | |
1707 renderer = gtk_cell_renderer_text_new(); | |
1708 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1709 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
1710 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vdt, NULL); | |
1711 | |
1712 gtk_tree_view_append_column(GTK_TREE_VIEW(vdt->treeview), column); | |
1713 | |
1714 g_signal_connect(G_OBJECT(vdt->treeview), "key_press_event", | |
1715 G_CALLBACK(vdtree_press_key_cb), vdt); | |
1716 | |
1717 gtk_container_add(GTK_CONTAINER(vdt->widget), vdt->treeview); | |
1718 gtk_widget_show(vdt->treeview); | |
1719 | |
1720 vdt->pf = folder_icons_new(); | |
1721 | |
1722 vdtree_setup_root(vdt); | |
1723 | |
1724 vdtree_dnd_init(vdt); | |
1725 | |
1726 g_signal_connect(G_OBJECT(vdt->treeview), "button_press_event", | |
1727 G_CALLBACK(vdtree_press_cb), vdt); | |
1728 g_signal_connect(G_OBJECT(vdt->treeview), "button_release_event", | |
1729 G_CALLBACK(vdtree_release_cb), vdt); | |
1730 | |
1731 vdtree_set_path(vdt, path); | |
1732 | |
1733 return vdt; | |
1734 } | |
1735 | |
1736 void vdtree_set_select_func(ViewDirTree *vdt, | |
1737 void (*func)(ViewDirTree *vdt, const gchar *path, gpointer data), gpointer data) | |
1738 { | |
1739 vdt->select_func = func; | |
1740 vdt->select_data = data; | |
1741 } | |
1742 | |
1743 #if 0 | |
1744 void vdtree_set_click_func(ViewDirTree *vdt, | |
1745 void (*func)(ViewDirTree *vdt, GdkEventButton *event, FileData *fd, gpointer), gpointer data) | |
1746 { | |
1747 if (!td) return; | |
1748 vdt->click_func = func; | |
1749 vdt->click_data = data; | |
1750 } | |
1751 #endif | |
1752 | |
1753 void vdtree_set_layout(ViewDirTree *vdt, LayoutWindow *layout) | |
1754 { | |
1755 vdt->layout = layout; | |
1756 } | |
1757 |