Mercurial > geeqie
annotate src/view_dir_list.c @ 360:822040a51249
Increase collection_load() buffer size and do not activate
error limiting for GQview collections.
author | zas_ |
---|---|
date | Mon, 14 Apr 2008 22:45:53 +0000 |
parents | 673d1eb5af73 |
children | 61a3c8b05b24 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
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_list.h" |
14 | |
15 #include "dnd.h" | |
16 #include "dupe.h" | |
17 #include "filelist.h" | |
18 #include "layout.h" | |
19 #include "layout_image.h" | |
20 #include "layout_util.h" | |
21 #include "utilops.h" | |
22 #include "ui_bookmark.h" | |
23 #include "ui_fileops.h" | |
24 #include "ui_menu.h" | |
25 #include "ui_tree_edit.h" | |
26 | |
27 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
28 | |
29 | |
30 #define VDLIST_PAD 4 | |
31 | |
32 | |
33 enum { | |
34 DIR_COLUMN_POINTER = 0, | |
35 DIR_COLUMN_ICON, | |
36 DIR_COLUMN_NAME, | |
37 DIR_COLUMN_COLOR, | |
38 DIR_COLUMN_COUNT | |
39 }; | |
40 | |
41 | |
42 static void vdlist_popup_destroy_cb(GtkWidget *widget, gpointer data); | |
43 static gint vdlist_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data); | |
44 | |
45 /* | |
46 *----------------------------------------------------------------------------- | |
47 * misc | |
48 *----------------------------------------------------------------------------- | |
49 */ | |
50 | |
51 static gint vdlist_find_row(ViewDirList *vdl, FileData *fd, GtkTreeIter *iter) | |
52 { | |
53 GtkTreeModel *store; | |
54 gint valid; | |
55 gint row = 0; | |
56 | |
57 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
58 valid = gtk_tree_model_get_iter_first(store, iter); | |
59 while (valid) | |
60 { | |
61 FileData *fd_n; | |
62 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &fd_n, -1); | |
63 if (fd_n == fd) return row; | |
64 | |
65 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
66 row++; | |
67 } | |
68 | |
69 return -1; | |
70 } | |
71 | |
72 static gint vdlist_rename_row_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) | |
73 { | |
74 ViewDirList *vdl = data; | |
75 GtkTreeModel *store; | |
76 GtkTreeIter iter; | |
77 FileData *fd; | |
78 gchar *old_path; | |
79 gchar *new_path; | |
80 gchar *base; | |
81 | |
82 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
83 if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE; | |
84 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
85 if (!fd) return FALSE; | |
86 | |
87 old_path = g_strdup(fd->path); | |
88 | |
89 base = remove_level_from_path(old_path); | |
90 new_path = concat_dir_and_file(base, new); | |
91 g_free(base); | |
92 | |
138 | 93 if (file_util_rename_dir(fd, new_path, vdl->listview)) |
9 | 94 { |
95 if (vdl->layout && strcmp(vdl->path, old_path) == 0) | |
96 { | |
97 layout_set_path(vdl->layout, new_path); | |
98 } | |
99 else | |
100 { | |
101 vdlist_refresh(vdl); | |
102 } | |
103 } | |
104 | |
105 g_free(old_path); | |
106 g_free(new_path); | |
107 return FALSE; | |
108 } | |
109 | |
110 static void vdlist_rename_by_row(ViewDirList *vdl, FileData *fd) | |
111 { | |
112 GtkTreeModel *store; | |
113 GtkTreePath *tpath; | |
114 GtkTreeIter iter; | |
115 | |
116 if (vdlist_find_row(vdl, fd, &iter) < 0) return; | |
117 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
118 tpath = gtk_tree_model_get_path(store, &iter); | |
119 | |
120 tree_edit_by_path(GTK_TREE_VIEW(vdl->listview), tpath, 0, fd->name, | |
121 vdlist_rename_row_cb, vdl); | |
122 gtk_tree_path_free(tpath); | |
123 } | |
124 | |
125 static FileData *vdlist_row_by_path(ViewDirList *vdl, const gchar *path, gint *row) | |
126 { | |
127 GList *work; | |
128 gint n; | |
129 | |
130 if (!path) | |
131 { | |
132 if (row) *row = -1; | |
133 return NULL; | |
134 } | |
135 | |
136 n = 0; | |
137 work = vdl->list; | |
138 while (work) | |
139 { | |
140 FileData *fd = work->data; | |
141 if (strcmp(fd->path, path) == 0) | |
142 { | |
143 if (row) *row = n; | |
144 return fd; | |
145 } | |
146 work = work->next; | |
147 n++; | |
148 } | |
149 | |
150 if (row) *row = -1; | |
151 return NULL; | |
152 } | |
153 | |
154 static void vdlist_color_set(ViewDirList *vdl, FileData *fd, gint color_set) | |
155 { | |
156 GtkTreeModel *store; | |
157 GtkTreeIter iter; | |
158 | |
159 if (vdlist_find_row(vdl, fd, &iter) < 0) return; | |
160 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
161 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1); | |
162 } | |
163 | |
164 /* | |
165 *----------------------------------------------------------------------------- | |
166 * drop menu (from dnd) | |
167 *----------------------------------------------------------------------------- | |
168 */ | |
169 | |
170 static void vdlist_drop_menu_copy_cb(GtkWidget *widget, gpointer data) | |
171 { | |
172 ViewDirList *vdl = data; | |
173 const gchar *path; | |
174 GList *list; | |
175 | |
176 if (!vdl->drop_fd) return; | |
177 | |
178 path = vdl->drop_fd->path; | |
179 list = vdl->drop_list; | |
180 vdl->drop_list = NULL; | |
181 | |
182 file_util_copy_simple(list, path); | |
183 } | |
184 | |
185 static void vdlist_drop_menu_move_cb(GtkWidget *widget, gpointer data) | |
186 { | |
187 ViewDirList *vdl = data; | |
188 const gchar *path; | |
189 GList *list; | |
190 | |
191 if (!vdl->drop_fd) return; | |
192 | |
193 path = vdl->drop_fd->path; | |
194 list = vdl->drop_list; | |
195 | |
196 vdl->drop_list = NULL; | |
197 | |
198 file_util_move_simple(list, path); | |
199 } | |
200 | |
201 static GtkWidget *vdlist_drop_menu(ViewDirList *vdl, gint active) | |
202 { | |
203 GtkWidget *menu; | |
204 | |
205 menu = popup_menu_short_lived(); | |
206 g_signal_connect(G_OBJECT(menu), "destroy", | |
207 G_CALLBACK(vdlist_popup_destroy_cb), vdl); | |
208 | |
209 menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active, | |
210 G_CALLBACK(vdlist_drop_menu_copy_cb), vdl); | |
211 menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vdlist_drop_menu_move_cb), vdl); | |
212 | |
213 menu_item_add_divider(menu); | |
214 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vdl); | |
215 | |
216 return menu; | |
217 } | |
218 | |
219 /* | |
220 *----------------------------------------------------------------------------- | |
221 * pop-up menu | |
222 *----------------------------------------------------------------------------- | |
223 */ | |
224 | |
225 static void vdlist_pop_menu_up_cb(GtkWidget *widget, gpointer data) | |
226 { | |
227 ViewDirList *vdl = data; | |
228 gchar *path; | |
229 | |
230 if (!vdl->path || strcmp(vdl->path, "/") == 0) return; | |
231 path = remove_level_from_path(vdl->path); | |
232 | |
233 if (vdl->select_func) | |
234 { | |
235 vdl->select_func(vdl, path, vdl->select_data); | |
236 } | |
237 | |
238 g_free(path); | |
239 } | |
240 | |
241 static void vdlist_pop_menu_slide_cb(GtkWidget *widget, gpointer data) | |
242 { | |
243 ViewDirList *vdl = data; | |
244 gchar *path; | |
245 | |
246 if (!vdl->layout || !vdl->click_fd) return; | |
247 | |
248 path = g_strdup(vdl->click_fd->path); | |
249 | |
250 layout_set_path(vdl->layout, path); | |
251 layout_select_none(vdl->layout); | |
252 layout_image_slideshow_stop(vdl->layout); | |
253 layout_image_slideshow_start(vdl->layout); | |
254 | |
255 g_free(path); | |
256 } | |
257 | |
258 static void vdlist_pop_menu_slide_rec_cb(GtkWidget *widget, gpointer data) | |
259 { | |
260 ViewDirList *vdl = data; | |
261 gchar *path; | |
262 GList *list; | |
263 | |
264 if (!vdl->layout || !vdl->click_fd) return; | |
265 | |
266 path = g_strdup(vdl->click_fd->path); | |
267 | |
138 | 268 list = filelist_recursive(path); |
9 | 269 |
270 layout_image_slideshow_stop(vdl->layout); | |
271 layout_image_slideshow_start_from_list(vdl->layout, list); | |
272 | |
273 g_free(path); | |
274 } | |
275 | |
276 static void vdlist_pop_menu_dupe(ViewDirList *vdl, gint recursive) | |
277 { | |
278 DupeWindow *dw; | |
279 GList *list = NULL; | |
280 | |
281 if (!vdl->click_fd) return; | |
282 | |
283 if (recursive) | |
284 { | |
138 | 285 list = g_list_append(list, file_data_ref(vdl->click_fd)); |
9 | 286 } |
287 else | |
288 { | |
138 | 289 filelist_read(vdl->click_fd->path, &list, NULL); |
290 list = filelist_filter(list, FALSE); | |
9 | 291 } |
292 | |
293 dw = dupe_window_new(DUPE_MATCH_NAME); | |
294 dupe_window_add_files(dw, list, recursive); | |
295 | |
138 | 296 filelist_free(list); |
9 | 297 } |
298 | |
299 static void vdlist_pop_menu_dupe_cb(GtkWidget *widget, gpointer data) | |
300 { | |
301 ViewDirList *vdl = data; | |
302 vdlist_pop_menu_dupe(vdl, FALSE); | |
303 } | |
304 | |
305 static void vdlist_pop_menu_dupe_rec_cb(GtkWidget *widget, gpointer data) | |
306 { | |
307 ViewDirList *vdl = data; | |
308 vdlist_pop_menu_dupe(vdl, TRUE); | |
309 } | |
310 | |
311 static void vdlist_pop_menu_new_cb(GtkWidget *widget, gpointer data) | |
312 { | |
313 ViewDirList *vdl = data; | |
314 gchar *new_path; | |
315 gchar *buf; | |
316 | |
317 if (!vdl->path) return; | |
318 | |
319 buf = concat_dir_and_file(vdl->path, _("new_folder")); | |
320 new_path = unique_filename(buf, NULL, NULL, FALSE); | |
321 g_free(buf); | |
322 if (!new_path) return; | |
323 | |
324 if (!mkdir_utf8(new_path, 0755)) | |
325 { | |
326 gchar *text; | |
327 | |
328 text = g_strdup_printf(_("Unable to create folder:\n%s"), new_path); | |
329 file_util_warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, vdl->listview); | |
330 g_free(text); | |
331 } | |
332 else | |
333 { | |
334 FileData *fd; | |
335 | |
336 vdlist_refresh(vdl); | |
337 fd = vdlist_row_by_path(vdl, new_path, NULL); | |
338 | |
339 vdlist_rename_by_row(vdl, fd); | |
340 } | |
341 | |
342 g_free(new_path); | |
343 } | |
344 | |
345 static void vdlist_pop_menu_rename_cb(GtkWidget *widget, gpointer data) | |
346 { | |
347 ViewDirList *vdl = data; | |
348 | |
349 vdlist_rename_by_row(vdl, vdl->click_fd); | |
350 } | |
351 | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
352 static void vdlist_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
|
353 { |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
354 ViewDirList *vdl = data; |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
355 |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
356 if (!vdl->click_fd) return; |
138 | 357 file_util_delete_dir(vdl->click_fd, vdl->widget); |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
358 } |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
359 |
9 | 360 static void vdlist_pop_menu_tree_cb(GtkWidget *widget, gpointer data) |
361 { | |
362 ViewDirList *vdl = data; | |
363 | |
364 if (vdl->layout) layout_views_set(vdl->layout, TRUE, vdl->layout->icon_view); | |
365 } | |
366 | |
367 static void vdlist_pop_menu_refresh_cb(GtkWidget *widget, gpointer data) | |
368 { | |
369 ViewDirList *vdl = data; | |
370 | |
371 if (vdl->layout) layout_refresh(vdl->layout); | |
372 } | |
373 | |
356 | 374 static void vdlist_toggle_show_hidden_files_cb(GtkWidget *widget, gpointer data) |
355
0b82646e977f
Let toggle the visibility of hidden files from directories list
zas_
parents:
281
diff
changeset
|
375 { |
0b82646e977f
Let toggle the visibility of hidden files from directories list
zas_
parents:
281
diff
changeset
|
376 ViewDirList *vdl = data; |
0b82646e977f
Let toggle the visibility of hidden files from directories list
zas_
parents:
281
diff
changeset
|
377 |
356 | 378 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:
281
diff
changeset
|
379 if (vdl->layout) layout_refresh(vdl->layout); |
0b82646e977f
Let toggle the visibility of hidden files from directories list
zas_
parents:
281
diff
changeset
|
380 } |
0b82646e977f
Let toggle the visibility of hidden files from directories list
zas_
parents:
281
diff
changeset
|
381 |
9 | 382 static GtkWidget *vdlist_pop_menu(ViewDirList *vdl, FileData *fd) |
383 { | |
384 GtkWidget *menu; | |
385 gint active; | |
386 | |
387 active = (fd != NULL); | |
388 | |
389 menu = popup_menu_short_lived(); | |
390 g_signal_connect(G_OBJECT(menu), "destroy", | |
391 G_CALLBACK(vdlist_popup_destroy_cb), vdl); | |
392 | |
393 menu_item_add_stock_sensitive(menu, _("_Up to parent"), GTK_STOCK_GO_UP, | |
394 (vdl->path && strcmp(vdl->path, "/") != 0), | |
395 G_CALLBACK(vdlist_pop_menu_up_cb), vdl); | |
396 | |
397 menu_item_add_divider(menu); | |
398 menu_item_add_sensitive(menu, _("_Slideshow"), active, | |
399 G_CALLBACK(vdlist_pop_menu_slide_cb), vdl); | |
400 menu_item_add_sensitive(menu, _("Slideshow recursive"), active, | |
401 G_CALLBACK(vdlist_pop_menu_slide_rec_cb), vdl); | |
402 | |
403 menu_item_add_divider(menu); | |
404 menu_item_add_stock_sensitive(menu, _("Find _duplicates..."), GTK_STOCK_FIND, active, | |
405 G_CALLBACK(vdlist_pop_menu_dupe_cb), vdl); | |
406 menu_item_add_stock_sensitive(menu, _("Find duplicates recursive..."), GTK_STOCK_FIND, active, | |
407 G_CALLBACK(vdlist_pop_menu_dupe_rec_cb), vdl); | |
408 | |
409 menu_item_add_divider(menu); | |
410 | |
411 /* check using . (always row 0) */ | |
412 active = (vdl->path && access_file(vdl->path , W_OK | X_OK)); | |
413 menu_item_add_sensitive(menu, _("_New folder..."), active, | |
414 G_CALLBACK(vdlist_pop_menu_new_cb), vdl); | |
415 | |
416 /* ignore .. and . */ | |
417 active = (active && fd && | |
418 strcmp(fd->name, ".") != 0 && | |
419 strcmp(fd->name, "..") != 0 && | |
420 access_file(fd->path, W_OK | X_OK)); | |
421 menu_item_add_sensitive(menu, _("_Rename..."), active, | |
422 G_CALLBACK(vdlist_pop_menu_rename_cb), vdl); | |
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
423 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active, |
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
424 G_CALLBACK(vdlist_pop_menu_delete_cb), vdl); |
9 | 425 |
426 menu_item_add_divider(menu); | |
427 menu_item_add_check(menu, _("View as _tree"), FALSE, | |
428 G_CALLBACK(vdlist_pop_menu_tree_cb), vdl); | |
356 | 429 menu_item_add_check(menu, _("Show _hidden files"), options->file_filter.show_hidden_files, |
430 G_CALLBACK(vdlist_toggle_show_hidden_files_cb), vdl); | |
355
0b82646e977f
Let toggle the visibility of hidden files from directories list
zas_
parents:
281
diff
changeset
|
431 |
9 | 432 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, |
433 G_CALLBACK(vdlist_pop_menu_refresh_cb), vdl); | |
434 | |
435 return menu; | |
436 } | |
437 | |
438 static void vdlist_popup_destroy_cb(GtkWidget *widget, gpointer data) | |
439 { | |
440 ViewDirList *vdl = data; | |
441 | |
442 vdlist_color_set(vdl, vdl->click_fd, FALSE); | |
443 vdl->click_fd = NULL; | |
444 vdl->popup = NULL; | |
445 | |
446 vdlist_color_set(vdl, vdl->drop_fd, FALSE); | |
138 | 447 filelist_free(vdl->drop_list); |
9 | 448 vdl->drop_list = NULL; |
449 vdl->drop_fd = NULL; | |
450 } | |
451 | |
452 /* | |
453 *----------------------------------------------------------------------------- | |
454 * dnd | |
455 *----------------------------------------------------------------------------- | |
456 */ | |
457 | |
458 static GtkTargetEntry vdlist_dnd_drop_types[] = { | |
459 { "text/uri-list", 0, TARGET_URI_LIST } | |
460 }; | |
461 static gint vdlist_dnd_drop_types_count = 1; | |
462 | |
463 static void vdlist_dest_set(ViewDirList *vdl, gint enable) | |
464 { | |
465 if (enable) | |
466 { | |
467 gtk_drag_dest_set(vdl->listview, | |
468 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, | |
469 vdlist_dnd_drop_types, vdlist_dnd_drop_types_count, | |
470 GDK_ACTION_MOVE | GDK_ACTION_COPY); | |
471 } | |
472 else | |
473 { | |
474 gtk_drag_dest_unset(vdl->listview); | |
475 } | |
476 } | |
477 | |
478 static void vdlist_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
479 GtkSelectionData *selection_data, guint info, | |
480 guint time, gpointer data) | |
481 { | |
482 ViewDirList *vdl = data; | |
483 GList *list; | |
484 gchar *text = NULL; | |
485 gint length = 0; | |
486 | |
487 if (!vdl->click_fd) return; | |
488 | |
489 switch (info) | |
490 { | |
491 case TARGET_URI_LIST: | |
492 case TARGET_TEXT_PLAIN: | |
138 | 493 list = g_list_prepend(NULL, vdl->click_fd); |
494 text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN)); | |
9 | 495 g_list_free(list); |
496 break; | |
497 } | |
498 if (text) | |
499 { | |
500 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:
44
diff
changeset
|
501 8, (guchar *)text, length); |
9 | 502 g_free(text); |
503 } | |
504 } | |
505 | |
506 static void vdlist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
507 { | |
508 ViewDirList *vdl = data; | |
509 | |
510 vdlist_color_set(vdl, vdl->click_fd, TRUE); | |
511 vdlist_dest_set(vdl, FALSE); | |
512 } | |
513 | |
514 static void vdlist_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
515 { | |
516 ViewDirList *vdl = data; | |
517 | |
518 vdlist_color_set(vdl, vdl->click_fd, FALSE); | |
519 | |
520 if (context->action == GDK_ACTION_MOVE) | |
521 { | |
522 vdlist_refresh(vdl); | |
523 } | |
524 vdlist_dest_set(vdl, TRUE); | |
525 } | |
526 | |
527 static void vdlist_dnd_drop_receive(GtkWidget *widget, | |
528 GdkDragContext *context, gint x, gint y, | |
529 GtkSelectionData *selection_data, guint info, | |
530 guint time, gpointer data) | |
531 { | |
532 ViewDirList *vdl = data; | |
533 GtkTreePath *tpath; | |
534 GtkTreeIter iter; | |
535 FileData *fd = NULL; | |
536 | |
537 vdl->click_fd = NULL; | |
538 | |
539 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, | |
540 &tpath, NULL, NULL, NULL)) | |
541 { | |
542 GtkTreeModel *store; | |
543 | |
544 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
545 gtk_tree_model_get_iter(store, &iter, tpath); | |
546 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
547 gtk_tree_path_free(tpath); | |
548 } | |
549 | |
550 if (!fd) return; | |
551 | |
552 if (info == TARGET_URI_LIST) | |
553 { | |
554 GList *list; | |
555 gint active; | |
556 | |
138 | 557 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); |
9 | 558 if (!list) return; |
559 | |
560 active = access_file(fd->path, W_OK | X_OK); | |
561 | |
562 vdlist_color_set(vdl, fd, TRUE); | |
563 vdl->popup = vdlist_drop_menu(vdl, active); | |
564 gtk_menu_popup(GTK_MENU(vdl->popup), NULL, NULL, NULL, NULL, 0, time); | |
565 | |
566 vdl->drop_fd = fd; | |
567 vdl->drop_list = list; | |
568 } | |
569 } | |
570 | |
571 #if 0 | |
572 static gint vdlist_get_row_visibility(ViewDirList *vdl, FileData *fd) | |
573 { | |
574 GtkTreeModel *store; | |
575 GtkTreeViewColumn *column; | |
576 GtkTreePath *tpath; | |
577 GtkTreeIter iter; | |
578 | |
579 GdkRectangle vrect; | |
580 GdkRectangle crect; | |
581 | |
582 if (!fd || vdlist_find_row(vdl, fd, &iter) < 0) return 0; | |
583 | |
584 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vdl->listview), 0); | |
585 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
586 tpath = gtk_tree_model_get_path(store, &iter); | |
587 | |
588 gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(vdl->listview), &vrect); | |
589 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(vdl->listview), tpath, column, &crect); | |
590 printf("window: %d + %d; cell: %d + %d\n", vrect.y, vrect.height, crect.y, crect.height); | |
591 gtk_tree_path_free(tpath); | |
592 | |
593 if (crect.y + crect.height < vrect.y) return -1; | |
594 if (crect.y > vrect.y + vrect.height) return 1; | |
595 return 0; | |
596 } | |
597 #endif | |
598 | |
599 static void vdlist_scroll_to_row(ViewDirList *vdl, FileData *fd, gfloat y_align) | |
600 { | |
601 GtkTreeIter iter; | |
602 | |
603 if (GTK_WIDGET_REALIZED(vdl->listview) && | |
604 vdlist_find_row(vdl, fd, &iter) >= 0) | |
605 { | |
606 GtkTreeModel *store; | |
607 GtkTreePath *tpath; | |
608 | |
609 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
610 tpath = gtk_tree_model_get_path(store, &iter); | |
611 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vdl->listview), tpath, NULL, TRUE, y_align, 0.0); | |
612 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vdl->listview), tpath, NULL, FALSE); | |
613 gtk_tree_path_free(tpath); | |
614 | |
615 if (!GTK_WIDGET_HAS_FOCUS(vdl->listview)) gtk_widget_grab_focus(vdl->listview); | |
616 } | |
617 } | |
618 | |
619 static void vdlist_drop_update(ViewDirList *vdl, gint x, gint y) | |
620 { | |
621 GtkTreePath *tpath; | |
622 GtkTreeIter iter; | |
623 FileData *fd = NULL; | |
624 | |
625 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vdl->listview), x, y, | |
626 &tpath, NULL, NULL, NULL)) | |
627 { | |
628 GtkTreeModel *store; | |
629 | |
630 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
631 gtk_tree_model_get_iter(store, &iter, tpath); | |
632 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
633 gtk_tree_path_free(tpath); | |
634 } | |
635 | |
636 if (fd != vdl->drop_fd) | |
637 { | |
638 vdlist_color_set(vdl, vdl->drop_fd, FALSE); | |
639 vdlist_color_set(vdl, fd, TRUE); | |
640 } | |
641 | |
642 vdl->drop_fd = fd; | |
643 } | |
644 | |
645 static void vdlist_dnd_drop_scroll_cancel(ViewDirList *vdl) | |
646 { | |
647 if (vdl->drop_scroll_id != -1) g_source_remove(vdl->drop_scroll_id); | |
648 vdl->drop_scroll_id = -1; | |
649 } | |
650 | |
651 static gint vdlist_auto_scroll_idle_cb(gpointer data) | |
652 { | |
653 ViewDirList *vdl = data; | |
654 | |
655 if (vdl->drop_fd) | |
656 { | |
657 GdkWindow *window; | |
658 gint x, y; | |
659 gint w, h; | |
660 | |
661 window = vdl->listview->window; | |
662 gdk_window_get_pointer(window, &x, &y, NULL); | |
663 gdk_drawable_get_size(window, &w, &h); | |
664 if (x >= 0 && x < w && y >= 0 && y < h) | |
665 { | |
666 vdlist_drop_update(vdl, x, y); | |
667 } | |
668 } | |
669 | |
670 vdl->drop_scroll_id = -1; | |
671 return FALSE; | |
672 } | |
673 | |
674 static gint vdlist_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data) | |
675 { | |
676 ViewDirList *vdl = data; | |
677 | |
678 if (!vdl->drop_fd || vdl->drop_list) return FALSE; | |
679 | |
680 if (vdl->drop_scroll_id == -1) vdl->drop_scroll_id = g_idle_add(vdlist_auto_scroll_idle_cb, vdl); | |
681 | |
682 return TRUE; | |
683 } | |
684 | |
685 static gint vdlist_dnd_drop_motion(GtkWidget *widget, GdkDragContext *context, | |
686 gint x, gint y, guint time, gpointer data) | |
687 { | |
688 ViewDirList *vdl = data; | |
689 | |
690 vdl->click_fd = NULL; | |
691 | |
692 if (gtk_drag_get_source_widget(context) == vdl->listview) | |
693 { | |
694 /* from same window */ | |
695 gdk_drag_status(context, 0, time); | |
696 return TRUE; | |
697 } | |
698 else | |
699 { | |
700 gdk_drag_status(context, context->suggested_action, time); | |
701 } | |
702 | |
703 vdlist_drop_update(vdl, x, y); | |
704 | |
705 if (vdl->drop_fd) | |
706 { | |
707 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vdl->listview)); | |
708 widget_auto_scroll_start(vdl->listview, adj, -1, -1, vdlist_auto_scroll_notify_cb, vdl); | |
709 } | |
710 | |
711 return FALSE; | |
712 } | |
713 | |
714 static void vdlist_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | |
715 { | |
716 ViewDirList *vdl = data; | |
717 | |
718 if (vdl->drop_fd != vdl->click_fd) vdlist_color_set(vdl, vdl->drop_fd, FALSE); | |
719 | |
720 vdl->drop_fd = NULL; | |
721 } | |
722 | |
723 static void vdlist_dnd_init(ViewDirList *vdl) | |
724 { | |
725 gtk_drag_source_set(vdl->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
726 dnd_file_drag_types, dnd_file_drag_types_count, | |
727 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
728 g_signal_connect(G_OBJECT(vdl->listview), "drag_data_get", | |
729 G_CALLBACK(vdlist_dnd_get), vdl); | |
730 g_signal_connect(G_OBJECT(vdl->listview), "drag_begin", | |
731 G_CALLBACK(vdlist_dnd_begin), vdl); | |
732 g_signal_connect(G_OBJECT(vdl->listview), "drag_end", | |
733 G_CALLBACK(vdlist_dnd_end), vdl); | |
734 | |
735 vdlist_dest_set(vdl, TRUE); | |
736 g_signal_connect(G_OBJECT(vdl->listview), "drag_data_received", | |
737 G_CALLBACK(vdlist_dnd_drop_receive), vdl); | |
738 g_signal_connect(G_OBJECT(vdl->listview), "drag_motion", | |
739 G_CALLBACK(vdlist_dnd_drop_motion), vdl); | |
740 g_signal_connect(G_OBJECT(vdl->listview), "drag_leave", | |
741 G_CALLBACK(vdlist_dnd_drop_leave), vdl); | |
742 } | |
743 | |
744 /* | |
745 *----------------------------------------------------------------------------- | |
746 * main | |
747 *----------------------------------------------------------------------------- | |
748 */ | |
749 | |
750 static void vdlist_select_row(ViewDirList *vdl, FileData *fd) | |
751 { | |
752 if (fd && vdl->select_func) | |
753 { | |
754 gchar *path; | |
755 | |
756 path = g_strdup(fd->path); | |
757 vdl->select_func(vdl, path, vdl->select_data); | |
758 g_free(path); | |
759 } | |
760 } | |
761 | |
762 const gchar *vdlist_row_get_path(ViewDirList *vdl, gint row) | |
763 { | |
764 FileData *fd; | |
765 | |
766 fd = g_list_nth_data(vdl->list, row); | |
767 | |
768 if (fd) return fd->path; | |
769 | |
770 return NULL; | |
771 } | |
772 | |
773 static void vdlist_populate(ViewDirList *vdl) | |
774 { | |
775 GtkListStore *store; | |
776 GList *work; | |
777 | |
778 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview))); | |
779 gtk_list_store_clear(store); | |
780 | |
781 work = vdl->list; | |
782 while (work) | |
783 { | |
784 FileData *fd; | |
785 GtkTreeIter iter; | |
786 GdkPixbuf *pixbuf; | |
787 | |
788 fd = work->data; | |
789 | |
790 if (access_file(fd->path, R_OK | X_OK) && fd->name) | |
791 { | |
792 if (fd->name[0] == '.' && fd->name[1] == '\0') | |
793 { | |
794 pixbuf = vdl->pf->open; | |
795 } | |
796 else if (fd->name[0] == '.' && fd->name[1] == '.' && fd->name[2] == '\0') | |
797 { | |
798 pixbuf = vdl->pf->parent; | |
799 } | |
800 else | |
801 { | |
802 pixbuf = vdl->pf->close; | |
803 } | |
804 } | |
805 else | |
806 { | |
807 pixbuf = vdl->pf->deny; | |
808 } | |
809 | |
810 gtk_list_store_append(store, &iter); | |
811 gtk_list_store_set(store, &iter, | |
812 DIR_COLUMN_POINTER, fd, | |
813 DIR_COLUMN_ICON, pixbuf, | |
814 DIR_COLUMN_NAME, fd->name, -1); | |
815 | |
816 work = work->next; | |
817 } | |
818 | |
819 vdl->click_fd = NULL; | |
820 vdl->drop_fd = NULL; | |
821 } | |
822 | |
823 gint vdlist_set_path(ViewDirList *vdl, const gchar *path) | |
824 { | |
825 gint ret; | |
826 FileData *fd; | |
827 gchar *old_path = NULL; | |
138 | 828 gchar *filepath; |
9 | 829 |
830 if (!path) return FALSE; | |
831 if (vdl->path && strcmp(path, vdl->path) == 0) return TRUE; | |
832 | |
833 if (vdl->path) | |
834 { | |
835 gchar *base; | |
836 | |
837 base = remove_level_from_path(vdl->path); | |
838 if (strcmp(base, path) == 0) | |
839 { | |
840 old_path = g_strdup(filename_from_path(vdl->path)); | |
841 } | |
842 g_free(base); | |
843 } | |
844 | |
845 g_free(vdl->path); | |
846 vdl->path = g_strdup(path); | |
847 | |
848 filelist_free(vdl->list); | |
849 vdl->list = NULL; | |
850 | |
851 ret = filelist_read(vdl->path, NULL, &vdl->list); | |
852 | |
853 vdl->list = filelist_sort(vdl->list, SORT_NAME, TRUE); | |
854 | |
855 /* add . and .. */ | |
856 | |
857 if (strcmp(vdl->path, "/") != 0) | |
858 { | |
138 | 859 filepath = g_strconcat(vdl->path, "/", "..", NULL); |
860 fd = file_data_new_simple(filepath); | |
9 | 861 vdl->list = g_list_prepend(vdl->list, fd); |
138 | 862 g_free(filepath); |
9 | 863 } |
138 | 864 filepath = g_strconcat(vdl->path, "/", ".", NULL); |
865 fd = file_data_new_simple(filepath); | |
9 | 866 vdl->list = g_list_prepend(vdl->list, fd); |
138 | 867 g_free(filepath); |
9 | 868 |
869 vdlist_populate(vdl); | |
870 | |
871 if (old_path) | |
872 { | |
873 /* scroll to make last path visible */ | |
874 FileData *found = NULL; | |
875 GList *work; | |
876 | |
877 work = vdl->list; | |
878 while (work && !found) | |
879 { | |
880 FileData *fd = work->data; | |
881 if (strcmp(old_path, fd->name) == 0) found = fd; | |
882 work = work->next; | |
883 } | |
884 | |
885 if (found) vdlist_scroll_to_row(vdl, found, 0.5); | |
886 | |
887 g_free(old_path); | |
888 return ret; | |
889 } | |
890 | |
891 if (GTK_WIDGET_REALIZED(vdl->listview)) | |
892 { | |
893 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vdl->listview), 0, 0); | |
894 } | |
895 | |
896 return ret; | |
897 } | |
898 | |
899 void vdlist_refresh(ViewDirList *vdl) | |
900 { | |
901 gchar *path; | |
902 | |
903 path = g_strdup(vdl->path); | |
904 vdl->path = NULL; | |
905 vdlist_set_path(vdl, path); | |
906 g_free(path); | |
907 } | |
908 | |
909 static void vdlist_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
910 { | |
911 ViewDirList *vdl = data; | |
912 GtkTreeModel *store; | |
913 GtkTreeIter iter; | |
914 GtkTreePath *tpath; | |
915 gint cw, ch; | |
916 | |
917 if (vdlist_find_row(vdl, vdl->click_fd, &iter) < 0) return; | |
918 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
919 tpath = gtk_tree_model_get_path(store, &iter); | |
920 tree_view_get_cell_clamped(GTK_TREE_VIEW(vdl->listview), tpath, 0, TRUE, x, y, &cw, &ch); | |
921 gtk_tree_path_free(tpath); | |
922 *y += ch; | |
923 popup_menu_position_clamp(menu, x, y, 0); | |
924 } | |
925 | |
926 static gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
927 { | |
928 ViewDirList *vdl = data; | |
929 GtkTreePath *tpath; | |
930 | |
931 if (event->keyval != GDK_Menu) return FALSE; | |
932 | |
933 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vdl->listview), &tpath, NULL); | |
934 if (tpath) | |
935 { | |
936 GtkTreeModel *store; | |
937 GtkTreeIter iter; | |
938 | |
939 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
940 gtk_tree_model_get_iter(store, &iter, tpath); | |
941 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &vdl->click_fd, -1); | |
942 | |
943 gtk_tree_path_free(tpath); | |
944 } | |
945 else | |
946 { | |
947 vdl->click_fd = NULL; | |
948 } | |
949 | |
950 vdlist_color_set(vdl, vdl->click_fd, TRUE); | |
951 | |
952 vdl->popup = vdlist_pop_menu(vdl, vdl->click_fd); | |
953 | |
954 gtk_menu_popup(GTK_MENU(vdl->popup), NULL, NULL, vdlist_menu_position_cb, vdl, 0, GDK_CURRENT_TIME); | |
955 | |
956 return TRUE; | |
957 } | |
958 | |
959 static gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
960 { | |
961 ViewDirList *vdl = data; | |
962 GtkTreePath *tpath; | |
963 GtkTreeIter iter; | |
964 FileData *fd = NULL; | |
965 | |
966 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
967 &tpath, NULL, NULL, NULL)) | |
968 { | |
969 GtkTreeModel *store; | |
970 | |
971 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
972 gtk_tree_model_get_iter(store, &iter, tpath); | |
973 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
974 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
975 gtk_tree_path_free(tpath); | |
976 } | |
977 | |
978 vdl->click_fd = fd; | |
979 vdlist_color_set(vdl, vdl->click_fd, TRUE); | |
980 | |
981 if (bevent->button == 3) | |
982 { | |
983 vdl->popup = vdlist_pop_menu(vdl, vdl->click_fd); | |
984 gtk_menu_popup(GTK_MENU(vdl->popup), NULL, NULL, NULL, NULL, | |
985 bevent->button, bevent->time); | |
986 } | |
987 | |
988 return TRUE; | |
989 } | |
990 | |
991 static gint vdlist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
992 { | |
993 ViewDirList *vdl = data; | |
994 GtkTreePath *tpath; | |
995 GtkTreeIter iter; | |
996 FileData *fd = NULL; | |
997 | |
998 vdlist_color_set(vdl, vdl->click_fd, FALSE); | |
999 | |
1000 if (bevent->button != 1) return TRUE; | |
1001 | |
1002 if ((bevent->x != 0 || bevent->y != 0) && | |
1003 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1004 &tpath, NULL, NULL, NULL)) | |
1005 { | |
1006 GtkTreeModel *store; | |
1007 | |
1008 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1009 gtk_tree_model_get_iter(store, &iter, tpath); | |
1010 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
1011 gtk_tree_path_free(tpath); | |
1012 } | |
1013 | |
1014 if (fd && vdl->click_fd == fd) | |
1015 { | |
1016 vdlist_select_row(vdl, vdl->click_fd); | |
1017 } | |
1018 | |
1019 return TRUE; | |
1020 } | |
1021 | |
1022 static void vdlist_select_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
1023 { | |
1024 ViewDirList *vdl = data; | |
1025 GtkTreeModel *store; | |
1026 GtkTreeIter iter; | |
1027 FileData *fd; | |
1028 | |
1029 store = gtk_tree_view_get_model(tview); | |
1030 gtk_tree_model_get_iter(store, &iter, tpath); | |
1031 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
1032 | |
1033 vdlist_select_row(vdl, fd); | |
1034 } | |
1035 | |
1036 static GdkColor *vdlist_color_shifted(GtkWidget *widget) | |
1037 { | |
1038 static GdkColor color; | |
1039 static GtkWidget *done = NULL; | |
1040 | |
1041 if (done != widget) | |
1042 { | |
1043 GtkStyle *style; | |
1044 | |
1045 style = gtk_widget_get_style(widget); | |
1046 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
1047 shift_color(&color, -1, 0); | |
1048 done = widget; | |
1049 } | |
1050 | |
1051 return &color; | |
1052 } | |
1053 | |
1054 static void vdlist_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
1055 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
1056 { | |
1057 ViewDirList *vdl = data; | |
1058 gboolean set; | |
1059 | |
1060 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1); | |
1061 g_object_set(G_OBJECT(cell), | |
1062 "cell-background-gdk", vdlist_color_shifted(vdl->listview), | |
1063 "cell-background-set", set, NULL); | |
1064 } | |
1065 | |
1066 static void vdlist_destroy_cb(GtkWidget *widget, gpointer data) | |
1067 { | |
1068 ViewDirList *vdl = data; | |
1069 | |
1070 if (vdl->popup) | |
1071 { | |
1072 g_signal_handlers_disconnect_matched(G_OBJECT(vdl->popup), G_SIGNAL_MATCH_DATA, | |
1073 0, 0, 0, NULL, vdl); | |
1074 gtk_widget_destroy(vdl->popup); | |
1075 } | |
1076 | |
1077 vdlist_dnd_drop_scroll_cancel(vdl); | |
1078 widget_auto_scroll_stop(vdl->listview); | |
1079 | |
138 | 1080 filelist_free(vdl->drop_list); |
9 | 1081 |
1082 folder_icons_free(vdl->pf); | |
1083 | |
1084 g_free(vdl->path); | |
1085 filelist_free(vdl->list); | |
1086 g_free(vdl); | |
1087 } | |
1088 | |
1089 ViewDirList *vdlist_new(const gchar *path) | |
1090 { | |
1091 ViewDirList *vdl; | |
1092 GtkListStore *store; | |
1093 GtkTreeSelection *selection; | |
1094 GtkTreeViewColumn *column; | |
1095 GtkCellRenderer *renderer; | |
1096 | |
1097 vdl = g_new0(ViewDirList, 1); | |
1098 | |
1099 vdl->path = NULL; | |
1100 vdl->list = NULL; | |
1101 vdl->click_fd = NULL; | |
1102 | |
1103 vdl->drop_fd = NULL; | |
1104 vdl->drop_list = NULL; | |
1105 | |
1106 vdl->drop_scroll_id = -1; | |
1107 | |
1108 vdl->popup = NULL; | |
1109 | |
1110 vdl->widget = gtk_scrolled_window_new(NULL, NULL); | |
1111 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vdl->widget), GTK_SHADOW_IN); | |
1112 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vdl->widget), | |
1113 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1114 g_signal_connect(G_OBJECT(vdl->widget), "destroy", | |
1115 G_CALLBACK(vdlist_destroy_cb), vdl); | |
1116 | |
1117 store = gtk_list_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
1118 vdl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
1119 g_object_unref(store); | |
1120 | |
1121 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vdl->listview), FALSE); | |
1122 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vdl->listview), FALSE); | |
1123 g_signal_connect(G_OBJECT(vdl->listview), "row_activated", | |
1124 | |
1125 G_CALLBACK(vdlist_select_cb), vdl); | |
1126 | |
1127 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdl->listview)); | |
1128 gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); | |
1129 | |
1130 column = gtk_tree_view_column_new(); | |
1131 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
1132 | |
1133 renderer = gtk_cell_renderer_pixbuf_new(); | |
1134 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
1135 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
1136 gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vdl, NULL); | |
1137 | |
1138 renderer = gtk_cell_renderer_text_new(); | |
1139 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
1140 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
1141 gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vdl, NULL); | |
1142 | |
1143 gtk_tree_view_append_column(GTK_TREE_VIEW(vdl->listview), column); | |
1144 | |
1145 g_signal_connect(G_OBJECT(vdl->listview), "key_press_event", | |
1146 G_CALLBACK(vdlist_press_key_cb), vdl); | |
1147 gtk_container_add(GTK_CONTAINER(vdl->widget), vdl->listview); | |
1148 gtk_widget_show(vdl->listview); | |
1149 | |
1150 vdl->pf = folder_icons_new(); | |
1151 | |
1152 vdlist_dnd_init(vdl); | |
1153 | |
1154 g_signal_connect(G_OBJECT(vdl->listview), "button_press_event", | |
1155 G_CALLBACK(vdlist_press_cb), vdl); | |
1156 g_signal_connect(G_OBJECT(vdl->listview), "button_release_event", | |
1157 G_CALLBACK(vdlist_release_cb), vdl); | |
1158 | |
1159 if (path) vdlist_set_path(vdl, path); | |
1160 | |
1161 return vdl; | |
1162 } | |
1163 | |
1164 void vdlist_set_select_func(ViewDirList *vdl, | |
1165 void (*func)(ViewDirList *vdl, const gchar *path, gpointer data), gpointer data) | |
1166 { | |
1167 vdl->select_func = func; | |
1168 vdl->select_data = data; | |
1169 } | |
1170 | |
1171 void vdlist_set_layout(ViewDirList *vdl, LayoutWindow *layout) | |
1172 { | |
1173 vdl->layout = layout; | |
1174 } | |
1175 |