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