Mercurial > geeqie.yaz
annotate src/view_dir_tree.c @ 319:f9611a6cf0e2
Move file_sort_case_sensitive to ConfOptions.
author | zas_ |
---|---|
date | Fri, 11 Apr 2008 22:27:54 +0000 |
parents | b16b9b8979e5 |
children | c74af1cbd61a |
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 | |
281 | 12 #include "main.h" |
9 | 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 GList *list; | |
555 gchar *uri_text = NULL; | |
556 gint length = 0; | |
557 | |
558 if (!vdt->click_fd) return; | |
559 | |
560 switch (info) | |
561 { | |
562 case TARGET_URI_LIST: | |
563 case TARGET_TEXT_PLAIN: | |
138 | 564 list = g_list_prepend(NULL, vdt->click_fd); |
565 uri_text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN)); | |
9 | 566 g_list_free(list); |
567 break; | |
568 } | |
569 | |
570 if (uri_text) | |
571 { | |
572 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
|
573 8, (guchar *)uri_text, length); |
9 | 574 g_free(uri_text); |
575 } | |
576 } | |
577 | |
578 static void vdtree_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
579 { | |
580 ViewDirTree *vdt = data; | |
581 | |
582 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
583 vdtree_dest_set(vdt, FALSE); | |
584 } | |
585 | |
586 static void vdtree_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
587 { | |
588 ViewDirTree *vdt = data; | |
589 | |
590 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
591 vdtree_dest_set(vdt, TRUE); | |
592 } | |
593 | |
594 static void vdtree_dnd_drop_receive(GtkWidget *widget, | |
595 GdkDragContext *context, gint x, gint y, | |
596 GtkSelectionData *selection_data, guint info, | |
597 guint time, gpointer data) | |
598 { | |
599 ViewDirTree *vdt = data; | |
600 GtkTreePath *tpath; | |
601 GtkTreeIter iter; | |
602 FileData *fd = NULL; | |
603 | |
604 vdt->click_fd = NULL; | |
605 | |
606 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, | |
607 &tpath, NULL, NULL, NULL)) | |
608 { | |
609 GtkTreeModel *store; | |
610 NodeData *nd; | |
611 | |
612 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
613 gtk_tree_model_get_iter(store, &iter, tpath); | |
614 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
615 gtk_tree_path_free(tpath); | |
616 | |
617 fd = (nd) ? nd->fd : NULL; | |
618 } | |
619 | |
620 if (!fd) return; | |
621 | |
622 if (info == TARGET_URI_LIST) | |
623 { | |
624 GList *list; | |
625 gint active; | |
626 | |
138 | 627 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); |
9 | 628 if (!list) return; |
629 | |
630 active = access_file(fd->path, W_OK | X_OK); | |
631 | |
632 vdtree_color_set(vdt, fd, TRUE); | |
633 vdt->popup = vdtree_drop_menu(vdt, active); | |
634 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, NULL, NULL, 0, time); | |
635 | |
636 vdt->drop_fd = fd; | |
637 vdt->drop_list = list; | |
638 } | |
639 } | |
640 | |
641 static gint vdtree_dnd_drop_expand_cb(gpointer data) | |
642 { | |
643 ViewDirTree *vdt = data; | |
644 GtkTreeIter iter; | |
645 | |
646 if (vdt->drop_fd && | |
647 vdtree_find_row(vdt, vdt->drop_fd, &iter, NULL)) | |
648 { | |
649 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
650 vdtree_expand_by_data(vdt, vdt->drop_fd, TRUE); | |
651 } | |
652 | |
653 vdt->drop_expand_id = -1; | |
654 return FALSE; | |
655 } | |
656 | |
657 static void vdtree_dnd_drop_expand_cancel(ViewDirTree *vdt) | |
658 { | |
659 if (vdt->drop_expand_id != -1) g_source_remove(vdt->drop_expand_id); | |
660 vdt->drop_expand_id = -1; | |
661 } | |
662 | |
663 static void vdtree_dnd_drop_expand(ViewDirTree *vdt) | |
664 { | |
665 vdtree_dnd_drop_expand_cancel(vdt); | |
666 vdt->drop_expand_id = g_timeout_add(1000, vdtree_dnd_drop_expand_cb, vdt); | |
667 } | |
668 | |
669 static void vdtree_drop_update(ViewDirTree *vdt, gint x, gint y) | |
670 { | |
671 GtkTreePath *tpath; | |
672 GtkTreeIter iter; | |
673 FileData *fd = NULL; | |
674 | |
675 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vdt->treeview), x, y, | |
676 &tpath, NULL, NULL, NULL)) | |
677 { | |
678 GtkTreeModel *store; | |
679 NodeData *nd; | |
680 | |
681 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
682 gtk_tree_model_get_iter(store, &iter, tpath); | |
683 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
684 gtk_tree_path_free(tpath); | |
685 | |
686 fd = (nd) ? nd->fd : NULL; | |
687 } | |
688 | |
689 if (fd != vdt->drop_fd) | |
690 { | |
691 vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
692 vdtree_color_set(vdt, fd, TRUE); | |
693 if (fd) vdtree_dnd_drop_expand(vdt); | |
694 } | |
695 | |
696 vdt->drop_fd = fd; | |
697 } | |
698 | |
699 static void vdtree_dnd_drop_scroll_cancel(ViewDirTree *vdt) | |
700 { | |
701 if (vdt->drop_scroll_id != -1) g_source_remove(vdt->drop_scroll_id); | |
702 vdt->drop_scroll_id = -1; | |
703 } | |
704 | |
705 static gint vdtree_auto_scroll_idle_cb(gpointer data) | |
706 { | |
707 ViewDirTree *vdt = data; | |
708 | |
709 if (vdt->drop_fd) | |
710 { | |
711 GdkWindow *window; | |
712 gint x, y; | |
713 gint w, h; | |
714 | |
715 window = vdt->treeview->window; | |
716 gdk_window_get_pointer(window, &x, &y, NULL); | |
717 gdk_drawable_get_size(window, &w, &h); | |
718 if (x >= 0 && x < w && y >= 0 && y < h) | |
719 { | |
720 vdtree_drop_update(vdt, x, y); | |
721 } | |
722 } | |
723 | |
724 vdt->drop_scroll_id = -1; | |
725 return FALSE; | |
726 } | |
727 | |
728 static gint vdtree_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data) | |
729 { | |
730 ViewDirTree *vdt = data; | |
731 | |
732 if (!vdt->drop_fd || vdt->drop_list) return FALSE; | |
733 | |
734 if (vdt->drop_scroll_id == -1) vdt->drop_scroll_id = g_idle_add(vdtree_auto_scroll_idle_cb, vdt); | |
735 | |
736 return TRUE; | |
737 } | |
738 | |
739 static gint vdtree_dnd_drop_motion(GtkWidget *widget, GdkDragContext *context, | |
740 gint x, gint y, guint time, gpointer data) | |
741 { | |
742 ViewDirTree *vdt = data; | |
743 | |
744 vdt->click_fd = NULL; | |
745 | |
746 if (gtk_drag_get_source_widget(context) == vdt->treeview) | |
747 { | |
748 gdk_drag_status(context, 0, time); | |
749 return TRUE; | |
750 } | |
751 else | |
752 { | |
753 gdk_drag_status(context, context->suggested_action, time); | |
754 } | |
755 | |
756 vdtree_drop_update(vdt, x, y); | |
757 | |
758 if (vdt->drop_fd) | |
759 { | |
760 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vdt->treeview)); | |
761 widget_auto_scroll_start(vdt->treeview, adj, -1, -1, vdtree_auto_scroll_notify_cb, vdt); | |
762 } | |
763 | |
764 return FALSE; | |
765 } | |
766 | |
767 static void vdtree_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | |
768 { | |
769 ViewDirTree *vdt = data; | |
770 | |
771 if (vdt->drop_fd != vdt->click_fd) vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
772 | |
773 vdt->drop_fd = NULL; | |
774 | |
775 vdtree_dnd_drop_expand_cancel(vdt); | |
776 } | |
777 | |
778 static void vdtree_dnd_init(ViewDirTree *vdt) | |
779 { | |
780 gtk_drag_source_set(vdt->treeview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
781 dnd_file_drag_types, dnd_file_drag_types_count, | |
782 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); | |
783 g_signal_connect(G_OBJECT(vdt->treeview), "drag_data_get", | |
784 G_CALLBACK(vdtree_dnd_get), vdt); | |
785 g_signal_connect(G_OBJECT(vdt->treeview), "drag_begin", | |
786 G_CALLBACK(vdtree_dnd_begin), vdt); | |
787 g_signal_connect(G_OBJECT(vdt->treeview), "drag_end", | |
788 G_CALLBACK(vdtree_dnd_end), vdt); | |
789 | |
790 vdtree_dest_set(vdt, TRUE); | |
791 g_signal_connect(G_OBJECT(vdt->treeview), "drag_data_received", | |
792 G_CALLBACK(vdtree_dnd_drop_receive), vdt); | |
793 g_signal_connect(G_OBJECT(vdt->treeview), "drag_motion", | |
794 G_CALLBACK(vdtree_dnd_drop_motion), vdt); | |
795 g_signal_connect(G_OBJECT(vdt->treeview), "drag_leave", | |
796 G_CALLBACK(vdtree_dnd_drop_leave), vdt); | |
797 } | |
798 | |
799 /* | |
800 *---------------------------------------------------------------------------- | |
801 * parts lists | |
802 *---------------------------------------------------------------------------- | |
803 */ | |
804 | |
805 static GList *parts_list(const gchar *path) | |
806 { | |
807 GList *list = NULL; | |
808 const gchar *strb, *strp; | |
809 gint l; | |
810 | |
811 strp = path; | |
812 | |
813 if (*strp != '/') return NULL; | |
814 | |
815 strp++; | |
816 strb = strp; | |
817 l = 0; | |
818 | |
819 while (*strp != '\0') | |
820 { | |
821 if (*strp == '/') | |
822 { | |
823 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
824 strp++; | |
825 strb = strp; | |
826 l = 0; | |
827 } | |
828 else | |
829 { | |
830 strp++; | |
831 l++; | |
832 } | |
833 } | |
834 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
835 | |
836 list = g_list_reverse(list); | |
837 | |
838 list = g_list_prepend(list, g_strdup("/")); | |
839 | |
840 return list; | |
841 } | |
842 | |
843 static void parts_list_free(GList *list) | |
844 { | |
845 GList *work = list; | |
846 while (work) | |
847 { | |
848 PathData *pd = work->data; | |
849 g_free(pd->name); | |
850 g_free(pd); | |
851 work = work->next; | |
852 } | |
853 | |
854 g_list_free(list); | |
855 } | |
856 | |
857 static GList *parts_list_add_node_points(ViewDirTree *vdt, GList *list) | |
858 { | |
859 GList *work; | |
860 GtkTreeModel *store; | |
861 GtkTreeIter iter; | |
862 gint valid; | |
863 | |
864 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
865 valid = gtk_tree_model_get_iter_first(store, &iter); | |
866 | |
867 work = list; | |
868 while (work) | |
869 { | |
870 PathData *pd; | |
871 FileData *fd = NULL; | |
872 | |
873 pd = g_new0(PathData, 1); | |
874 pd->name = work->data; | |
875 | |
876 while (valid && !fd) | |
877 { | |
878 NodeData *nd; | |
879 | |
880 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
881 if (strcmp(nd->fd->name, pd->name) == 0) | |
882 { | |
883 fd = nd->fd; | |
884 } | |
885 else | |
886 { | |
887 valid = gtk_tree_model_iter_next(store, &iter); | |
888 } | |
889 } | |
890 | |
891 pd->node = fd; | |
892 work->data = pd; | |
893 | |
894 if (fd) | |
895 { | |
896 GtkTreeIter parent; | |
897 memcpy(&parent, &iter, sizeof(parent)); | |
898 valid = gtk_tree_model_iter_children(store, &iter, &parent); | |
899 } | |
900 | |
901 work = work->next; | |
902 } | |
903 | |
904 return list; | |
905 } | |
906 | |
907 /* | |
908 *---------------------------------------------------------------------------- | |
909 * misc | |
910 *---------------------------------------------------------------------------- | |
911 */ | |
912 | |
913 #if 0 | |
914 static void vdtree_row_deleted_cb(GtkTreeModel *tree_model, GtkTreePath *tpath, gpointer data) | |
915 { | |
916 GtkTreeIter iter; | |
917 NodeData *nd; | |
918 | |
919 gtk_tree_model_get_iter(tree_model, &iter, tpath); | |
920 gtk_tree_model_get(tree_model, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
921 | |
922 if (!nd) return; | |
923 | |
138 | 924 file_data_unref(nd->fd); |
9 | 925 g_free(nd); |
926 } | |
927 #endif | |
928 | |
929 /* | |
930 *---------------------------------------------------------------------------- | |
931 * node traversal, management | |
932 *---------------------------------------------------------------------------- | |
933 */ | |
934 | |
935 static gint vdtree_find_iter_by_data(ViewDirTree *vdt, GtkTreeIter *parent, NodeData *nd, GtkTreeIter *iter) | |
936 { | |
937 GtkTreeModel *store; | |
938 | |
939 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
940 if (!nd || !gtk_tree_model_iter_children(store, iter, parent)) return -1; | |
941 do { | |
942 NodeData *cnd; | |
943 | |
944 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &cnd, -1); | |
945 if (cnd == nd) return TRUE; | |
946 } while (gtk_tree_model_iter_next(store, iter)); | |
947 | |
948 return FALSE; | |
949 } | |
950 | |
951 static NodeData *vdtree_find_iter_by_name(ViewDirTree *vdt, GtkTreeIter *parent, const gchar *name, GtkTreeIter *iter) | |
952 { | |
953 GtkTreeModel *store; | |
954 | |
955 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
956 if (!name || !gtk_tree_model_iter_children(store, iter, parent)) return NULL; | |
957 do { | |
958 NodeData *nd; | |
959 | |
960 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
961 if (nd && strcmp(nd->fd->name, name) == 0) return nd; | |
962 } while (gtk_tree_model_iter_next(store, iter)); | |
963 | |
964 return NULL; | |
965 } | |
966 | |
967 static void vdtree_add_by_data(ViewDirTree *vdt, FileData *fd, GtkTreeIter *parent) | |
968 { | |
969 GtkTreeStore *store; | |
970 GtkTreeIter child; | |
971 NodeData *nd; | |
972 GdkPixbuf *pixbuf; | |
973 NodeData *end; | |
974 GtkTreeIter empty; | |
975 | |
976 if (!fd) return; | |
977 | |
978 if (access_file(fd->path, R_OK | X_OK)) | |
979 { | |
980 pixbuf = vdt->pf->close; | |
981 } | |
982 else | |
983 { | |
984 pixbuf = vdt->pf->deny; | |
985 } | |
986 | |
987 nd = g_new0(NodeData, 1); | |
988 nd->fd = fd; | |
989 nd->expanded = FALSE; | |
990 nd->last_update = time(NULL); | |
991 | |
992 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview))); | |
993 gtk_tree_store_append(store, &child, parent); | |
994 gtk_tree_store_set(store, &child, DIR_COLUMN_POINTER, nd, | |
995 DIR_COLUMN_ICON, pixbuf, | |
996 DIR_COLUMN_NAME, nd->fd->name, | |
997 DIR_COLUMN_COLOR, FALSE, -1); | |
998 | |
999 /* all nodes are created with an "empty" node, so that the expander is shown | |
1000 * this is removed when the child is populated */ | |
1001 end = g_new0(NodeData, 1); | |
138 | 1002 end->fd = file_data_new_simple(""); |
9 | 1003 end->expanded = TRUE; |
1004 | |
1005 gtk_tree_store_append(store, &empty, &child); | |
1006 gtk_tree_store_set(store, &empty, DIR_COLUMN_POINTER, end, | |
1007 DIR_COLUMN_NAME, "empty", -1); | |
1008 | |
1009 if (parent) | |
1010 { | |
1011 NodeData *pnd; | |
1012 GtkTreePath *tpath; | |
1013 | |
1014 gtk_tree_model_get(GTK_TREE_MODEL(store), parent, DIR_COLUMN_POINTER, &pnd, -1); | |
1015 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent); | |
1016 if (tree_descend_subdirs && | |
1017 gtk_tree_view_row_expanded(GTK_TREE_VIEW(vdt->treeview), tpath) && | |
1018 !nd->expanded) | |
1019 { | |
1020 vdtree_populate_path_by_iter(vdt, &child, FALSE, vdt->path); | |
1021 } | |
1022 gtk_tree_path_free(tpath); | |
1023 } | |
1024 } | |
1025 | |
1026 static gint vdtree_populate_path_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, gint force, const gchar *target_path) | |
1027 { | |
1028 GtkTreeModel *store; | |
1029 GList *list; | |
1030 GList *work; | |
1031 GList *old; | |
1032 time_t current_time; | |
1033 GtkTreeIter child; | |
1034 NodeData *nd; | |
1035 | |
1036 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1037 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
1038 | |
1039 if (!nd) return FALSE; | |
1040 | |
1041 current_time = time(NULL); | |
1042 | |
1043 if (nd->expanded) | |
1044 { | |
1045 if (!force && current_time - nd->last_update < 10) return TRUE; | |
1046 if (!isdir(nd->fd->path)) | |
1047 { | |
1048 if (vdt->click_fd == nd->fd) vdt->click_fd = NULL; | |
1049 if (vdt->drop_fd == nd->fd) vdt->drop_fd = NULL; | |
1050 gtk_tree_store_remove(GTK_TREE_STORE(store), iter); | |
1051 vdtree_node_free(nd); | |
1052 return FALSE; | |
1053 } | |
1054 if (!force && filetime(nd->fd->path) == nd->fd->date) return TRUE; | |
1055 } | |
1056 | |
1057 vdtree_busy_push(vdt); | |
1058 | |
1059 list = NULL; | |
1060 filelist_read(nd->fd->path, NULL, &list); | |
1061 | |
1062 /* when hidden files are not enabled, and the user enters a hidden path, | |
1063 * allow the tree to display that path by specifically inserting the hidden entries | |
1064 */ | |
318 | 1065 if (!options->show_dot_files && |
9 | 1066 target_path && |
1067 strncmp(nd->fd->path, target_path, strlen(nd->fd->path)) == 0) | |
1068 { | |
1069 gint n; | |
1070 | |
1071 n = strlen(nd->fd->path); | |
1072 if (target_path[n] == '/' && target_path[n+1] == '.') | |
1073 { | |
1074 gchar *name8; | |
1075 struct stat sbuf; | |
1076 | |
1077 n++; | |
1078 | |
1079 while (target_path[n] != '\0' && target_path[n] != '/') n++; | |
1080 name8 = g_strndup(target_path, n); | |
1081 | |
1082 if (stat_utf8(name8, &sbuf)) | |
1083 { | |
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
138
diff
changeset
|
1084 list = g_list_prepend(list, file_data_new_simple(name8)); |
9 | 1085 } |
1086 | |
1087 g_free(name8); | |
1088 } | |
1089 } | |
1090 | |
1091 old = NULL; | |
1092 if (gtk_tree_model_iter_children(store, &child, iter)) | |
1093 { | |
1094 do { | |
1095 NodeData *cnd; | |
1096 | |
1097 gtk_tree_model_get(store, &child, DIR_COLUMN_POINTER, &cnd, -1); | |
1098 old = g_list_prepend(old, cnd); | |
1099 } while (gtk_tree_model_iter_next(store, &child)); | |
1100 } | |
1101 | |
1102 work = list; | |
1103 while (work) | |
1104 { | |
1105 FileData *fd; | |
1106 | |
1107 fd = work->data; | |
1108 work = work->next; | |
1109 | |
1110 if (strcmp(fd->name, ".") == 0 || strcmp(fd->name, "..") == 0) | |
1111 { | |
138 | 1112 file_data_unref(fd); |
9 | 1113 } |
1114 else | |
1115 { | |
1116 NodeData *cnd; | |
1117 | |
1118 cnd = vdtree_find_iter_by_name(vdt, iter, fd->name, &child); | |
1119 if (cnd) | |
1120 { | |
1121 old = g_list_remove(old, cnd); | |
1122 if (cnd->expanded && cnd->fd->date != fd->date && | |
1123 vdtree_populate_path_by_iter(vdt, &child, FALSE, target_path)) | |
1124 { | |
1125 cnd->fd->size = fd->size; | |
1126 cnd->fd->date = fd->date; | |
1127 } | |
1128 | |
138 | 1129 file_data_unref(fd); |
9 | 1130 } |
1131 else | |
1132 { | |
1133 vdtree_add_by_data(vdt, fd, iter); | |
1134 } | |
1135 } | |
1136 } | |
1137 | |
1138 work = old; | |
1139 while (work) | |
1140 { | |
1141 NodeData *cnd = work->data; | |
1142 work = work->next; | |
1143 | |
1144 if (vdt->click_fd == cnd->fd) vdt->click_fd = NULL; | |
1145 if (vdt->drop_fd == cnd->fd) vdt->drop_fd = NULL; | |
1146 | |
1147 if (vdtree_find_iter_by_data(vdt, iter, cnd, &child)) | |
1148 { | |
1149 gtk_tree_store_remove(GTK_TREE_STORE(store), &child); | |
1150 vdtree_node_free(cnd); | |
1151 } | |
1152 } | |
1153 | |
1154 g_list_free(old); | |
1155 g_list_free(list); | |
1156 | |
1157 vdtree_busy_pop(vdt); | |
1158 | |
1159 nd->expanded = TRUE; | |
1160 nd->last_update = current_time; | |
1161 | |
1162 return TRUE; | |
1163 } | |
1164 | |
1165 static FileData *vdtree_populate_path(ViewDirTree *vdt, const gchar *path, gint expand, gint force) | |
1166 { | |
1167 GList *list; | |
1168 GList *work; | |
1169 FileData *fd = NULL; | |
1170 | |
1171 if (!path) return NULL; | |
1172 | |
1173 vdtree_busy_push(vdt); | |
1174 | |
1175 list = parts_list(path); | |
1176 list = parts_list_add_node_points(vdt, list); | |
1177 | |
1178 work = list; | |
1179 while (work) | |
1180 { | |
1181 PathData *pd = work->data; | |
1182 if (pd->node == NULL) | |
1183 { | |
1184 PathData *parent_pd; | |
1185 GtkTreeIter parent_iter; | |
1186 GtkTreeIter iter; | |
1187 NodeData *nd; | |
1188 | |
1189 if (work == list) | |
1190 { | |
1191 /* should not happen */ | |
1192 printf("vdtree warning, root node not found\n"); | |
1193 parts_list_free(list); | |
1194 vdtree_busy_pop(vdt); | |
1195 return NULL; | |
1196 } | |
1197 | |
1198 parent_pd = work->prev->data; | |
1199 | |
1200 if (!vdtree_find_row(vdt, parent_pd->node, &parent_iter, NULL) || | |
1201 !vdtree_populate_path_by_iter(vdt, &parent_iter, force, path) || | |
1202 (nd = vdtree_find_iter_by_name(vdt, &parent_iter, pd->name, &iter)) == NULL) | |
1203 { | |
1204 printf("vdtree warning, aborted at %s\n", parent_pd->name); | |
1205 parts_list_free(list); | |
1206 vdtree_busy_pop(vdt); | |
1207 return NULL; | |
1208 } | |
1209 | |
1210 pd->node = nd->fd; | |
1211 | |
1212 if (pd->node) | |
1213 { | |
1214 if (expand) | |
1215 { | |
1216 vdtree_expand_by_iter(vdt, &parent_iter, TRUE); | |
1217 vdtree_expand_by_iter(vdt, &iter, TRUE); | |
1218 } | |
1219 vdtree_populate_path_by_iter(vdt, &iter, force, path); | |
1220 } | |
1221 } | |
1222 else | |
1223 { | |
1224 GtkTreeIter iter; | |
1225 | |
1226 if (vdtree_find_row(vdt, pd->node, &iter, NULL)) | |
1227 { | |
1228 if (expand) vdtree_expand_by_iter(vdt, &iter, TRUE); | |
1229 vdtree_populate_path_by_iter(vdt, &iter, force, path); | |
1230 } | |
1231 } | |
1232 | |
1233 work = work->next; | |
1234 } | |
1235 | |
1236 work = g_list_last(list); | |
1237 if (work) | |
1238 { | |
1239 PathData *pd = work->data; | |
1240 fd = pd->node; | |
1241 } | |
1242 parts_list_free(list); | |
1243 | |
1244 vdtree_busy_pop(vdt); | |
1245 | |
1246 return fd; | |
1247 } | |
1248 | |
1249 /* | |
1250 *---------------------------------------------------------------------------- | |
1251 * access | |
1252 *---------------------------------------------------------------------------- | |
1253 */ | |
1254 | |
1255 static gint selection_is_ok = FALSE; | |
1256 | |
1257 static gboolean vdtree_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
1258 gboolean path_currently_selected, gpointer data) | |
1259 { | |
1260 return selection_is_ok; | |
1261 } | |
1262 | |
1263 static void vdtree_select_row(ViewDirTree *vdt, FileData *fd) | |
1264 { | |
1265 GtkTreeSelection *selection; | |
1266 GtkTreeIter iter; | |
1267 | |
1268 if (!vdtree_find_row(vdt, fd, &iter, NULL)) return; | |
1269 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdt->treeview)); | |
1270 | |
1271 /* hack, such that selection is only allowed to be changed from here */ | |
1272 selection_is_ok = TRUE; | |
1273 gtk_tree_selection_select_iter(selection, &iter); | |
1274 selection_is_ok = FALSE; | |
1275 | |
1276 if (!vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path)) return; | |
1277 | |
1278 vdtree_expand_by_iter(vdt, &iter, TRUE); | |
1279 | |
1280 if (fd && vdt->select_func) | |
1281 { | |
1282 vdt->select_func(vdt, fd->path, vdt->select_data); | |
1283 } | |
1284 } | |
1285 | |
1286 gint vdtree_set_path(ViewDirTree *vdt, const gchar *path) | |
1287 { | |
1288 FileData *fd; | |
1289 GtkTreeIter iter; | |
1290 | |
1291 if (!path) return FALSE; | |
1292 if (vdt->path && strcmp(path, vdt->path) == 0) return TRUE; | |
1293 | |
1294 g_free(vdt->path); | |
1295 vdt->path = g_strdup(path); | |
1296 | |
63
e29c291e106b
Mon Aug 15 16:35:15 2005 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1297 fd = vdtree_populate_path(vdt, vdt->path, TRUE, FALSE); |
9 | 1298 |
1299 if (!fd) return FALSE; | |
1300 | |
1301 if (vdtree_find_row(vdt, fd, &iter, NULL)) | |
1302 { | |
1303 GtkTreeModel *store; | |
1304 GtkTreePath *tpath; | |
1305 | |
1306 tree_view_row_make_visible(GTK_TREE_VIEW(vdt->treeview), &iter, TRUE); | |
1307 | |
1308 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1309 tpath = gtk_tree_model_get_path(store, &iter); | |
1310 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vdt->treeview), tpath, NULL, FALSE); | |
1311 gtk_tree_path_free(tpath); | |
1312 | |
1313 vdtree_select_row(vdt, fd); | |
1314 } | |
1315 | |
1316 return TRUE; | |
1317 } | |
1318 | |
1319 #if 0 | |
1320 const gchar *vdtree_get_path(ViewDirTree *vdt) | |
1321 { | |
1322 return vdt->path; | |
1323 } | |
1324 #endif | |
1325 | |
1326 void vdtree_refresh(ViewDirTree *vdt) | |
1327 { | |
1328 vdtree_populate_path(vdt, vdt->path, FALSE, TRUE); | |
1329 } | |
1330 | |
1331 const gchar *vdtree_row_get_path(ViewDirTree *vdt, gint row) | |
1332 { | |
1333 printf("FIXME: no get row path\n"); | |
1334 return NULL; | |
1335 } | |
1336 | |
1337 /* | |
1338 *---------------------------------------------------------------------------- | |
1339 * callbacks | |
1340 *---------------------------------------------------------------------------- | |
1341 */ | |
1342 | |
1343 static void vdtree_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
1344 { | |
1345 ViewDirTree *vdt = data; | |
1346 GtkTreeModel *store; | |
1347 GtkTreeIter iter; | |
1348 GtkTreePath *tpath; | |
1349 gint cw, ch; | |
1350 | |
1351 if (vdtree_find_row(vdt, vdt->click_fd, &iter, NULL) < 0) return; | |
1352 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1353 tpath = gtk_tree_model_get_path(store, &iter); | |
1354 tree_view_get_cell_clamped(GTK_TREE_VIEW(vdt->treeview), tpath, 0, TRUE, x, y, &cw, &ch); | |
1355 gtk_tree_path_free(tpath); | |
1356 *y += ch; | |
1357 popup_menu_position_clamp(menu, x, y, 0); | |
1358 } | |
1359 | |
1360 static gint vdtree_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
1361 { | |
1362 ViewDirTree *vdt = data; | |
1363 GtkTreePath *tpath; | |
1364 GtkTreeIter iter; | |
1365 FileData *fd = NULL; | |
1366 | |
1367 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vdt->treeview), &tpath, NULL); | |
1368 if (tpath) | |
1369 { | |
1370 GtkTreeModel *store; | |
1371 NodeData *nd; | |
1372 | |
1373 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1374 gtk_tree_model_get_iter(store, &iter, tpath); | |
1375 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1376 | |
1377 gtk_tree_path_free(tpath); | |
1378 | |
1379 fd = (nd) ? nd->fd : NULL; | |
1380 } | |
1381 | |
1382 switch (event->keyval) | |
1383 { | |
1384 case GDK_Menu: | |
1385 vdt->click_fd = fd; | |
1386 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
1387 | |
1388 vdt->popup = vdtree_pop_menu(vdt, vdt->click_fd); | |
1389 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, vdtree_menu_position_cb, vdt, 0, GDK_CURRENT_TIME); | |
1390 | |
1391 return TRUE; | |
1392 break; | |
1393 case GDK_plus: | |
1394 case GDK_Right: | |
1395 case GDK_KP_Add: | |
1396 if (fd) | |
1397 { | |
1398 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
1399 vdtree_icon_set_by_iter(vdt, &iter, vdt->pf->open); | |
1400 } | |
1401 break; | |
1402 } | |
1403 | |
1404 return FALSE; | |
1405 } | |
1406 | |
1407 static gint vdtree_clicked_on_expander(GtkTreeView *treeview, GtkTreePath *tpath, | |
1408 GtkTreeViewColumn *column, gint x, gint y, gint *left_of_expander) | |
1409 { | |
1410 gint depth; | |
1411 gint size; | |
1412 gint sep; | |
1413 gint exp_width; | |
1414 | |
1415 if (column != gtk_tree_view_get_expander_column(treeview)) return FALSE; | |
1416 | |
1417 gtk_widget_style_get(GTK_WIDGET(treeview), "expander-size", &size, "horizontal-separator", &sep, NULL); | |
1418 depth = gtk_tree_path_get_depth(tpath); | |
1419 | |
1420 exp_width = sep + size + sep; | |
1421 | |
1422 if (x <= depth * exp_width) | |
1423 { | |
1424 if (left_of_expander) *left_of_expander = !(x >= (depth - 1) * exp_width); | |
1425 return TRUE; | |
1426 } | |
1427 | |
1428 return FALSE; | |
1429 } | |
1430 | |
1431 static gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1432 { | |
1433 ViewDirTree *vdt = data; | |
1434 GtkTreePath *tpath; | |
1435 GtkTreeViewColumn *column; | |
1436 GtkTreeIter iter; | |
1437 NodeData *nd = NULL; | |
1438 | |
1439 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1440 &tpath, &column, NULL, NULL)) | |
1441 { | |
1442 GtkTreeModel *store; | |
1443 gint left_of_expander; | |
1444 | |
1445 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1446 gtk_tree_model_get_iter(store, &iter, tpath); | |
1447 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1448 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1449 | |
1450 if (vdtree_clicked_on_expander(GTK_TREE_VIEW(widget), tpath, column, bevent->x, bevent->y, &left_of_expander)) | |
1451 { | |
1452 vdt->click_fd = NULL; | |
1453 | |
1454 /* clicking this region should automatically reveal an expander, if necessary | |
1455 * treeview bug: the expander will not expand until a button_motion_event highlights it. | |
1456 */ | |
1457 if (bevent->button == 1 && | |
1458 !left_of_expander && | |
1459 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vdt->treeview), tpath)) | |
1460 { | |
1461 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
1462 vdtree_icon_set_by_iter(vdt, &iter, vdt->pf->open); | |
1463 } | |
1464 | |
1465 gtk_tree_path_free(tpath); | |
1466 return FALSE; | |
1467 } | |
1468 | |
1469 gtk_tree_path_free(tpath); | |
1470 } | |
1471 | |
1472 vdt->click_fd = (nd) ? nd->fd : NULL; | |
1473 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
1474 | |
1475 if (bevent->button == 3) | |
1476 { | |
1477 vdt->popup = vdtree_pop_menu(vdt, vdt->click_fd); | |
1478 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, NULL, NULL, | |
1479 bevent->button, bevent->time); | |
1480 } | |
1481 | |
1482 return (bevent->button != 1); | |
1483 } | |
1484 | |
1485 static gint vdtree_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1486 { | |
1487 ViewDirTree *vdt = data; | |
1488 GtkTreePath *tpath; | |
1489 GtkTreeIter iter; | |
1490 NodeData *nd = NULL; | |
1491 | |
1492 if (!vdt->click_fd) return FALSE; | |
1493 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
1494 | |
1495 if (bevent->button != 1) return TRUE; | |
1496 | |
1497 if ((bevent->x != 0 || bevent->y != 0) && | |
1498 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1499 &tpath, NULL, NULL, NULL)) | |
1500 { | |
1501 GtkTreeModel *store; | |
1502 | |
1503 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1504 gtk_tree_model_get_iter(store, &iter, tpath); | |
1505 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1506 gtk_tree_path_free(tpath); | |
1507 } | |
1508 | |
1509 if (nd && vdt->click_fd == nd->fd) | |
1510 { | |
1511 vdtree_select_row(vdt, vdt->click_fd); | |
1512 } | |
1513 | |
1514 return FALSE; | |
1515 } | |
1516 | |
1517 static void vdtree_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
1518 { | |
1519 ViewDirTree *vdt = data; | |
1520 | |
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1521 vdtree_populate_path_by_iter(vdt, iter, FALSE, NULL); |
9 | 1522 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->open); |
1523 } | |
1524 | |
1525 static void vdtree_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
1526 { | |
1527 ViewDirTree *vdt = data; | |
1528 | |
1529 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->close); | |
1530 } | |
1531 | |
1532 static gint vdtree_sort_cb(GtkTreeModel *store, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
1533 { | |
1534 NodeData *nda; | |
1535 NodeData *ndb; | |
1536 | |
1537 gtk_tree_model_get(store, a, DIR_COLUMN_POINTER, &nda, -1); | |
1538 gtk_tree_model_get(store, b, DIR_COLUMN_POINTER, &ndb, -1); | |
1539 | |
1540 return CASE_SORT(nda->fd->name, ndb->fd->name); | |
1541 } | |
1542 | |
1543 /* | |
1544 *---------------------------------------------------------------------------- | |
1545 * core | |
1546 *---------------------------------------------------------------------------- | |
1547 */ | |
1548 | |
1549 static void vdtree_setup_root(ViewDirTree *vdt) | |
1550 { | |
1551 const gchar *path = "/"; | |
1552 FileData *fd; | |
1553 | |
138 | 1554 |
1555 fd = file_data_new_simple(path); | |
9 | 1556 vdtree_add_by_data(vdt, fd, NULL); |
1557 | |
1558 vdtree_expand_by_data(vdt, fd, TRUE); | |
1559 vdtree_populate_path(vdt, path, FALSE, FALSE); | |
1560 } | |
1561 | |
1562 static void vdtree_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
1563 { | |
1564 ViewDirTree *vdt = data; | |
1565 GtkTreeModel *store; | |
1566 GtkTreeIter iter; | |
1567 NodeData *nd; | |
1568 | |
1569 store = gtk_tree_view_get_model(tview); | |
1570 gtk_tree_model_get_iter(store, &iter, tpath); | |
1571 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
1572 | |
1573 vdtree_select_row(vdt, nd->fd); | |
1574 } | |
1575 | |
1576 static GdkColor *vdtree_color_shifted(GtkWidget *widget) | |
1577 { | |
1578 static GdkColor color; | |
1579 static GtkWidget *done = NULL; | |
1580 | |
1581 if (done != widget) | |
1582 { | |
1583 GtkStyle *style; | |
1584 | |
1585 style = gtk_widget_get_style(widget); | |
1586 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
1587 shift_color(&color, -1, 0); | |
1588 done = widget; | |
1589 } | |
1590 | |
1591 return &color; | |
1592 } | |
1593 | |
1594 static void vdtree_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
1595 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
1596 { | |
1597 ViewDirTree *vdt = data; | |
1598 gboolean set; | |
1599 | |
1600 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1); | |
1601 g_object_set(G_OBJECT(cell), | |
1602 "cell-background-gdk", vdtree_color_shifted(vdt->treeview), | |
1603 "cell-background-set", set, NULL); | |
1604 } | |
1605 | |
1606 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
1607 { | |
1608 NodeData *nd; | |
1609 | |
1610 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
1611 vdtree_node_free(nd); | |
1612 | |
1613 return FALSE; | |
1614 } | |
1615 | |
1616 static void vdtree_destroy_cb(GtkWidget *widget, gpointer data) | |
1617 { | |
1618 ViewDirTree *vdt = data; | |
1619 GtkTreeModel *store; | |
1620 | |
1621 if (vdt->popup) | |
1622 { | |
1623 g_signal_handlers_disconnect_matched(G_OBJECT(vdt->popup), G_SIGNAL_MATCH_DATA, | |
1624 0, 0, 0, NULL, vdt); | |
1625 gtk_widget_destroy(vdt->popup); | |
1626 } | |
1627 | |
1628 vdtree_dnd_drop_expand_cancel(vdt); | |
1629 vdtree_dnd_drop_scroll_cancel(vdt); | |
1630 widget_auto_scroll_stop(vdt->treeview); | |
1631 | |
1632 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
1633 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vdt); | |
1634 | |
138 | 1635 filelist_free(vdt->drop_list); |
9 | 1636 |
1637 folder_icons_free(vdt->pf); | |
1638 | |
1639 g_free(vdt->path); | |
1640 g_free(vdt); | |
1641 } | |
1642 | |
1643 ViewDirTree *vdtree_new(const gchar *path, gint expand) | |
1644 { | |
1645 ViewDirTree *vdt; | |
1646 GtkTreeStore *store; | |
1647 GtkTreeSelection *selection; | |
1648 GtkTreeViewColumn *column; | |
1649 GtkCellRenderer *renderer; | |
1650 | |
1651 vdt = g_new0(ViewDirTree, 1); | |
1652 | |
1653 vdt->path = NULL; | |
1654 vdt->click_fd = NULL; | |
1655 | |
1656 vdt->drop_fd = NULL; | |
1657 vdt->drop_list = NULL; | |
1658 vdt->drop_scroll_id = -1; | |
1659 vdt->drop_expand_id = -1; | |
1660 | |
1661 vdt->popup = NULL; | |
1662 | |
1663 vdt->busy_ref = 0; | |
1664 | |
1665 vdt->widget = gtk_scrolled_window_new(NULL, NULL); | |
1666 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vdt->widget), GTK_SHADOW_IN); | |
1667 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vdt->widget), | |
1668 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1669 g_signal_connect(G_OBJECT(vdt->widget), "destroy", | |
1670 G_CALLBACK(vdtree_destroy_cb), vdt); | |
1671 | |
1672 store = gtk_tree_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); | |
1673 vdt->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1674 g_object_unref(store); | |
1675 | |
1676 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vdt->treeview), FALSE); | |
1677 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vdt->treeview), FALSE); | |
1678 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vdt, NULL); | |
1679 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), | |
1680 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); | |
1681 | |
1682 g_signal_connect(G_OBJECT(vdt->treeview), "row_activated", | |
1683 G_CALLBACK(vdtree_activate_cb), vdt); | |
1684 g_signal_connect(G_OBJECT(vdt->treeview), "row_expanded", | |
1685 G_CALLBACK(vdtree_row_expanded), vdt); | |
1686 g_signal_connect(G_OBJECT(vdt->treeview), "row_collapsed", | |
1687 G_CALLBACK(vdtree_row_collapsed), vdt); | |
1688 #if 0 | |
1689 g_signal_connect(G_OBJECT(store), "row_deleted", | |
1690 G_CALLBACK(vdtree_row_deleted_cb), vdt); | |
1691 #endif | |
1692 | |
1693 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdt->treeview)); | |
1694 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
1695 gtk_tree_selection_set_select_function(selection, vdtree_select_cb, vdt, NULL); | |
1696 | |
1697 column = gtk_tree_view_column_new(); | |
1698 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
1699 | |
1700 renderer = gtk_cell_renderer_pixbuf_new(); | |
1701 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1702 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
1703 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vdt, NULL); | |
1704 | |
1705 renderer = gtk_cell_renderer_text_new(); | |
1706 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1707 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
1708 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vdt, NULL); | |
1709 | |
1710 gtk_tree_view_append_column(GTK_TREE_VIEW(vdt->treeview), column); | |
1711 | |
1712 g_signal_connect(G_OBJECT(vdt->treeview), "key_press_event", | |
1713 G_CALLBACK(vdtree_press_key_cb), vdt); | |
1714 | |
1715 gtk_container_add(GTK_CONTAINER(vdt->widget), vdt->treeview); | |
1716 gtk_widget_show(vdt->treeview); | |
1717 | |
1718 vdt->pf = folder_icons_new(); | |
1719 | |
1720 vdtree_setup_root(vdt); | |
1721 | |
1722 vdtree_dnd_init(vdt); | |
1723 | |
1724 g_signal_connect(G_OBJECT(vdt->treeview), "button_press_event", | |
1725 G_CALLBACK(vdtree_press_cb), vdt); | |
1726 g_signal_connect(G_OBJECT(vdt->treeview), "button_release_event", | |
1727 G_CALLBACK(vdtree_release_cb), vdt); | |
1728 | |
1729 vdtree_set_path(vdt, path); | |
1730 | |
1731 return vdt; | |
1732 } | |
1733 | |
1734 void vdtree_set_select_func(ViewDirTree *vdt, | |
1735 void (*func)(ViewDirTree *vdt, const gchar *path, gpointer data), gpointer data) | |
1736 { | |
1737 vdt->select_func = func; | |
1738 vdt->select_data = data; | |
1739 } | |
1740 | |
1741 #if 0 | |
1742 void vdtree_set_click_func(ViewDirTree *vdt, | |
1743 void (*func)(ViewDirTree *vdt, GdkEventButton *event, FileData *fd, gpointer), gpointer data) | |
1744 { | |
1745 if (!td) return; | |
1746 vdt->click_func = func; | |
1747 vdt->click_data = data; | |
1748 } | |
1749 #endif | |
1750 | |
1751 void vdtree_set_layout(ViewDirTree *vdt, LayoutWindow *layout) | |
1752 { | |
1753 vdt->layout = layout; | |
1754 } | |
1755 |