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