Mercurial > geeqie.yaz
annotate src/view_file_icon.c @ 497:a33badd85f16
Allow the copy of file paths to clipboard.
This feature is disabled by default, it can be set through
Preferences > Advanced > Behavior > Show "Copy path" ...
When enabled, it adds a menu entry "Copy path" that let the
user copies current selection's paths to X clipboard.
It is very convenient to paste paths to xterm for example.
Patch by Carles Pina i Estany and me.
author | zas_ |
---|---|
date | Wed, 23 Apr 2008 22:17:21 +0000 |
parents | c7a2471e5c4e |
children | cc46a09d0805 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
3 * (C) 2006 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
281 | 13 #include "main.h" |
9 | 14 #include "view_file_icon.h" |
15 | |
16 #include "cellrenderericon.h" | |
17 #include "collect.h" | |
18 #include "collect-io.h" | |
19 #include "collect-table.h" | |
20 #include "dnd.h" | |
21 #include "editors.h" | |
22 #include "img-view.h" | |
23 #include "info.h" | |
24 #include "filelist.h" | |
25 #include "layout.h" | |
26 #include "layout_image.h" | |
27 #include "menu.h" | |
28 #include "thumb.h" | |
29 #include "utilops.h" | |
30 #include "ui_bookmark.h" | |
31 #include "ui_fileops.h" | |
32 #include "ui_menu.h" | |
33 #include "ui_tree_edit.h" | |
34 | |
35 | |
36 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
37 | |
38 /* between these, the icon width is increased by thumb_max_width / 2 */ | |
39 #define THUMB_MIN_ICON_WIDTH 128 | |
40 #define THUMB_MAX_ICON_WIDTH 150 | |
41 | |
42 #define VFICON_MAX_COLUMNS 32 | |
43 #define THUMB_BORDER_PADDING 2 | |
44 | |
45 #define VFICON_TIP_DELAY 500 | |
46 | |
47 enum { | |
48 FILE_COLUMN_POINTER = 0, | |
49 FILE_COLUMN_COUNT | |
50 }; | |
51 | |
52 typedef enum { | |
53 SELECTION_NONE = 0, | |
54 SELECTION_SELECTED = 1 << 0, | |
55 SELECTION_PRELIGHT = 1 << 1, | |
56 SELECTION_FOCUS = 1 << 2 | |
57 } SelectionType; | |
58 | |
59 typedef struct _IconData IconData; | |
60 struct _IconData | |
61 { | |
62 SelectionType selected; | |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
63 gint row; |
138 | 64 FileData *fd; |
9 | 65 }; |
66 | |
138 | 67 static gint vficon_index_by_id(ViewFileIcon *vfi, IconData *in_id); |
68 | |
69 static IconData *vficon_icon_data(ViewFileIcon *vfi, FileData *fd) | |
70 { | |
71 IconData *id = NULL; | |
72 GList *work; | |
73 | |
74 if (!fd) return NULL; | |
75 work = vfi->list; | |
76 while (work && !id) | |
77 { | |
78 IconData *chk = work->data; | |
79 work = work->next; | |
80 if (chk->fd == fd) id = chk; | |
81 } | |
82 return id; | |
83 } | |
84 | |
9 | 85 |
86 static gint iconlist_read(const gchar *path, GList **list) | |
87 { | |
88 GList *temp; | |
89 GList *work; | |
90 | |
91 if (!filelist_read(path, &temp, NULL)) return FALSE; | |
92 | |
93 work = temp; | |
94 while (work) | |
95 { | |
96 FileData *fd; | |
97 IconData *id; | |
98 | |
99 fd = work->data; | |
442 | 100 g_assert(fd->magick == 0x12345678); |
9 | 101 id = g_new0(IconData, 1); |
102 | |
103 id->selected = SELECTION_NONE; | |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
104 id->row = -1; |
138 | 105 id->fd = fd; |
9 | 106 |
107 work->data = id; | |
108 work = work->next; | |
109 } | |
110 | |
111 *list = temp; | |
112 | |
113 return TRUE; | |
114 } | |
115 | |
116 static void iconlist_free(GList *list) | |
117 { | |
138 | 118 GList *work = list; |
119 while (work) | |
120 { | |
121 IconData *id = work->data; | |
122 file_data_unref(id->fd); | |
123 g_free(id); | |
442 | 124 work = work->next; |
125 } | |
126 | |
127 g_list_free(list); | |
138 | 128 |
129 } | |
130 | |
131 gint iconlist_sort_file_cb(void *a, void *b) | |
132 { | |
133 IconData *ida = a; | |
134 IconData *idb = b; | |
135 return filelist_sort_compare_filedata(ida->fd, idb->fd); | |
136 } | |
137 GList *iconlist_sort(GList *list, SortType method, gint ascend) | |
138 { | |
139 return filelist_sort_full(list, method, ascend, (GCompareFunc) iconlist_sort_file_cb); | |
140 } | |
141 | |
142 GList *iconlist_insert_sort(GList *list, IconData *id, SortType method, gint ascend) | |
143 { | |
144 return filelist_insert_sort_full(list, id, method, ascend, (GCompareFunc) iconlist_sort_file_cb); | |
9 | 145 } |
146 | |
147 | |
148 static void vficon_toggle_filenames(ViewFileIcon *vfi); | |
138 | 149 static void vficon_selection_remove(ViewFileIcon *vfi, IconData *id, SelectionType mask, GtkTreeIter *iter); |
9 | 150 static void vficon_move_focus(ViewFileIcon *vfi, gint row, gint col, gint relative); |
138 | 151 static void vficon_set_focus(ViewFileIcon *vfi, IconData *id); |
9 | 152 static void vficon_thumb_update(ViewFileIcon *vfi); |
153 static void vficon_populate_at_new_size(ViewFileIcon *vfi, gint w, gint h, gint force); | |
154 | |
155 | |
156 /* | |
157 *----------------------------------------------------------------------------- | |
158 * pop-up menu | |
159 *----------------------------------------------------------------------------- | |
160 */ | |
161 | |
162 static GList *vficon_pop_menu_file_list(ViewFileIcon *vfi) | |
163 { | |
138 | 164 if (!vfi->click_id) return NULL; |
165 | |
166 if (vfi->click_id->selected & SELECTION_SELECTED) | |
9 | 167 { |
168 return vficon_selection_get_list(vfi); | |
169 } | |
170 | |
138 | 171 return g_list_append(NULL, file_data_ref(vfi->click_id->fd)); |
9 | 172 } |
173 | |
174 static void vficon_pop_menu_edit_cb(GtkWidget *widget, gpointer data) | |
175 { | |
176 ViewFileIcon *vfi; | |
177 gint n; | |
178 GList *list; | |
179 | |
180 vfi = submenu_item_get_data(widget); | |
181 n = GPOINTER_TO_INT(data); | |
182 | |
183 if (!vfi) return; | |
184 | |
185 list = vficon_pop_menu_file_list(vfi); | |
138 | 186 start_editor_from_filelist(n, list); |
187 filelist_free(list); | |
9 | 188 } |
189 | |
190 static void vficon_pop_menu_info_cb(GtkWidget *widget, gpointer data) | |
191 { | |
192 ViewFileIcon *vfi = data; | |
193 | |
479
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
194 info_window_new(NULL, vficon_pop_menu_file_list(vfi), NULL); |
9 | 195 } |
196 | |
197 static void vficon_pop_menu_view_cb(GtkWidget *widget, gpointer data) | |
198 { | |
199 ViewFileIcon *vfi = data; | |
200 | |
138 | 201 if (!vfi->click_id) return; |
202 | |
203 if (vfi->click_id->selected & SELECTION_SELECTED) | |
9 | 204 { |
205 GList *list; | |
442 | 206 |
9 | 207 list = vficon_selection_get_list(vfi); |
208 view_window_new_from_list(list); | |
138 | 209 filelist_free(list); |
9 | 210 } |
211 else | |
212 { | |
138 | 213 view_window_new(vfi->click_id->fd); |
9 | 214 } |
215 } | |
216 | |
217 static void vficon_pop_menu_copy_cb(GtkWidget *widget, gpointer data) | |
218 { | |
219 ViewFileIcon *vfi = data; | |
220 | |
221 file_util_copy(NULL, vficon_pop_menu_file_list(vfi), NULL, vfi->listview); | |
222 } | |
223 | |
224 static void vficon_pop_menu_move_cb(GtkWidget *widget, gpointer data) | |
225 { | |
226 ViewFileIcon *vfi = data; | |
227 | |
228 file_util_move(NULL, vficon_pop_menu_file_list(vfi), NULL, vfi->listview); | |
229 } | |
230 | |
231 static void vficon_pop_menu_rename_cb(GtkWidget *widget, gpointer data) | |
232 { | |
233 ViewFileIcon *vfi = data; | |
234 | |
235 file_util_rename(NULL, vficon_pop_menu_file_list(vfi), vfi->listview); | |
236 } | |
237 | |
238 static void vficon_pop_menu_delete_cb(GtkWidget *widget, gpointer data) | |
239 { | |
240 ViewFileIcon *vfi = data; | |
241 | |
242 file_util_delete(NULL, vficon_pop_menu_file_list(vfi), vfi->listview); | |
243 } | |
244 | |
497 | 245 static void vficon_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data) |
246 { | |
247 ViewFileIcon *vfi = data; | |
248 | |
249 file_util_copy_path_list_to_clipboard(vficon_pop_menu_file_list(vfi)); | |
250 } | |
251 | |
9 | 252 static void vficon_pop_menu_sort_cb(GtkWidget *widget, gpointer data) |
253 { | |
254 ViewFileIcon *vfi; | |
255 SortType type; | |
113
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
111
diff
changeset
|
256 |
55166d93498d
Fri Nov 24 21:37:01 2006 John Ellis <johne@verizon.net>
gqview
parents:
111
diff
changeset
|
257 if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) return; |
442 | 258 |
9 | 259 vfi = submenu_item_get_data(widget); |
260 if (!vfi) return; | |
261 | |
262 type = (SortType)GPOINTER_TO_INT(data); | |
263 | |
264 if (vfi->layout) | |
265 { | |
266 layout_sort_set(vfi->layout, type, vfi->sort_ascend); | |
267 } | |
268 else | |
269 { | |
270 vficon_sort_set(vfi, type, vfi->sort_ascend); | |
271 } | |
272 } | |
273 | |
274 static void vficon_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data) | |
275 { | |
276 ViewFileIcon *vfi = data; | |
277 | |
278 if (vfi->layout) | |
279 { | |
280 layout_sort_set(vfi->layout, vfi->sort_method, !vfi->sort_ascend); | |
281 } | |
282 else | |
283 { | |
284 vficon_sort_set(vfi, vfi->sort_method, !vfi->sort_ascend); | |
285 } | |
286 } | |
287 | |
288 static void vficon_pop_menu_list_cb(GtkWidget *widget, gpointer data) | |
289 { | |
290 ViewFileIcon *vfi = data; | |
291 | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
334
diff
changeset
|
292 if (vfi->layout) layout_views_set(vfi->layout, vfi->layout->dir_view_type, FALSE); |
9 | 293 } |
294 | |
295 static void vficon_pop_menu_show_names_cb(GtkWidget *widget, gpointer data) | |
296 { | |
297 ViewFileIcon *vfi = data; | |
298 | |
299 vficon_toggle_filenames(vfi); | |
300 } | |
301 | |
302 static void vficon_pop_menu_refresh_cb(GtkWidget *widget, gpointer data) | |
303 { | |
304 ViewFileIcon *vfi = data; | |
305 | |
306 vficon_refresh(vfi); | |
307 } | |
308 | |
309 static void vficon_popup_destroy_cb(GtkWidget *widget, gpointer data) | |
310 { | |
442 | 311 ViewFileIcon *vfi = data; |
138 | 312 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); |
313 vfi->click_id = NULL; | |
9 | 314 vfi->popup = NULL; |
315 } | |
316 | |
317 static GtkWidget *vficon_pop_menu(ViewFileIcon *vfi, gint active) | |
318 { | |
319 GtkWidget *menu; | |
320 GtkWidget *item; | |
321 GtkWidget *submenu; | |
322 | |
323 menu = popup_menu_short_lived(); | |
324 | |
325 g_signal_connect(G_OBJECT(menu), "destroy", | |
326 G_CALLBACK(vficon_popup_destroy_cb), vfi); | |
327 | |
328 submenu_add_edit(menu, &item, G_CALLBACK(vficon_pop_menu_edit_cb), vfi); | |
329 gtk_widget_set_sensitive(item, active); | |
330 | |
331 item = menu_item_add_stock(menu, _("_Properties"), GTK_STOCK_PROPERTIES, G_CALLBACK(vficon_pop_menu_info_cb), vfi); | |
332 gtk_widget_set_sensitive(item, active); | |
333 | |
334 item = menu_item_add_stock(menu, _("View in _new window"), GTK_STOCK_NEW, G_CALLBACK(vficon_pop_menu_view_cb), vfi); | |
335 gtk_widget_set_sensitive(item, active); | |
336 | |
337 menu_item_add_divider(menu); | |
338 item = menu_item_add_stock(menu, _("_Copy..."), GTK_STOCK_COPY, G_CALLBACK(vficon_pop_menu_copy_cb), vfi); | |
339 gtk_widget_set_sensitive(item, active); | |
340 item = menu_item_add(menu, _("_Move..."), G_CALLBACK(vficon_pop_menu_move_cb), vfi); | |
341 gtk_widget_set_sensitive(item, active); | |
342 item = menu_item_add(menu, _("_Rename..."), G_CALLBACK(vficon_pop_menu_rename_cb), vfi); | |
343 gtk_widget_set_sensitive(item, active); | |
344 item = menu_item_add_stock(menu, _("_Delete..."), GTK_STOCK_DELETE, G_CALLBACK(vficon_pop_menu_delete_cb), vfi); | |
345 gtk_widget_set_sensitive(item, active); | |
497 | 346 if (options->show_copy_path) |
347 { | |
348 item = menu_item_add(menu, _("_Copy path"), G_CALLBACK(vficon_pop_menu_copy_path_cb), vfi); | |
349 gtk_widget_set_sensitive(item, active); | |
350 } | |
9 | 351 |
352 menu_item_add_divider(menu); | |
353 | |
354 submenu = submenu_add_sort(NULL, G_CALLBACK(vficon_pop_menu_sort_cb), vfi, | |
355 FALSE, FALSE, TRUE, vfi->sort_method); | |
356 menu_item_add_divider(submenu); | |
357 menu_item_add_check(submenu, _("Ascending"), vfi->sort_ascend, | |
358 G_CALLBACK(vficon_pop_menu_sort_ascend_cb), vfi); | |
359 | |
360 item = menu_item_add(menu, _("_Sort"), NULL, NULL); | |
361 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu); | |
362 | |
363 menu_item_add_check(menu, _("View as _icons"), TRUE, | |
364 G_CALLBACK(vficon_pop_menu_list_cb), vfi); | |
365 menu_item_add_check(menu, _("Show filename _text"), vfi->show_text, | |
366 G_CALLBACK(vficon_pop_menu_show_names_cb), vfi); | |
367 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, G_CALLBACK(vficon_pop_menu_refresh_cb), vfi); | |
368 | |
369 return menu; | |
370 } | |
371 | |
372 /* | |
373 *------------------------------------------------------------------- | |
374 * signals | |
375 *------------------------------------------------------------------- | |
376 */ | |
377 | |
378 static void vficon_send_update(ViewFileIcon *vfi) | |
379 { | |
380 if (vfi->func_status) vfi->func_status(vfi, vfi->data_status); | |
381 } | |
382 | |
138 | 383 static void vficon_send_layout_select(ViewFileIcon *vfi, IconData *id) |
9 | 384 { |
138 | 385 FileData *read_ahead_fd = NULL; |
144 | 386 FileData *sel_fd; |
387 FileData *cur_fd; | |
388 | |
389 if (!vfi->layout || !id || !id->fd) return; | |
390 | |
391 sel_fd = id->fd; | |
442 | 392 |
144 | 393 cur_fd = layout_image_get_fd(vfi->layout); |
394 if (sel_fd == cur_fd) return; /* no change */ | |
442 | 395 |
334 | 396 if (options->image.enable_read_ahead) |
9 | 397 { |
398 gint row; | |
399 | |
138 | 400 row = g_list_index(vfi->list, id); |
144 | 401 if (row > vficon_index_by_fd(vfi, cur_fd) && |
9 | 402 row + 1 < vficon_count(vfi, NULL)) |
403 { | |
144 | 404 read_ahead_fd = vficon_index_get_data(vfi, row + 1); |
9 | 405 } |
406 else if (row > 0) | |
407 { | |
144 | 408 read_ahead_fd = vficon_index_get_data(vfi, row - 1); |
9 | 409 } |
410 } | |
411 | |
144 | 412 layout_image_set_with_ahead(vfi->layout, sel_fd, read_ahead_fd); |
9 | 413 } |
414 | |
415 static void vficon_toggle_filenames(ViewFileIcon *vfi) | |
416 { | |
417 vfi->show_text = !vfi->show_text; | |
320 | 418 options->show_icon_names = vfi->show_text; |
9 | 419 |
420 vficon_populate_at_new_size(vfi, vfi->listview->allocation.width, vfi->listview->allocation.height, TRUE); | |
421 } | |
422 | |
423 static gint vficon_get_icon_width(ViewFileIcon *vfi) | |
424 { | |
425 gint width; | |
426 | |
333 | 427 if (!vfi->show_text) return options->thumbnails.max_width; |
428 | |
429 width = options->thumbnails.max_width + options->thumbnails.max_width / 2; | |
9 | 430 if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH; |
333 | 431 if (width > THUMB_MAX_ICON_WIDTH) width = options->thumbnails.max_width; |
9 | 432 |
433 return width; | |
434 } | |
435 | |
436 /* | |
437 *------------------------------------------------------------------- | |
438 * misc utils | |
439 *------------------------------------------------------------------- | |
440 */ | |
441 | |
138 | 442 static gint vficon_find_position(ViewFileIcon *vfi, IconData *id, gint *row, gint *col) |
9 | 443 { |
444 gint n; | |
445 | |
138 | 446 n = g_list_index(vfi->list, id); |
9 | 447 |
448 if (n < 0) return FALSE; | |
449 | |
450 *row = n / vfi->columns; | |
451 *col = n - (*row * vfi->columns); | |
452 | |
453 return TRUE; | |
454 } | |
455 | |
138 | 456 static gint vficon_find_iter(ViewFileIcon *vfi, IconData *id, GtkTreeIter *iter, gint *column) |
9 | 457 { |
458 GtkTreeModel *store; | |
459 gint row, col; | |
460 | |
461 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
138 | 462 if (!vficon_find_position(vfi, id, &row, &col)) return FALSE; |
9 | 463 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE; |
464 if (column) *column = col; | |
465 | |
466 return TRUE; | |
467 } | |
468 | |
138 | 469 static IconData *vficon_find_data(ViewFileIcon *vfi, gint row, gint col, GtkTreeIter *iter) |
9 | 470 { |
471 GtkTreeModel *store; | |
472 GtkTreeIter p; | |
473 | |
474 if (row < 0 || col < 0) return NULL; | |
475 | |
476 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
477 if (gtk_tree_model_iter_nth_child(store, &p, NULL, row)) | |
478 { | |
479 GList *list; | |
480 | |
481 gtk_tree_model_get(store, &p, FILE_COLUMN_POINTER, &list, -1); | |
482 if (!list) return NULL; | |
483 | |
484 if (iter) *iter = p; | |
485 | |
486 return g_list_nth_data(list, col); | |
487 } | |
488 | |
489 return NULL; | |
490 } | |
491 | |
138 | 492 static IconData *vficon_find_data_by_coord(ViewFileIcon *vfi, gint x, gint y, GtkTreeIter *iter) |
9 | 493 { |
494 GtkTreePath *tpath; | |
495 GtkTreeViewColumn *column; | |
496 | |
497 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), x, y, | |
498 &tpath, &column, NULL, NULL)) | |
499 { | |
500 GtkTreeModel *store; | |
501 GtkTreeIter row; | |
502 GList *list; | |
503 gint n; | |
504 | |
505 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
506 gtk_tree_model_get_iter(store, &row, tpath); | |
507 gtk_tree_path_free(tpath); | |
508 | |
509 gtk_tree_model_get(store, &row, FILE_COLUMN_POINTER, &list, -1); | |
510 | |
511 n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_number")); | |
512 if (list) | |
513 { | |
514 if (iter) *iter = row; | |
515 return g_list_nth_data(list, n); | |
516 } | |
517 } | |
518 | |
519 return NULL; | |
520 } | |
521 | |
522 /* | |
523 *------------------------------------------------------------------- | |
524 * tooltip type window | |
525 *------------------------------------------------------------------- | |
526 */ | |
527 | |
528 static void tip_show(ViewFileIcon *vfi) | |
529 { | |
530 GtkWidget *label; | |
531 gint x, y; | |
532 | |
533 if (vfi->tip_window) return; | |
534 | |
535 gdk_window_get_pointer(gtk_tree_view_get_bin_window(GTK_TREE_VIEW(vfi->listview)), &x, &y, NULL); | |
536 | |
138 | 537 vfi->tip_id = vficon_find_data_by_coord(vfi, x, y, NULL); |
538 if (!vfi->tip_id) return; | |
9 | 539 |
540 vfi->tip_window = gtk_window_new(GTK_WINDOW_POPUP); | |
541 gtk_window_set_resizable(GTK_WINDOW(vfi->tip_window), FALSE); | |
542 gtk_container_set_border_width(GTK_CONTAINER(vfi->tip_window), 2); | |
543 | |
138 | 544 label = gtk_label_new(vfi->tip_id->fd->name); |
9 | 545 |
546 g_object_set_data(G_OBJECT(vfi->tip_window), "tip_label", label); | |
547 gtk_container_add(GTK_CONTAINER(vfi->tip_window), label); | |
548 gtk_widget_show(label); | |
549 | |
550 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
551 | |
552 if (!GTK_WIDGET_REALIZED(vfi->tip_window)) gtk_widget_realize(vfi->tip_window); | |
553 gtk_window_move(GTK_WINDOW(vfi->tip_window), x + 16, y + 16); | |
554 gtk_widget_show(vfi->tip_window); | |
555 } | |
556 | |
557 static void tip_hide(ViewFileIcon *vfi) | |
558 { | |
559 if (vfi->tip_window) gtk_widget_destroy(vfi->tip_window); | |
560 vfi->tip_window = NULL; | |
561 } | |
562 | |
563 static gint tip_schedule_cb(gpointer data) | |
564 { | |
565 ViewFileIcon *vfi = data; | |
566 GtkWidget *window; | |
567 | |
568 if (vfi->tip_delay_id == -1) return FALSE; | |
569 | |
570 window = gtk_widget_get_toplevel(vfi->listview); | |
571 | |
572 if (GTK_WIDGET_SENSITIVE(window) && | |
573 GTK_WINDOW(window)->has_focus) | |
574 { | |
575 tip_show(vfi); | |
576 } | |
577 | |
578 vfi->tip_delay_id = -1; | |
579 return FALSE; | |
580 } | |
581 | |
582 static void tip_schedule(ViewFileIcon *vfi) | |
583 { | |
584 tip_hide(vfi); | |
585 | |
586 if (vfi->tip_delay_id != -1) | |
587 { | |
588 g_source_remove(vfi->tip_delay_id); | |
589 vfi->tip_delay_id = -1; | |
590 } | |
591 | |
592 if (!vfi->show_text) | |
593 { | |
594 vfi->tip_delay_id = g_timeout_add(VFICON_TIP_DELAY, tip_schedule_cb, vfi); | |
595 } | |
596 } | |
597 | |
598 static void tip_unschedule(ViewFileIcon *vfi) | |
599 { | |
600 tip_hide(vfi); | |
601 | |
602 if (vfi->tip_delay_id != -1) g_source_remove(vfi->tip_delay_id); | |
603 vfi->tip_delay_id = -1; | |
604 } | |
605 | |
138 | 606 static void tip_update(ViewFileIcon *vfi, IconData *id) |
9 | 607 { |
608 if (vfi->tip_window) | |
609 { | |
610 gint x, y; | |
611 | |
612 gdk_window_get_pointer(NULL, &x, &y, NULL); | |
613 gtk_window_move(GTK_WINDOW(vfi->tip_window), x + 16, y + 16); | |
614 | |
138 | 615 if (id != vfi->tip_id) |
9 | 616 { |
617 GtkWidget *label; | |
618 | |
138 | 619 vfi->tip_id = id; |
620 | |
621 if (!vfi->tip_id) | |
9 | 622 { |
623 tip_hide(vfi); | |
624 tip_schedule(vfi); | |
625 return; | |
626 } | |
627 | |
628 label = g_object_get_data(G_OBJECT(vfi->tip_window), "tip_label"); | |
138 | 629 gtk_label_set_text(GTK_LABEL(label), vfi->tip_id->fd->name); |
9 | 630 } |
631 } | |
632 else | |
633 { | |
634 tip_schedule(vfi); | |
635 } | |
636 } | |
637 | |
638 /* | |
639 *------------------------------------------------------------------- | |
640 * dnd | |
641 *------------------------------------------------------------------- | |
642 */ | |
643 | |
644 static void vficon_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
645 GtkSelectionData *selection_data, guint info, | |
646 guint time, gpointer data) | |
647 { | |
648 ViewFileIcon *vfi = data; | |
649 GList *list = NULL; | |
650 gchar *uri_text = NULL; | |
651 gint total; | |
652 | |
138 | 653 if (!vfi->click_id) return; |
654 | |
655 if (vfi->click_id->selected & SELECTION_SELECTED) | |
9 | 656 { |
657 list = vficon_selection_get_list(vfi); | |
658 } | |
659 else | |
660 { | |
138 | 661 list = g_list_append(NULL, file_data_ref(vfi->click_id->fd)); |
9 | 662 } |
663 | |
664 if (!list) return; | |
138 | 665 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN)); |
666 filelist_free(list); | |
9 | 667 |
495 | 668 DEBUG_1(uri_text); |
9 | 669 |
670 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:
9
diff
changeset
|
671 8, (guchar *)uri_text, total); |
9 | 672 g_free(uri_text); |
673 } | |
674 | |
675 static void vficon_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
676 { | |
677 ViewFileIcon *vfi = data; | |
678 | |
679 tip_unschedule(vfi); | |
680 | |
138 | 681 if (vfi->click_id && vfi->click_id->fd->pixbuf) |
9 | 682 { |
683 gint items; | |
684 | |
138 | 685 if (vfi->click_id->selected & SELECTION_SELECTED) |
9 | 686 items = g_list_length(vfi->selection); |
687 else | |
688 items = 1; | |
689 | |
138 | 690 dnd_set_drag_icon(widget, context, vfi->click_id->fd->pixbuf, items); |
9 | 691 } |
692 } | |
693 | |
694 static void vficon_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
695 { | |
696 ViewFileIcon *vfi = data; | |
697 | |
138 | 698 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); |
9 | 699 |
700 if (context->action == GDK_ACTION_MOVE) | |
701 { | |
702 vficon_refresh(vfi); | |
703 } | |
704 | |
705 tip_unschedule(vfi); | |
706 } | |
707 | |
708 static void vficon_dnd_init(ViewFileIcon *vfi) | |
709 { | |
710 gtk_drag_source_set(vfi->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
711 dnd_file_drag_types, dnd_file_drag_types_count, | |
712 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
713 g_signal_connect(G_OBJECT(vfi->listview), "drag_data_get", | |
714 G_CALLBACK(vficon_dnd_get), vfi); | |
715 g_signal_connect(G_OBJECT(vfi->listview), "drag_begin", | |
716 G_CALLBACK(vficon_dnd_begin), vfi); | |
717 g_signal_connect(G_OBJECT(vfi->listview), "drag_end", | |
718 G_CALLBACK(vficon_dnd_end), vfi); | |
719 } | |
720 | |
721 /* | |
722 *------------------------------------------------------------------- | |
723 * cell updates | |
724 *------------------------------------------------------------------- | |
725 */ | |
726 | |
138 | 727 static void vficon_selection_set(ViewFileIcon *vfi, IconData *id, SelectionType value, GtkTreeIter *iter) |
9 | 728 { |
729 GtkTreeModel *store; | |
730 GList *list; | |
731 | |
138 | 732 if (!id) return; |
733 | |
9 | 734 |
735 if (id->selected == value) return; | |
736 id->selected = value; | |
737 | |
738 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
739 if (iter) | |
740 { | |
741 gtk_tree_model_get(store, iter, FILE_COLUMN_POINTER, &list, -1); | |
742 if (list) gtk_list_store_set(GTK_LIST_STORE(store), iter, FILE_COLUMN_POINTER, list, -1); | |
743 } | |
744 else | |
745 { | |
746 GtkTreeIter row; | |
747 | |
138 | 748 if (vficon_find_iter(vfi, id, &row, NULL)) |
9 | 749 { |
750 gtk_tree_model_get(store, &row, FILE_COLUMN_POINTER, &list, -1); | |
751 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, FILE_COLUMN_POINTER, list, -1); | |
752 } | |
753 } | |
754 } | |
755 | |
138 | 756 static void vficon_selection_add(ViewFileIcon *vfi, IconData *id, SelectionType mask, GtkTreeIter *iter) |
9 | 757 { |
138 | 758 if (!id) return; |
759 | |
760 vficon_selection_set(vfi, id, id->selected | mask, iter); | |
9 | 761 } |
762 | |
138 | 763 static void vficon_selection_remove(ViewFileIcon *vfi, IconData *id, SelectionType mask, GtkTreeIter *iter) |
9 | 764 { |
138 | 765 if (!id) return; |
766 | |
767 vficon_selection_set(vfi, id, id->selected & ~mask, iter); | |
9 | 768 } |
769 | |
770 /* | |
771 *------------------------------------------------------------------- | |
772 * selections | |
773 *------------------------------------------------------------------- | |
774 */ | |
775 | |
776 static void vficon_verify_selections(ViewFileIcon *vfi) | |
777 { | |
778 GList *work; | |
779 | |
780 work = vfi->selection; | |
781 while (work) | |
782 { | |
138 | 783 IconData *id = work->data; |
9 | 784 work = work->next; |
138 | 785 if (vficon_index_by_id(vfi, id) < 0) |
9 | 786 { |
138 | 787 vfi->selection = g_list_remove(vfi->selection, id); |
9 | 788 } |
789 } | |
790 } | |
791 | |
792 void vficon_select_all(ViewFileIcon *vfi) | |
793 { | |
794 GList *work; | |
795 | |
796 g_list_free(vfi->selection); | |
797 vfi->selection = NULL; | |
798 | |
799 work = vfi->list; | |
800 while (work) | |
801 { | |
138 | 802 IconData *id = work->data; |
803 vfi->selection = g_list_append(vfi->selection, id); | |
9 | 804 vficon_selection_add(vfi, work->data, SELECTION_SELECTED, NULL); |
805 work = work->next; | |
806 } | |
807 | |
808 vficon_send_update(vfi); | |
809 } | |
810 | |
811 void vficon_select_none(ViewFileIcon *vfi) | |
812 { | |
813 GList *work; | |
814 | |
815 work = vfi->selection; | |
816 while (work) | |
817 { | |
818 vficon_selection_remove(vfi, work->data, SELECTION_SELECTED, NULL); | |
819 work = work->next; | |
820 } | |
821 | |
822 g_list_free(vfi->selection); | |
823 vfi->selection = NULL; | |
824 | |
825 vficon_send_update(vfi); | |
826 } | |
827 | |
138 | 828 static void vficon_select(ViewFileIcon *vfi, IconData *id) |
9 | 829 { |
138 | 830 vfi->prev_selection = id; |
831 | |
832 if (!id || id->selected & SELECTION_SELECTED) return; | |
833 | |
834 vfi->selection = g_list_append(vfi->selection, id); | |
835 vficon_selection_add(vfi, id, SELECTION_SELECTED, NULL); | |
9 | 836 |
837 vficon_send_update(vfi); | |
838 } | |
839 | |
138 | 840 static void vficon_unselect(ViewFileIcon *vfi, IconData *id) |
9 | 841 { |
138 | 842 vfi->prev_selection = id; |
843 | |
844 if (!id || !(id->selected & SELECTION_SELECTED) ) return; | |
845 | |
846 vfi->selection = g_list_remove(vfi->selection, id); | |
847 vficon_selection_remove(vfi, id, SELECTION_SELECTED, NULL); | |
9 | 848 |
849 vficon_send_update(vfi); | |
850 } | |
851 | |
138 | 852 static void vficon_select_util(ViewFileIcon *vfi, IconData *id, gint select) |
9 | 853 { |
854 if (select) | |
855 { | |
138 | 856 vficon_select(vfi, id); |
9 | 857 } |
858 else | |
859 { | |
138 | 860 vficon_unselect(vfi, id); |
9 | 861 } |
862 } | |
863 | |
138 | 864 static void vficon_select_region_util(ViewFileIcon *vfi, IconData *start, IconData *end, gint select) |
9 | 865 { |
866 gint row1, col1; | |
867 gint row2, col2; | |
868 gint t; | |
869 gint i, j; | |
870 | |
871 if (!vficon_find_position(vfi, start, &row1, &col1) || | |
872 !vficon_find_position(vfi, end, &row2, &col2) ) return; | |
873 | |
874 vfi->prev_selection = end; | |
875 | |
330 | 876 if (!options->collections.rectangular_selection) |
9 | 877 { |
878 GList *work; | |
138 | 879 IconData *id; |
9 | 880 |
881 if (g_list_index(vfi->list, start) > g_list_index(vfi->list, end)) | |
882 { | |
138 | 883 id = start; |
9 | 884 start = end; |
138 | 885 end = id; |
9 | 886 } |
887 | |
888 work = g_list_find(vfi->list, start); | |
889 while (work) | |
890 { | |
138 | 891 id = work->data; |
892 vficon_select_util(vfi, id, select); | |
442 | 893 |
9 | 894 if (work->data != end) |
895 work = work->next; | |
896 else | |
897 work = NULL; | |
898 } | |
899 return; | |
900 } | |
901 | |
902 if (row2 < row1) | |
903 { | |
904 t = row1; | |
905 row1 = row2; | |
906 row2 = t; | |
907 } | |
908 if (col2 < col1) | |
909 { | |
910 t = col1; | |
911 col1 = col2; | |
912 col2 = t; | |
913 } | |
914 | |
495 | 915 DEBUG_1("table: %d x %d to %d x %d\n", row1, col1, row2, col2); |
9 | 916 |
917 for (i = row1; i <= row2; i++) | |
918 { | |
919 for (j = col1; j <= col2; j++) | |
920 { | |
138 | 921 IconData *id = vficon_find_data(vfi, i, j, NULL); |
922 if (id) vficon_select_util(vfi, id, select); | |
9 | 923 } |
924 } | |
925 } | |
926 | |
927 gint vficon_index_is_selected(ViewFileIcon *vfi, gint row) | |
928 { | |
138 | 929 IconData *id = g_list_nth_data(vfi->list, row); |
930 | |
931 if (!id) return FALSE; | |
932 | |
933 return (id->selected & SELECTION_SELECTED); | |
9 | 934 } |
935 | |
936 gint vficon_selection_count(ViewFileIcon *vfi, gint64 *bytes) | |
937 { | |
938 if (bytes) | |
939 { | |
940 gint64 b = 0; | |
941 GList *work; | |
942 | |
943 work = vfi->selection; | |
944 while (work) | |
945 { | |
138 | 946 IconData *id = work->data; |
947 FileData *fd = id->fd; | |
442 | 948 g_assert(fd->magick == 0x12345678); |
9 | 949 b += fd->size; |
950 | |
951 work = work->next; | |
952 } | |
953 | |
954 *bytes = b; | |
955 } | |
956 | |
957 return g_list_length(vfi->selection); | |
958 } | |
959 | |
960 GList *vficon_selection_get_list(ViewFileIcon *vfi) | |
961 { | |
962 GList *list = NULL; | |
963 GList *work; | |
964 | |
965 work = vfi->selection; | |
966 while (work) | |
967 { | |
138 | 968 IconData *id = work->data; |
969 FileData *fd = id->fd; | |
442 | 970 g_assert(fd->magick == 0x12345678); |
138 | 971 |
972 list = g_list_prepend(list, file_data_ref(fd)); | |
9 | 973 |
974 work = work->next; | |
975 } | |
976 | |
977 list = g_list_reverse(list); | |
978 | |
979 return list; | |
980 } | |
981 | |
982 GList *vficon_selection_get_list_by_index(ViewFileIcon *vfi) | |
983 { | |
984 GList *list = NULL; | |
985 GList *work; | |
986 | |
442 | 987 work = vfi->selection; |
9 | 988 while (work) |
989 { | |
990 list = g_list_prepend(list, GINT_TO_POINTER(g_list_index(vfi->list, work->data))); | |
991 work = work->next; | |
992 } | |
993 | |
994 return g_list_reverse(list); | |
995 } | |
996 | |
138 | 997 static void vficon_select_by_id(ViewFileIcon *vfi, IconData *id) |
998 { | |
999 if (!id) return; | |
1000 | |
1001 if (!(id->selected & SELECTION_SELECTED)) | |
1002 { | |
1003 vficon_select_none(vfi); | |
1004 vficon_select(vfi, id); | |
1005 } | |
1006 | |
1007 vficon_set_focus(vfi, id); | |
1008 } | |
1009 | |
1010 | |
9 | 1011 void vficon_select_by_path(ViewFileIcon *vfi, const gchar *path) |
1012 { | |
138 | 1013 IconData *id = NULL; |
9 | 1014 GList *work; |
1015 | |
1016 if (!path) return; | |
1017 | |
1018 work = vfi->list; | |
138 | 1019 while (work && !id) |
9 | 1020 { |
138 | 1021 IconData *chk = work->data; |
9 | 1022 work = work->next; |
138 | 1023 if (strcmp(chk->fd->path, path) == 0) id = chk; |
9 | 1024 } |
138 | 1025 vficon_select_by_id(vfi, id); |
1026 } | |
1027 | |
1028 void vficon_select_by_fd(ViewFileIcon *vfi, FileData *fd) | |
1029 { | |
1030 IconData *id = NULL; | |
1031 GList *work; | |
9 | 1032 |
1033 if (!fd) return; | |
138 | 1034 work = vfi->list; |
1035 while (work && !id) | |
9 | 1036 { |
138 | 1037 IconData *chk = work->data; |
1038 work = work->next; | |
1039 if (chk->fd == fd) id = chk; | |
9 | 1040 } |
138 | 1041 vficon_select_by_id(vfi, id); |
9 | 1042 } |
1043 | |
165 | 1044 void vficon_mark_to_selection(ViewFileIcon *vfi, gint mark, MarkToSelectionMode mode) |
1045 { | |
1046 GList *work; | |
1047 | |
1048 work = vfi->list; | |
1049 while (work) | |
1050 { | |
1051 IconData *id = work->data; | |
1052 FileData *fd = id->fd; | |
1053 gboolean mark_val, selected; | |
1054 | |
442 | 1055 g_assert(fd->magick == 0x12345678); |
165 | 1056 |
1057 mark_val = fd->marks[mark]; | |
1058 selected = (id->selected & SELECTION_SELECTED); | |
442 | 1059 |
1060 switch (mode) | |
165 | 1061 { |
1062 case MTS_MODE_SET: selected = mark_val; | |
1063 break; | |
1064 case MTS_MODE_OR: selected = mark_val | selected; | |
1065 break; | |
1066 case MTS_MODE_AND: selected = mark_val & selected; | |
1067 break; | |
1068 case MTS_MODE_MINUS: selected = !mark_val & selected; | |
1069 break; | |
1070 } | |
442 | 1071 |
165 | 1072 vficon_select_util(vfi, id, selected); |
1073 | |
1074 work = work->next; | |
1075 } | |
1076 } | |
1077 | |
1078 void vficon_selection_to_mark(ViewFileIcon *vfi, gint mark, SelectionToMarkMode mode) | |
1079 { | |
1080 GList *slist; | |
1081 GList *work; | |
1082 | |
1083 g_assert(mark >= 0 && mark < FILEDATA_MARKS_SIZE); | |
1084 | |
1085 slist = vficon_selection_get_list(vfi); | |
1086 work = slist; | |
1087 while (work) | |
1088 { | |
1089 FileData *fd = work->data; | |
442 | 1090 |
165 | 1091 switch (mode) |
1092 { | |
1093 case STM_MODE_SET: fd->marks[mark] = 1; | |
1094 break; | |
1095 case STM_MODE_RESET: fd->marks[mark] = 0; | |
1096 break; | |
1097 case STM_MODE_TOGGLE: fd->marks[mark] = !fd->marks[mark]; | |
1098 break; | |
1099 } | |
442 | 1100 |
165 | 1101 work = work->next; |
1102 } | |
1103 filelist_free(slist); | |
1104 } | |
138 | 1105 |
1106 | |
9 | 1107 /* |
1108 *------------------------------------------------------------------- | |
1109 * focus | |
1110 *------------------------------------------------------------------- | |
1111 */ | |
1112 | |
1113 static void vficon_move_focus(ViewFileIcon *vfi, gint row, gint col, gint relative) | |
1114 { | |
1115 gint new_row; | |
1116 gint new_col; | |
1117 | |
1118 if (relative) | |
1119 { | |
1120 new_row = vfi->focus_row; | |
1121 new_col = vfi->focus_column; | |
1122 | |
1123 new_row += row; | |
1124 if (new_row < 0) new_row = 0; | |
1125 if (new_row >= vfi->rows) new_row = vfi->rows - 1; | |
1126 | |
1127 while(col != 0) | |
1128 { | |
1129 if (col < 0) | |
1130 { | |
1131 new_col--; | |
1132 col++; | |
1133 } | |
1134 else | |
1135 { | |
1136 new_col++; | |
1137 col--; | |
1138 } | |
1139 | |
1140 if (new_col < 0) | |
1141 { | |
1142 if (new_row > 0) | |
1143 { | |
1144 new_row--; | |
1145 new_col = vfi->columns - 1; | |
1146 } | |
1147 else | |
1148 { | |
1149 new_col = 0; | |
1150 } | |
1151 } | |
1152 if (new_col >= vfi->columns) | |
1153 { | |
1154 if (new_row < vfi->rows - 1) | |
1155 { | |
1156 new_row++; | |
1157 new_col = 0; | |
1158 } | |
1159 else | |
1160 { | |
1161 new_col = vfi->columns - 1; | |
1162 } | |
1163 } | |
1164 } | |
1165 } | |
1166 else | |
1167 { | |
1168 new_row = row; | |
1169 new_col = col; | |
1170 | |
1171 if (new_row >= vfi->rows) | |
1172 { | |
1173 if (vfi->rows > 0) | |
1174 new_row = vfi->rows - 1; | |
1175 else | |
1176 new_row = 0; | |
1177 new_col = vfi->columns - 1; | |
1178 } | |
1179 if (new_col >= vfi->columns) new_col = vfi->columns - 1; | |
1180 } | |
1181 | |
1182 if (new_row == vfi->rows - 1) | |
1183 { | |
1184 gint l; | |
1185 | |
1186 /* if we moved beyond the last image, go to the last image */ | |
1187 | |
1188 l = g_list_length(vfi->list); | |
1189 if (vfi->rows > 1) l -= (vfi->rows - 1) * vfi->columns; | |
1190 if (new_col >= l) new_col = l - 1; | |
1191 } | |
1192 | |
1193 vficon_set_focus(vfi, vficon_find_data(vfi, new_row, new_col, NULL)); | |
1194 } | |
1195 | |
138 | 1196 static void vficon_set_focus(ViewFileIcon *vfi, IconData *id) |
9 | 1197 { |
1198 GtkTreeIter iter; | |
1199 gint row, col; | |
1200 | |
138 | 1201 if (g_list_find(vfi->list, vfi->focus_id)) |
9 | 1202 { |
138 | 1203 if (id == vfi->focus_id) |
9 | 1204 { |
1205 /* ensure focus row col are correct */ | |
138 | 1206 vficon_find_position(vfi, vfi->focus_id, &vfi->focus_row, &vfi->focus_column); |
9 | 1207 return; |
1208 } | |
138 | 1209 vficon_selection_remove(vfi, vfi->focus_id, SELECTION_FOCUS, NULL); |
9 | 1210 } |
1211 | |
138 | 1212 if (!vficon_find_position(vfi, id, &row, &col)) |
9 | 1213 { |
138 | 1214 vfi->focus_id = NULL; |
9 | 1215 vfi->focus_row = -1; |
1216 vfi->focus_column = -1; | |
1217 return; | |
1218 } | |
1219 | |
138 | 1220 vfi->focus_id = id; |
9 | 1221 vfi->focus_row = row; |
1222 vfi->focus_column = col; | |
138 | 1223 vficon_selection_add(vfi, vfi->focus_id, SELECTION_FOCUS, NULL); |
1224 | |
1225 if (vficon_find_iter(vfi, vfi->focus_id, &iter, NULL)) | |
9 | 1226 { |
1227 GtkTreePath *tpath; | |
1228 GtkTreeViewColumn *column; | |
1229 GtkTreeModel *store; | |
1230 | |
1231 tree_view_row_make_visible(GTK_TREE_VIEW(vfi->listview), &iter, FALSE); | |
1232 | |
1233 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
1234 tpath = gtk_tree_model_get_path(store, &iter); | |
1235 /* focus is set to an extra column with 0 width to hide focus, we draw it ourself */ | |
1236 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vfi->listview), VFICON_MAX_COLUMNS); | |
1237 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vfi->listview), tpath, column, FALSE); | |
1238 gtk_tree_path_free(tpath); | |
1239 } | |
1240 } | |
1241 | |
1242 static void vficon_update_focus(ViewFileIcon *vfi) | |
1243 { | |
1244 gint new_row = 0; | |
1245 gint new_col = 0; | |
1246 | |
138 | 1247 if (vfi->focus_id && vficon_find_position(vfi, vfi->focus_id, &new_row, &new_col)) |
9 | 1248 { |
1249 /* first find the old focus, if it exists and is valid */ | |
1250 } | |
1251 else | |
1252 { | |
1253 /* (try to) stay where we were */ | |
1254 new_row = vfi->focus_row; | |
1255 new_col = vfi->focus_column; | |
1256 } | |
1257 | |
1258 vficon_move_focus(vfi, new_row, new_col, FALSE); | |
1259 } | |
1260 | |
1261 /* used to figure the page up/down distances */ | |
1262 static gint page_height(ViewFileIcon *vfi) | |
1263 { | |
1264 GtkAdjustment *adj; | |
1265 gint page_size; | |
1266 gint row_height; | |
1267 gint ret; | |
1268 | |
1269 adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vfi->listview)); | |
1270 page_size = (gint)adj->page_increment; | |
1271 | |
333 | 1272 row_height = options->thumbnails.max_height + THUMB_BORDER_PADDING * 2; |
1273 if (vfi->show_text) row_height += options->thumbnails.max_height / 3; | |
9 | 1274 |
1275 ret = page_size / row_height; | |
1276 if (ret < 1) ret = 1; | |
1277 | |
1278 return ret; | |
1279 } | |
1280 | |
1281 /* | |
1282 *------------------------------------------------------------------- | |
1283 * keyboard | |
1284 *------------------------------------------------------------------- | |
1285 */ | |
1286 | |
1287 static void vfi_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
1288 { | |
1289 ViewFileIcon *vfi = data; | |
1290 GtkTreeModel *store; | |
1291 GtkTreeIter iter; | |
1292 gint column; | |
1293 GtkTreePath *tpath; | |
1294 gint cw, ch; | |
1295 | |
138 | 1296 if (!vficon_find_iter(vfi, vfi->click_id, &iter, &column)) return; |
9 | 1297 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); |
1298 tpath = gtk_tree_model_get_path(store, &iter); | |
1299 tree_view_get_cell_clamped(GTK_TREE_VIEW(vfi->listview), tpath, column, FALSE, x, y, &cw, &ch); | |
1300 gtk_tree_path_free(tpath); | |
1301 *y += ch; | |
1302 popup_menu_position_clamp(menu, x, y, 0); | |
1303 } | |
1304 | |
1305 static gint vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
1306 { | |
1307 ViewFileIcon *vfi = data; | |
1308 gint focus_row = 0; | |
1309 gint focus_col = 0; | |
138 | 1310 IconData *id; |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1311 gint stop_signal; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1312 |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1313 stop_signal = TRUE; |
9 | 1314 switch (event->keyval) |
1315 { | |
1316 case GDK_Left: case GDK_KP_Left: | |
1317 focus_col = -1; | |
1318 break; | |
1319 case GDK_Right: case GDK_KP_Right: | |
1320 focus_col = 1; | |
1321 break; | |
1322 case GDK_Up: case GDK_KP_Up: | |
1323 focus_row = -1; | |
1324 break; | |
1325 case GDK_Down: case GDK_KP_Down: | |
1326 focus_row = 1; | |
1327 break; | |
1328 case GDK_Page_Up: case GDK_KP_Page_Up: | |
1329 focus_row = -page_height(vfi); | |
1330 break; | |
1331 case GDK_Page_Down: case GDK_KP_Page_Down: | |
1332 focus_row = page_height(vfi); | |
1333 break; | |
1334 case GDK_Home: case GDK_KP_Home: | |
1335 focus_row = -vfi->focus_row; | |
1336 focus_col = -vfi->focus_column; | |
1337 break; | |
1338 case GDK_End: case GDK_KP_End: | |
1339 focus_row = vfi->rows - 1 - vfi->focus_row; | |
1340 focus_col = vfi->columns - 1 - vfi->focus_column; | |
1341 break; | |
1342 case GDK_space: | |
138 | 1343 id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); |
1344 if (id) | |
9 | 1345 { |
138 | 1346 vfi->click_id = id; |
9 | 1347 if (event->state & GDK_CONTROL_MASK) |
1348 { | |
1349 gint selected; | |
1350 | |
138 | 1351 selected = id->selected & SELECTION_SELECTED; |
9 | 1352 if (selected) |
1353 { | |
138 | 1354 vficon_unselect(vfi, id); |
9 | 1355 } |
1356 else | |
1357 { | |
138 | 1358 vficon_select(vfi, id); |
1359 vficon_send_layout_select(vfi, id); | |
9 | 1360 } |
1361 } | |
1362 else | |
1363 { | |
1364 vficon_select_none(vfi); | |
138 | 1365 vficon_select(vfi, id); |
1366 vficon_send_layout_select(vfi, id); | |
9 | 1367 } |
1368 } | |
1369 break; | |
1370 case GDK_Menu: | |
138 | 1371 id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); |
1372 vfi->click_id = id; | |
1373 | |
1374 vficon_selection_add(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); | |
9 | 1375 tip_unschedule(vfi); |
1376 | |
138 | 1377 vfi->popup = vficon_pop_menu(vfi, (id != NULL)); |
9 | 1378 gtk_menu_popup(GTK_MENU(vfi->popup), NULL, NULL, vfi_menu_position_cb, vfi, 0, GDK_CURRENT_TIME); |
1379 break; | |
1380 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1381 stop_signal = FALSE; |
9 | 1382 break; |
1383 } | |
1384 | |
1385 if (focus_row != 0 || focus_col != 0) | |
1386 { | |
138 | 1387 IconData *new_id; |
1388 IconData *old_id; | |
1389 | |
1390 old_id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); | |
9 | 1391 vficon_move_focus(vfi, focus_row, focus_col, TRUE); |
138 | 1392 new_id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); |
1393 | |
1394 if (new_id != old_id) | |
9 | 1395 { |
1396 if (event->state & GDK_SHIFT_MASK) | |
1397 { | |
330 | 1398 if (!options->collections.rectangular_selection) |
9 | 1399 { |
138 | 1400 vficon_select_region_util(vfi, old_id, new_id, FALSE); |
9 | 1401 } |
1402 else | |
1403 { | |
138 | 1404 vficon_select_region_util(vfi, vfi->click_id, old_id, FALSE); |
9 | 1405 } |
138 | 1406 vficon_select_region_util(vfi, vfi->click_id, new_id, TRUE); |
1407 vficon_send_layout_select(vfi, new_id); | |
9 | 1408 } |
1409 else if (event->state & GDK_CONTROL_MASK) | |
1410 { | |
138 | 1411 vfi->click_id = new_id; |
9 | 1412 } |
1413 else | |
1414 { | |
138 | 1415 vfi->click_id = new_id; |
9 | 1416 vficon_select_none(vfi); |
138 | 1417 vficon_select(vfi, new_id); |
1418 vficon_send_layout_select(vfi, new_id); | |
9 | 1419 } |
1420 } | |
1421 } | |
1422 | |
1423 if (stop_signal) | |
1424 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1425 #if 0 |
9 | 1426 g_signal_stop_emission_by_name(GTK_OBJECT(widget), "key_press_event"); |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1427 #endif |
9 | 1428 tip_unschedule(vfi); |
1429 } | |
1430 | |
1431 return stop_signal; | |
1432 } | |
1433 | |
1434 /* | |
1435 *------------------------------------------------------------------- | |
1436 * mouse | |
1437 *------------------------------------------------------------------- | |
1438 */ | |
1439 | |
1440 static gint vficon_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1441 { | |
1442 ViewFileIcon *vfi = data; | |
138 | 1443 IconData *id; |
1444 | |
1445 id = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, NULL); | |
1446 tip_update(vfi, id); | |
9 | 1447 |
1448 return FALSE; | |
1449 } | |
1450 | |
1451 static gint vficon_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1452 { | |
1453 ViewFileIcon *vfi = data; | |
1454 GtkTreeIter iter; | |
138 | 1455 IconData *id; |
9 | 1456 |
1457 tip_unschedule(vfi); | |
442 | 1458 |
138 | 1459 id = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, &iter); |
1460 | |
1461 vfi->click_id = id; | |
1462 vficon_selection_add(vfi, vfi->click_id, SELECTION_PRELIGHT, &iter); | |
9 | 1463 |
1464 switch (bevent->button) | |
1465 { | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1466 case MOUSE_BUTTON_LEFT: |
9 | 1467 if (!GTK_WIDGET_HAS_FOCUS(vfi->listview)) |
1468 { | |
1469 gtk_widget_grab_focus(vfi->listview); | |
1470 } | |
1471 #if 0 | |
1472 if (bevent->type == GDK_2BUTTON_PRESS && | |
1473 vfi->layout) | |
1474 { | |
138 | 1475 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, &iter); |
9 | 1476 layout_image_full_screen_start(vfi->layout); |
1477 } | |
1478 #endif | |
1479 break; | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1480 case MOUSE_BUTTON_RIGHT: |
138 | 1481 vfi->popup = vficon_pop_menu(vfi, (id != NULL)); |
9 | 1482 gtk_menu_popup(GTK_MENU(vfi->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time); |
1483 break; | |
1484 default: | |
1485 break; | |
1486 } | |
1487 | |
1488 return TRUE; | |
1489 } | |
1490 | |
1491 static gint vficon_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1492 { | |
1493 ViewFileIcon *vfi = data; | |
1494 GtkTreeIter iter; | |
138 | 1495 IconData *id = NULL; |
9 | 1496 gint was_selected = FALSE; |
1497 | |
1498 tip_schedule(vfi); | |
1499 | |
1500 if ((gint)bevent->x != 0 || (gint) bevent->y != 0) | |
1501 { | |
138 | 1502 id = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, &iter); |
9 | 1503 } |
1504 | |
138 | 1505 if (vfi->click_id) |
9 | 1506 { |
138 | 1507 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); |
9 | 1508 } |
1509 | |
138 | 1510 if (id) was_selected = (id->selected & SELECTION_SELECTED); |
9 | 1511 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1512 if (bevent->button == MOUSE_BUTTON_LEFT && |
138 | 1513 id && vfi->click_id == id) |
9 | 1514 { |
138 | 1515 vficon_set_focus(vfi, id); |
442 | 1516 |
9 | 1517 if (bevent->state & GDK_CONTROL_MASK) |
1518 { | |
1519 gint select; | |
1520 | |
138 | 1521 select = !(id->selected & SELECTION_SELECTED); |
9 | 1522 if ((bevent->state & GDK_SHIFT_MASK) && vfi->prev_selection) |
1523 { | |
138 | 1524 vficon_select_region_util(vfi, vfi->prev_selection, id, select); |
9 | 1525 } |
1526 else | |
1527 { | |
138 | 1528 vficon_select_util(vfi, id, select); |
9 | 1529 } |
1530 } | |
1531 else | |
1532 { | |
1533 vficon_select_none(vfi); | |
1534 | |
1535 if ((bevent->state & GDK_SHIFT_MASK) && | |
1536 vfi->prev_selection) | |
1537 { | |
138 | 1538 vficon_select_region_util(vfi, vfi->prev_selection, id, TRUE); |
9 | 1539 } |
1540 else | |
1541 { | |
138 | 1542 vficon_select_util(vfi, id, TRUE); |
9 | 1543 was_selected = FALSE; |
1544 } | |
1545 } | |
1546 } | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1547 else if (bevent->button == MOUSE_BUTTON_MIDDLE && |
138 | 1548 id && vfi->click_id == id) |
9 | 1549 { |
138 | 1550 vficon_select_util(vfi, id, !(id->selected & SELECTION_SELECTED)); |
9 | 1551 } |
1552 | |
138 | 1553 if (id && !was_selected && |
1554 (id->selected & SELECTION_SELECTED)) | |
9 | 1555 { |
138 | 1556 vficon_send_layout_select(vfi, id); |
9 | 1557 } |
1558 | |
1559 return TRUE; | |
1560 } | |
1561 | |
1562 static gint vficon_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) | |
1563 { | |
1564 ViewFileIcon *vfi = data; | |
1565 | |
1566 tip_unschedule(vfi); | |
1567 return FALSE; | |
1568 } | |
1569 | |
1570 /* | |
1571 *------------------------------------------------------------------- | |
1572 * population | |
1573 *------------------------------------------------------------------- | |
1574 */ | |
1575 | |
1576 static gboolean vficon_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
1577 { | |
1578 GList *list; | |
1579 | |
1580 gtk_tree_model_get(store, iter, FILE_COLUMN_POINTER, &list, -1); | |
1581 g_list_free(list); | |
1582 | |
1583 return FALSE; | |
1584 } | |
1585 | |
1586 static void vficon_clear_store(ViewFileIcon *vfi) | |
1587 { | |
1588 GtkTreeModel *store; | |
1589 | |
1590 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
1591 gtk_tree_model_foreach(store, vficon_destroy_node_cb, NULL); | |
1592 | |
1593 gtk_list_store_clear(GTK_LIST_STORE(store)); | |
1594 } | |
1595 | |
1596 static void vficon_set_thumb(ViewFileIcon *vfi, FileData *fd, GdkPixbuf *pb) | |
1597 { | |
1598 GtkTreeModel *store; | |
1599 GtkTreeIter iter; | |
1600 GList *list; | |
1601 | |
138 | 1602 if (!vficon_find_iter(vfi, vficon_icon_data(vfi, fd), &iter, NULL)) return; |
9 | 1603 |
1604 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
1605 | |
1606 if (pb) g_object_ref(pb); | |
1607 if (fd->pixbuf) g_object_unref(fd->pixbuf); | |
1608 fd->pixbuf = pb; | |
1609 | |
1610 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
1611 gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1); | |
1612 } | |
1613 | |
1614 static GList *vficon_add_row(ViewFileIcon *vfi, GtkTreeIter *iter) | |
1615 { | |
1616 GtkListStore *store; | |
1617 GList *list = NULL; | |
1618 gint i; | |
1619 | |
1620 for (i = 0; i < vfi->columns; i++) list = g_list_prepend(list, NULL); | |
1621 | |
1622 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview))); | |
1623 gtk_list_store_append(store, iter); | |
1624 gtk_list_store_set(store, iter, FILE_COLUMN_POINTER, list, -1); | |
1625 | |
1626 return list; | |
1627 } | |
1628 | |
1629 static void vficon_populate(ViewFileIcon *vfi, gint resize, gint keep_position) | |
1630 { | |
1631 GtkTreeModel *store; | |
1632 GtkTreePath *tpath; | |
1633 gint row; | |
1634 GList *work; | |
138 | 1635 IconData *visible_id = NULL; |
9 | 1636 |
1637 vficon_verify_selections(vfi); | |
1638 | |
1639 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
1640 | |
1641 if (keep_position && GTK_WIDGET_REALIZED(vfi->listview) && | |
1642 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1643 { | |
1644 GtkTreeIter iter; | |
1645 GList *list; | |
1646 | |
1647 gtk_tree_model_get_iter(store, &iter, tpath); | |
1648 gtk_tree_path_free(tpath); | |
1649 | |
1650 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
138 | 1651 if (list) visible_id = list->data; |
9 | 1652 } |
1653 | |
1654 vficon_clear_store(vfi); | |
1655 | |
1656 if (resize) | |
1657 { | |
1658 gint i; | |
1659 gint thumb_width; | |
1660 | |
1661 thumb_width = vficon_get_icon_width(vfi); | |
1662 | |
1663 for (i = 0; i < VFICON_MAX_COLUMNS; i++) | |
1664 { | |
1665 GtkTreeViewColumn *column; | |
1666 GtkCellRenderer *cell; | |
1667 GList *list; | |
1668 | |
1669 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vfi->listview), i); | |
1670 gtk_tree_view_column_set_visible(column, (i < vfi->columns)); | |
1671 gtk_tree_view_column_set_fixed_width(column, thumb_width + (THUMB_BORDER_PADDING * 6)); | |
1672 | |
1673 list = gtk_tree_view_column_get_cell_renderers(column); | |
1674 cell = (list) ? list->data : NULL; | |
1675 g_list_free(list); | |
1676 | |
1677 if (cell && GQV_IS_CELL_RENDERER_ICON(cell)) | |
1678 { | |
1679 g_object_set(G_OBJECT(cell), "fixed_width", thumb_width, | |
333 | 1680 "fixed_height", options->thumbnails.max_height, |
9 | 1681 "show_text", vfi->show_text, NULL); |
1682 } | |
1683 } | |
1684 if (GTK_WIDGET_REALIZED(vfi->listview)) gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vfi->listview)); | |
1685 } | |
1686 | |
1687 row = -1; | |
1688 work = vfi->list; | |
1689 while (work) | |
1690 { | |
1691 GList *list; | |
1692 GtkTreeIter iter; | |
1693 | |
1694 row++; | |
1695 | |
1696 list = vficon_add_row(vfi, &iter); | |
1697 while (work && list) | |
1698 { | |
138 | 1699 IconData *id; |
1700 | |
1701 id = work->data; | |
1702 id->row = row; | |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
1703 |
9 | 1704 list->data = work->data; |
1705 list = list->next; | |
1706 work = work->next; | |
1707 } | |
1708 } | |
1709 | |
138 | 1710 if (visible_id && |
9 | 1711 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), 0, 0, &tpath, NULL, NULL, NULL)) |
1712 { | |
1713 GtkTreeIter iter; | |
1714 GList *list; | |
1715 | |
1716 gtk_tree_model_get_iter(store, &iter, tpath); | |
1717 gtk_tree_path_free(tpath); | |
1718 | |
1719 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
138 | 1720 if (g_list_find(list, visible_id) == NULL && |
1721 vficon_find_iter(vfi, visible_id, &iter, NULL)) | |
9 | 1722 { |
1723 tree_view_row_make_visible(GTK_TREE_VIEW(vfi->listview), &iter, FALSE); | |
1724 } | |
1725 } | |
1726 | |
1727 vfi->rows = row + 1; | |
1728 | |
1729 vficon_send_update(vfi); | |
1730 vficon_thumb_update(vfi); | |
1731 } | |
1732 | |
1733 static void vficon_populate_at_new_size(ViewFileIcon *vfi, gint w, gint h, gint force) | |
1734 { | |
1735 gint new_cols; | |
1736 gint thumb_width; | |
1737 | |
1738 thumb_width = vficon_get_icon_width(vfi); | |
1739 | |
1740 new_cols = w / (thumb_width + (THUMB_BORDER_PADDING * 6)); | |
1741 if (new_cols < 1) new_cols = 1; | |
1742 | |
1743 if (!force && new_cols == vfi->columns) return; | |
1744 | |
1745 vfi->columns = new_cols; | |
1746 | |
1747 vficon_populate(vfi, TRUE, TRUE); | |
1748 | |
495 | 1749 DEBUG_1("col tab pop cols=%d rows=%d\n", vfi->columns, vfi->rows); |
9 | 1750 } |
1751 | |
1752 static void vficon_sync(ViewFileIcon *vfi) | |
1753 { | |
1754 GtkTreeModel *store; | |
1755 GtkTreeIter iter; | |
1756 GList *work; | |
1757 gint r, c; | |
1758 | |
1759 if (vfi->rows == 0) return; | |
1760 | |
1761 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
1762 | |
1763 r = -1; | |
1764 c = 0; | |
1765 | |
1766 work = vfi->list; | |
1767 while (work) | |
1768 { | |
1769 GList *list; | |
1770 r++; | |
1771 c = 0; | |
1772 if (gtk_tree_model_iter_nth_child(store, &iter, NULL, r)) | |
1773 { | |
1774 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
1775 gtk_list_store_set(GTK_LIST_STORE(store), &iter, FILE_COLUMN_POINTER, list, -1); | |
1776 } | |
1777 else | |
1778 { | |
1779 list = vficon_add_row(vfi, &iter); | |
1780 } | |
442 | 1781 |
9 | 1782 while (list) |
1783 { | |
138 | 1784 IconData *id; |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
1785 |
9 | 1786 if (work) |
1787 { | |
138 | 1788 id = work->data; |
9 | 1789 work = work->next; |
1790 c++; | |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
1791 |
138 | 1792 id->row = r; |
9 | 1793 } |
1794 else | |
1795 { | |
138 | 1796 id = NULL; |
9 | 1797 } |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
1798 |
138 | 1799 list->data = id; |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
1800 list = list->next; |
9 | 1801 } |
1802 } | |
1803 | |
1804 r++; | |
1805 while (gtk_tree_model_iter_nth_child(store, &iter, NULL, r)) | |
1806 { | |
1807 GList *list; | |
1808 | |
1809 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
1810 gtk_list_store_remove(GTK_LIST_STORE(store), &iter); | |
1811 g_list_free(list); | |
1812 } | |
1813 | |
1814 vfi->rows = r; | |
1815 | |
1816 vficon_update_focus(vfi); | |
1817 } | |
1818 | |
1819 static gint vficon_sync_idle_cb(gpointer data) | |
1820 { | |
1821 ViewFileIcon *vfi = data; | |
1822 | |
1823 if (vfi->sync_idle_id == -1) return FALSE; | |
1824 vfi->sync_idle_id = -1; | |
1825 | |
1826 vficon_sync(vfi); | |
1827 return FALSE; | |
1828 } | |
1829 | |
1830 static void vficon_sync_idle(ViewFileIcon *vfi) | |
1831 { | |
1832 if (vfi->sync_idle_id == -1) | |
1833 { | |
1834 /* high priority, the view needs to be resynced before a redraw | |
1835 * may contain invalid pointers at this time | |
1836 */ | |
1837 vfi->sync_idle_id = g_idle_add_full(G_PRIORITY_HIGH, vficon_sync_idle_cb, vfi, NULL); | |
1838 } | |
1839 } | |
1840 | |
1841 static void vficon_sized_cb(GtkWidget *widget, GtkAllocation *allocation, gpointer data) | |
1842 { | |
1843 ViewFileIcon *vfi = data; | |
1844 | |
1845 vficon_populate_at_new_size(vfi, allocation->width, allocation->height, FALSE); | |
1846 } | |
1847 | |
1848 /* | |
1849 *----------------------------------------------------------------------------- | |
1850 * misc | |
1851 *----------------------------------------------------------------------------- | |
1852 */ | |
1853 | |
1854 void vficon_sort_set(ViewFileIcon *vfi, SortType type, gint ascend) | |
1855 { | |
1856 if (vfi->sort_method == type && vfi->sort_ascend == ascend) return; | |
1857 | |
1858 vfi->sort_method = type; | |
1859 vfi->sort_ascend = ascend; | |
1860 | |
1861 if (!vfi->list) return; | |
1862 | |
138 | 1863 vfi->list = iconlist_sort(vfi->list, vfi->sort_method, vfi->sort_ascend); |
9 | 1864 vficon_sync(vfi); |
1865 } | |
1866 | |
1867 /* | |
1868 *----------------------------------------------------------------------------- | |
1869 * thumb updates | |
1870 *----------------------------------------------------------------------------- | |
1871 */ | |
1872 | |
1873 static gint vficon_thumb_next(ViewFileIcon *vfi); | |
1874 | |
1875 static void vficon_thumb_status(ViewFileIcon *vfi, gdouble val, const gchar *text) | |
1876 { | |
1877 if (vfi->func_thumb_status) | |
1878 { | |
1879 vfi->func_thumb_status(vfi, val, text, vfi->data_thumb_status); | |
1880 } | |
1881 } | |
1882 | |
1883 static void vficon_thumb_cleanup(ViewFileIcon *vfi) | |
1884 { | |
1885 vficon_thumb_status(vfi, 0.0, NULL); | |
1886 | |
1887 g_list_free(vfi->thumbs_list); | |
1888 vfi->thumbs_list = NULL; | |
1889 vfi->thumbs_count = 0; | |
1890 vfi->thumbs_running = FALSE; | |
1891 | |
1892 thumb_loader_free(vfi->thumbs_loader); | |
1893 vfi->thumbs_loader = NULL; | |
1894 | |
1895 vfi->thumbs_fd = NULL; | |
1896 } | |
1897 | |
1898 static void vficon_thumb_stop(ViewFileIcon *vfi) | |
1899 { | |
1900 if (vfi->thumbs_running) vficon_thumb_cleanup(vfi); | |
1901 } | |
1902 | |
1903 static void vficon_thumb_do(ViewFileIcon *vfi, ThumbLoader *tl, FileData *fd) | |
1904 { | |
1905 GdkPixbuf *pixbuf; | |
1906 | |
1907 if (!fd) return; | |
1908 | |
1909 pixbuf = thumb_loader_get_pixbuf(tl, TRUE); | |
1910 vficon_set_thumb(vfi, fd, pixbuf); | |
1911 g_object_unref(pixbuf); | |
1912 | |
1913 vficon_thumb_status(vfi, (gdouble)(vfi->thumbs_count) / g_list_length(vfi->list), _("Loading thumbs...")); | |
1914 } | |
1915 | |
1916 static void vficon_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
1917 { | |
1918 ViewFileIcon *vfi = data; | |
1919 | |
1920 if (vfi->thumbs_fd && vfi->thumbs_loader == tl) | |
1921 { | |
1922 vficon_thumb_do(vfi, tl, vfi->thumbs_fd); | |
1923 } | |
1924 | |
1925 while (vficon_thumb_next(vfi)); | |
1926 } | |
1927 | |
1928 static void vficon_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
1929 { | |
1930 ViewFileIcon *vfi = data; | |
1931 | |
1932 if (vfi->thumbs_fd && vfi->thumbs_loader == tl) | |
1933 { | |
1934 vficon_thumb_do(vfi, tl, vfi->thumbs_fd); | |
1935 } | |
1936 | |
1937 while (vficon_thumb_next(vfi)); | |
1938 } | |
1939 | |
1940 static gint vficon_thumb_next(ViewFileIcon *vfi) | |
1941 { | |
1942 GtkTreePath *tpath; | |
1943 FileData *fd = NULL; | |
1944 | |
1945 if (!GTK_WIDGET_REALIZED(vfi->listview)) | |
1946 { | |
1947 vficon_thumb_status(vfi, 0.0, NULL); | |
1948 return FALSE; | |
1949 } | |
1950 | |
1951 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), 0, 0, &tpath, NULL, NULL, NULL)) | |
1952 { | |
1953 GtkTreeModel *store; | |
1954 GtkTreeIter iter; | |
1955 gint valid = TRUE; | |
1956 | |
1957 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
1958 gtk_tree_model_get_iter(store, &iter, tpath); | |
1959 gtk_tree_path_free(tpath); | |
1960 | |
1961 while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vfi->listview), &iter, FALSE) == 0) | |
1962 { | |
1963 GList *list; | |
1964 | |
1965 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
1966 | |
1967 while (!fd && list) | |
1968 { | |
138 | 1969 IconData *id = list->data; |
1970 if (id && !id->fd->pixbuf) fd = id->fd; | |
9 | 1971 list = list->next; |
1972 } | |
1973 | |
1974 valid = gtk_tree_model_iter_next(store, &iter); | |
1975 } | |
1976 } | |
1977 | |
1978 /* then find first undone */ | |
1979 | |
1980 if (!fd) | |
1981 { | |
1982 GList *work = vfi->list; | |
1983 while (work && !fd) | |
1984 { | |
138 | 1985 IconData *id = work->data; |
1986 FileData *fd_p = id->fd; | |
9 | 1987 work = work->next; |
1988 | |
1989 if (!fd_p->pixbuf) fd = fd_p; | |
1990 } | |
1991 } | |
1992 | |
1993 if (!fd) | |
1994 { | |
1995 /* done */ | |
1996 vficon_thumb_cleanup(vfi); | |
1997 return FALSE; | |
1998 } | |
1999 | |
2000 vfi->thumbs_count++; | |
2001 | |
2002 vfi->thumbs_fd = fd; | |
2003 | |
2004 thumb_loader_free(vfi->thumbs_loader); | |
2005 | |
333 | 2006 vfi->thumbs_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); |
9 | 2007 thumb_loader_set_callbacks(vfi->thumbs_loader, |
2008 vficon_thumb_done_cb, | |
2009 vficon_thumb_error_cb, | |
2010 NULL, | |
2011 vfi); | |
2012 | |
2013 if (!thumb_loader_start(vfi->thumbs_loader, fd->path)) | |
2014 { | |
2015 /* set icon to unknown, continue */ | |
495 | 2016 DEBUG_1("thumb loader start failed %s\n", vfi->thumbs_loader->path); |
9 | 2017 vficon_thumb_do(vfi, vfi->thumbs_loader, fd); |
2018 | |
2019 return TRUE; | |
2020 } | |
2021 | |
2022 return FALSE; | |
2023 } | |
2024 | |
2025 static void vficon_thumb_update(ViewFileIcon *vfi) | |
2026 { | |
2027 vficon_thumb_stop(vfi); | |
2028 | |
2029 vficon_thumb_status(vfi, 0.0, _("Loading thumbs...")); | |
2030 vfi->thumbs_running = TRUE; | |
2031 | |
2032 while (vficon_thumb_next(vfi)); | |
2033 } | |
2034 | |
2035 /* | |
2036 *----------------------------------------------------------------------------- | |
2037 * row stuff | |
2038 *----------------------------------------------------------------------------- | |
2039 */ | |
2040 | |
2041 FileData *vficon_index_get_data(ViewFileIcon *vfi, gint row) | |
2042 { | |
138 | 2043 IconData *id; |
442 | 2044 |
138 | 2045 id = g_list_nth_data(vfi->list, row); |
2046 return id ? id->fd : NULL; | |
9 | 2047 } |
2048 | |
2049 gchar *vficon_index_get_path(ViewFileIcon *vfi, gint row) | |
2050 { | |
2051 FileData *fd; | |
138 | 2052 IconData *id; |
442 | 2053 |
138 | 2054 id = g_list_nth_data(vfi->list, row); |
2055 fd = id ? id->fd : NULL; | |
9 | 2056 |
2057 return (fd ? fd->path : NULL); | |
2058 } | |
2059 | |
2060 gint vficon_index_by_path(ViewFileIcon *vfi, const gchar *path) | |
2061 { | |
2062 gint p = 0; | |
2063 GList *work; | |
2064 | |
2065 if (!path) return -1; | |
2066 | |
2067 work = vfi->list; | |
2068 while (work) | |
2069 { | |
138 | 2070 IconData *id = work->data; |
2071 FileData *fd = id->fd; | |
9 | 2072 if (strcmp(path, fd->path) == 0) return p; |
2073 work = work->next; | |
2074 p++; | |
2075 } | |
2076 | |
2077 return -1; | |
2078 } | |
2079 | |
138 | 2080 gint vficon_index_by_fd(ViewFileIcon *vfi, FileData *in_fd) |
2081 { | |
2082 gint p = 0; | |
2083 GList *work; | |
2084 | |
2085 if (!in_fd) return -1; | |
2086 | |
2087 work = vfi->list; | |
2088 while (work) | |
2089 { | |
2090 IconData *id = work->data; | |
2091 FileData *fd = id->fd; | |
2092 if (fd == in_fd) return p; | |
2093 work = work->next; | |
2094 p++; | |
2095 } | |
2096 | |
2097 return -1; | |
2098 } | |
2099 | |
2100 static gint vficon_index_by_id(ViewFileIcon *vfi, IconData *in_id) | |
2101 { | |
2102 gint p = 0; | |
2103 GList *work; | |
2104 | |
2105 if (!in_id) return -1; | |
2106 | |
2107 work = vfi->list; | |
2108 while (work) | |
2109 { | |
2110 IconData *id = work->data; | |
2111 if (id == in_id) return p; | |
2112 work = work->next; | |
2113 p++; | |
2114 } | |
2115 | |
2116 return -1; | |
2117 } | |
2118 | |
9 | 2119 gint vficon_count(ViewFileIcon *vfi, gint64 *bytes) |
2120 { | |
2121 if (bytes) | |
2122 { | |
2123 gint64 b = 0; | |
2124 GList *work; | |
2125 | |
2126 work = vfi->list; | |
2127 while (work) | |
2128 { | |
442 | 2129 |
138 | 2130 IconData *id = work->data; |
2131 FileData *fd = id->fd; | |
9 | 2132 work = work->next; |
2133 b += fd->size; | |
2134 } | |
2135 | |
2136 *bytes = b; | |
2137 } | |
2138 | |
2139 return g_list_length(vfi->list); | |
2140 } | |
2141 | |
2142 GList *vficon_get_list(ViewFileIcon *vfi) | |
2143 { | |
2144 GList *list = NULL; | |
2145 GList *work; | |
2146 | |
2147 work = vfi->list; | |
2148 while (work) | |
2149 { | |
138 | 2150 IconData *id = work->data; |
2151 FileData *fd = id->fd; | |
9 | 2152 work = work->next; |
2153 | |
138 | 2154 list = g_list_prepend(list, file_data_ref(fd)); |
9 | 2155 } |
2156 | |
2157 return g_list_reverse(list); | |
2158 } | |
2159 | |
2160 /* | |
2161 *----------------------------------------------------------------------------- | |
2162 * | |
2163 *----------------------------------------------------------------------------- | |
2164 */ | |
2165 | |
2166 static gint vficon_refresh_real(ViewFileIcon *vfi, gint keep_position) | |
2167 { | |
2168 gint ret = TRUE; | |
2169 GList *old_list; | |
2170 GList *work; | |
138 | 2171 IconData *focus_id; |
2172 | |
2173 focus_id = vfi->focus_id; | |
9 | 2174 |
2175 old_list = vfi->list; | |
2176 vfi->list = NULL; | |
2177 | |
2178 if (vfi->path) | |
2179 { | |
2180 ret = iconlist_read(vfi->path, &vfi->list); | |
2181 } | |
2182 | |
2183 /* check for same files from old_list */ | |
2184 work = old_list; | |
2185 while (work) | |
2186 { | |
138 | 2187 IconData *id; |
9 | 2188 FileData *fd; |
442 | 2189 |
9 | 2190 GList *needle; |
2191 | |
138 | 2192 id = work->data; |
2193 fd = id->fd; | |
442 | 2194 |
9 | 2195 needle = vfi->list; |
2196 while (needle) | |
2197 { | |
138 | 2198 IconData *idn = needle->data; |
2199 FileData *fdn = idn->fd; | |
167 | 2200 if (fdn == fd) |
9 | 2201 { |
2202 /* swap, to retain old thumb, selection */ | |
138 | 2203 needle->data = id; |
2204 work->data = idn; | |
9 | 2205 needle = NULL; |
2206 } | |
2207 else | |
2208 { | |
2209 needle = needle->next; | |
2210 } | |
2211 } | |
2212 | |
2213 work = work->next; | |
2214 } | |
2215 | |
138 | 2216 vfi->list = iconlist_sort(vfi->list, vfi->sort_method, vfi->sort_ascend); |
9 | 2217 |
2218 work = old_list; | |
2219 while (work) | |
2220 { | |
138 | 2221 IconData *id = work->data; |
9 | 2222 work = work->next; |
2223 | |
138 | 2224 if (id == vfi->prev_selection) vfi->prev_selection = NULL; |
2225 if (id == vfi->click_id) vfi->click_id = NULL; | |
9 | 2226 } |
2227 | |
2228 vficon_populate(vfi, TRUE, keep_position); | |
2229 | |
2230 /* attempt to keep focus on same icon when refreshing */ | |
138 | 2231 if (focus_id && g_list_find(vfi->list, focus_id)) |
9 | 2232 { |
138 | 2233 vficon_set_focus(vfi, focus_id); |
9 | 2234 } |
2235 | |
2236 iconlist_free(old_list); | |
2237 | |
2238 return ret; | |
2239 } | |
2240 | |
2241 gint vficon_refresh(ViewFileIcon *vfi) | |
2242 { | |
2243 return vficon_refresh_real(vfi, TRUE); | |
2244 } | |
2245 | |
2246 /* | |
2247 *----------------------------------------------------------------------------- | |
2248 * draw, etc. | |
2249 *----------------------------------------------------------------------------- | |
2250 */ | |
2251 | |
2252 typedef struct _ColumnData ColumnData; | |
2253 struct _ColumnData | |
2254 { | |
2255 ViewFileIcon *vfi; | |
2256 gint number; | |
2257 }; | |
2258 | |
2259 static void vficon_cell_data_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
2260 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
2261 { | |
2262 ColumnData *cd = data; | |
2263 ViewFileIcon *vfi; | |
2264 GtkStyle *style; | |
2265 GList *list; | |
2266 GdkColor color_fg; | |
2267 GdkColor color_bg; | |
138 | 2268 IconData *id; |
9 | 2269 |
2270 vfi = cd->vfi; | |
2271 | |
2272 gtk_tree_model_get(tree_model, iter, FILE_COLUMN_POINTER, &list, -1); | |
442 | 2273 |
138 | 2274 id = g_list_nth_data(list, cd->number); |
442 | 2275 |
138 | 2276 if (id) g_assert(id->fd->magick == 0x12345678); |
442 | 2277 |
9 | 2278 style = gtk_widget_get_style(vfi->listview); |
138 | 2279 if (id && id->selected & SELECTION_SELECTED) |
9 | 2280 { |
2281 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg)); | |
2282 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg)); | |
2283 } | |
2284 else | |
2285 { | |
2286 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg)); | |
2287 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg)); | |
2288 } | |
2289 | |
138 | 2290 if (id && id->selected & SELECTION_PRELIGHT) |
9 | 2291 { |
2292 #if 0 | |
2293 shift_color(&color_fg, -1, 0); | |
2294 #endif | |
2295 shift_color(&color_bg, -1, 0); | |
2296 } | |
2297 | |
2298 if (GQV_IS_CELL_RENDERER_ICON(cell)) | |
442 | 2299 { |
138 | 2300 if (id) |
9 | 2301 { |
138 | 2302 g_object_set(cell, "pixbuf", id->fd->pixbuf, |
2303 "text", id->fd->name, | |
9 | 2304 "cell-background-gdk", &color_bg, |
2305 "cell-background-set", TRUE, | |
2306 "foreground-gdk", &color_fg, | |
2307 "foreground-set", TRUE, | |
138 | 2308 "has-focus", (vfi->focus_id == id), NULL); |
9 | 2309 } |
2310 else | |
2311 { | |
2312 g_object_set(cell, "pixbuf", NULL, | |
2313 "text", NULL, | |
2314 "cell-background-set", FALSE, | |
2315 "foreground-set", FALSE, | |
2316 "has-focus", FALSE, NULL); | |
442 | 2317 } |
9 | 2318 } |
2319 } | |
2320 | |
2321 static void vficon_append_column(ViewFileIcon *vfi, gint n) | |
2322 { | |
2323 ColumnData *cd; | |
2324 GtkTreeViewColumn *column; | |
2325 GtkCellRenderer *renderer; | |
2326 | |
2327 column = gtk_tree_view_column_new(); | |
2328 gtk_tree_view_column_set_min_width(column, 0); | |
2329 | |
2330 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
2331 gtk_tree_view_column_set_alignment(column, 0.5); | |
2332 | |
2333 renderer = gqv_cell_renderer_icon_new(); | |
2334 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
2335 g_object_set(G_OBJECT(renderer), "xpad", THUMB_BORDER_PADDING * 2, | |
2336 "ypad", THUMB_BORDER_PADDING, | |
2337 "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL); | |
2338 | |
2339 g_object_set_data(G_OBJECT(column), "column_number", GINT_TO_POINTER(n)); | |
2340 | |
2341 cd = g_new0(ColumnData, 1); | |
2342 cd->vfi = vfi; | |
2343 cd->number = n; | |
2344 gtk_tree_view_column_set_cell_data_func(column, renderer, vficon_cell_data_cb, cd, g_free); | |
2345 | |
2346 gtk_tree_view_append_column(GTK_TREE_VIEW(vfi->listview), column); | |
2347 } | |
2348 | |
2349 /* | |
2350 *----------------------------------------------------------------------------- | |
2351 * base | |
2352 *----------------------------------------------------------------------------- | |
2353 */ | |
2354 | |
2355 gint vficon_set_path(ViewFileIcon *vfi, const gchar *path) | |
2356 { | |
2357 gint ret; | |
2358 | |
2359 if (!path) return FALSE; | |
2360 if (vfi->path && strcmp(path, vfi->path) == 0) return TRUE; | |
2361 | |
2362 g_free(vfi->path); | |
2363 vfi->path = g_strdup(path); | |
2364 | |
2365 g_list_free(vfi->selection); | |
2366 vfi->selection = NULL; | |
2367 | |
2368 iconlist_free(vfi->list); | |
2369 vfi->list = NULL; | |
2370 | |
2371 /* NOTE: populate will clear the store for us */ | |
2372 ret = vficon_refresh_real(vfi, FALSE); | |
2373 | |
138 | 2374 vfi->focus_id = NULL; |
9 | 2375 vficon_move_focus(vfi, 0, 0, FALSE); |
2376 | |
2377 return ret; | |
2378 } | |
2379 | |
2380 static void vficon_destroy_cb(GtkWidget *widget, gpointer data) | |
2381 { | |
2382 ViewFileIcon *vfi = data; | |
2383 | |
2384 if (vfi->popup) | |
2385 { | |
2386 g_signal_handlers_disconnect_matched(G_OBJECT(vfi->popup), G_SIGNAL_MATCH_DATA, | |
2387 0, 0, 0, NULL, vfi); | |
2388 gtk_widget_destroy(vfi->popup); | |
2389 } | |
2390 | |
2391 if (vfi->sync_idle_id != -1) g_source_remove(vfi->sync_idle_id); | |
2392 | |
2393 tip_unschedule(vfi); | |
2394 | |
2395 vficon_thumb_cleanup(vfi); | |
2396 | |
2397 g_free(vfi->path); | |
2398 | |
2399 iconlist_free(vfi->list); | |
2400 g_list_free(vfi->selection); | |
2401 g_free(vfi); | |
2402 } | |
2403 | |
2404 ViewFileIcon *vficon_new(const gchar *path) | |
2405 { | |
2406 ViewFileIcon *vfi; | |
2407 GtkListStore *store; | |
2408 GtkTreeSelection *selection; | |
2409 gint i; | |
2410 | |
2411 vfi = g_new0(ViewFileIcon, 1); | |
2412 | |
2413 vfi->path = NULL; | |
2414 vfi->sort_method = SORT_NAME; | |
2415 vfi->sort_ascend = TRUE; | |
2416 | |
2417 vfi->selection = NULL; | |
2418 vfi->prev_selection = NULL; | |
2419 | |
2420 vfi->tip_window = NULL; | |
2421 vfi->tip_delay_id = -1; | |
2422 | |
2423 vfi->focus_row = 0; | |
2424 vfi->focus_column = 0; | |
138 | 2425 vfi->focus_id = NULL; |
9 | 2426 |
320 | 2427 vfi->show_text = options->show_icon_names; |
9 | 2428 |
2429 vfi->sync_idle_id = -1; | |
2430 | |
2431 vfi->popup = NULL; | |
2432 | |
2433 vfi->widget = gtk_scrolled_window_new(NULL, NULL); | |
2434 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vfi->widget), GTK_SHADOW_IN); | |
2435 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vfi->widget), | |
2436 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
2437 g_signal_connect(G_OBJECT(vfi->widget), "destroy", | |
2438 G_CALLBACK(vficon_destroy_cb), vfi); | |
2439 | |
2440 store = gtk_list_store_new(1, G_TYPE_POINTER); | |
2441 vfi->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
2442 g_object_unref(store); | |
2443 | |
2444 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vfi->listview)); | |
2445 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_NONE); | |
2446 | |
2447 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vfi->listview), FALSE); | |
2448 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vfi->listview), FALSE); | |
2449 | |
2450 for (i = 0; i < VFICON_MAX_COLUMNS; i++) | |
2451 { | |
2452 vficon_append_column(vfi, i); | |
2453 } | |
2454 | |
2455 /* zero width column to hide tree view focus, we draw it ourselves */ | |
2456 vficon_append_column(vfi, i); | |
2457 /* end column to fill white space */ | |
2458 vficon_append_column(vfi, i); | |
2459 | |
2460 g_signal_connect(G_OBJECT(vfi->listview), "size_allocate", | |
2461 G_CALLBACK(vficon_sized_cb), vfi); | |
2462 g_signal_connect(G_OBJECT(vfi->listview), "key_press_event", | |
2463 G_CALLBACK(vficon_press_key_cb), vfi); | |
2464 | |
2465 gtk_container_add(GTK_CONTAINER(vfi->widget), vfi->listview); | |
2466 gtk_widget_show(vfi->listview); | |
2467 | |
2468 vficon_dnd_init(vfi); | |
2469 | |
2470 gtk_widget_set_events(vfi->listview, GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK | | |
2471 GDK_BUTTON_PRESS_MASK | GDK_LEAVE_NOTIFY_MASK); | |
2472 g_signal_connect(G_OBJECT(vfi->listview), "button_press_event", | |
2473 G_CALLBACK(vficon_press_cb), vfi); | |
2474 g_signal_connect(G_OBJECT(vfi->listview), "button_release_event", | |
2475 G_CALLBACK(vficon_release_cb), vfi); | |
2476 g_signal_connect(G_OBJECT(vfi->listview),"motion_notify_event", | |
2477 G_CALLBACK(vficon_motion_cb), vfi); | |
2478 g_signal_connect(G_OBJECT(vfi->listview), "leave_notify_event", | |
2479 G_CALLBACK(vficon_leave_cb), vfi); | |
2480 | |
2481 /* force vfi->columns to be at least 1 (sane) - this will be corrected in the size_cb */ | |
2482 vficon_populate_at_new_size(vfi, 1, 1, FALSE); | |
2483 | |
2484 if (path) vficon_set_path(vfi, path); | |
2485 | |
2486 return vfi; | |
2487 } | |
2488 | |
2489 void vficon_set_status_func(ViewFileIcon *vfi, | |
2490 void (*func)(ViewFileIcon *vfi, gpointer data), gpointer data) | |
2491 { | |
2492 vfi->func_status = func; | |
2493 vfi->data_status = data; | |
2494 } | |
2495 | |
2496 void vficon_set_thumb_status_func(ViewFileIcon *vfi, | |
2497 void (*func)(ViewFileIcon *vfi, gdouble val, const gchar *text, gpointer data), | |
2498 gpointer data) | |
2499 { | |
2500 vfi->func_thumb_status = func; | |
2501 vfi->data_thumb_status = data; | |
2502 } | |
2503 | |
2504 void vficon_set_layout(ViewFileIcon *vfi, LayoutWindow *layout) | |
2505 { | |
2506 vfi->layout = layout; | |
2507 } | |
2508 | |
2509 /* | |
2510 *----------------------------------------------------------------------------- | |
2511 * maintenance (for rename, move, remove) | |
2512 *----------------------------------------------------------------------------- | |
2513 */ | |
2514 | |
2515 static gint vficon_maint_find_closest(ViewFileIcon *vfi, gint row, gint count, GList *ignore_list) | |
2516 { | |
2517 GList *list = NULL; | |
2518 GList *work; | |
2519 gint rev = row - 1; | |
2520 row ++; | |
2521 | |
2522 work = ignore_list; | |
2523 while (work) | |
2524 { | |
138 | 2525 FileData *fd = work->data; |
2526 gint f = vficon_index_by_fd(vfi, work->data); | |
2527 g_assert(fd->magick == 0x12345678); | |
9 | 2528 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f)); |
2529 work = work->next; | |
2530 } | |
2531 | |
2532 while (list) | |
2533 { | |
2534 gint c = TRUE; | |
2535 work = list; | |
2536 while (work && c) | |
2537 { | |
2538 gpointer p = work->data; | |
2539 work = work->next; | |
2540 if (row == GPOINTER_TO_INT(p)) | |
2541 { | |
2542 row++; | |
2543 c = FALSE; | |
2544 } | |
2545 if (rev == GPOINTER_TO_INT(p)) | |
2546 { | |
2547 rev--; | |
2548 c = FALSE; | |
2549 } | |
2550 if (!c) list = g_list_remove(list, p); | |
2551 } | |
2552 if (c && list) | |
2553 { | |
2554 g_list_free(list); | |
2555 list = NULL; | |
2556 } | |
2557 } | |
2558 if (row > count - 1) | |
2559 { | |
2560 if (rev < 0) | |
2561 return -1; | |
2562 else | |
2563 return rev; | |
2564 } | |
2565 else | |
2566 { | |
2567 return row; | |
2568 } | |
2569 } | |
2570 | |
138 | 2571 gint vficon_maint_renamed(ViewFileIcon *vfi, FileData *fd) |
9 | 2572 { |
2573 gint ret = FALSE; | |
2574 gint row; | |
2575 gchar *source_base; | |
2576 gchar *dest_base; | |
138 | 2577 IconData *id = vficon_icon_data(vfi, fd); |
2578 | |
2579 if (!id) return FALSE; | |
2580 | |
2581 row = vficon_index_by_id(vfi, id); | |
9 | 2582 if (row < 0) return FALSE; |
2583 | |
138 | 2584 source_base = remove_level_from_path(fd->change->source); |
2585 dest_base = remove_level_from_path(fd->change->dest); | |
9 | 2586 |
2587 if (strcmp(source_base, dest_base) == 0) | |
2588 { | |
138 | 2589 vfi->list = g_list_remove(vfi->list, id); |
2590 vfi->list = iconlist_insert_sort(vfi->list, id, vfi->sort_method, vfi->sort_ascend); | |
9 | 2591 |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
2592 vficon_sync_idle(vfi); |
9 | 2593 ret = TRUE; |
2594 } | |
2595 else | |
2596 { | |
138 | 2597 ret = vficon_maint_removed(vfi, fd, NULL); |
9 | 2598 } |
2599 | |
2600 g_free(source_base); | |
2601 g_free(dest_base); | |
2602 | |
2603 return ret; | |
2604 } | |
2605 | |
138 | 2606 gint vficon_maint_removed(ViewFileIcon *vfi, FileData *fd, GList *ignore_list) |
9 | 2607 { |
2608 gint row; | |
2609 gint new_row = -1; | |
2610 GtkTreeModel *store; | |
2611 GtkTreeIter iter; | |
138 | 2612 IconData *id = vficon_icon_data(vfi, fd); |
2613 | |
2614 if (!id) return FALSE; | |
2615 | |
2616 row = g_list_index(vfi->list, id); | |
9 | 2617 if (row < 0) return FALSE; |
2618 | |
138 | 2619 if ((id->selected & SELECTION_SELECTED) && |
9 | 2620 layout_image_get_collection(vfi->layout, NULL) == NULL) |
2621 { | |
138 | 2622 vficon_unselect(vfi, id); |
9 | 2623 |
2624 if (!vfi->selection) | |
2625 { | |
2626 gint n; | |
2627 | |
2628 n = vficon_count(vfi, NULL); | |
2629 if (ignore_list) | |
2630 { | |
2631 new_row = vficon_maint_find_closest(vfi, row, n, ignore_list); | |
495 | 2632 DEBUG_1("row = %d, closest is %d\n", row, new_row); |
9 | 2633 } |
2634 else | |
2635 { | |
2636 if (row + 1 < n) | |
2637 { | |
2638 new_row = row + 1; | |
2639 } | |
2640 else if (row > 0) | |
2641 { | |
2642 new_row = row - 1; | |
2643 } | |
2644 } | |
2645 } | |
2646 else if (ignore_list) | |
2647 { | |
2648 GList *work; | |
2649 | |
2650 work = vfi->selection; | |
2651 while (work) | |
2652 { | |
138 | 2653 IconData *ignore_id; |
9 | 2654 FileData *ignore_fd; |
2655 GList *tmp; | |
2656 gint match = FALSE; | |
2657 | |
138 | 2658 ignore_id = work->data; |
2659 ignore_fd = ignore_id->fd; | |
442 | 2660 g_assert(ignore_fd->magick == 0x12345678); |
9 | 2661 work = work->next; |
2662 | |
2663 tmp = ignore_list; | |
2664 while (tmp && !match) | |
2665 { | |
138 | 2666 FileData *ignore_list_fd = tmp->data; |
442 | 2667 g_assert(ignore_list_fd->magick == 0x12345678); |
9 | 2668 tmp = tmp->next; |
2669 | |
138 | 2670 if (ignore_list_fd == ignore_fd) |
9 | 2671 { |
2672 match = TRUE; | |
2673 } | |
2674 } | |
2675 if (!match) | |
2676 { | |
138 | 2677 new_row = g_list_index(vfi->list, ignore_id); |
9 | 2678 work = NULL; |
2679 } | |
2680 } | |
2681 if (new_row == -1) | |
2682 { | |
2683 /* selection all ignored, use closest */ | |
2684 new_row = vficon_maint_find_closest(vfi, row, vficon_count(vfi, NULL), ignore_list); | |
2685 } | |
2686 } | |
2687 else | |
2688 { | |
2689 new_row = g_list_index(vfi->list, vfi->selection->data); | |
2690 } | |
2691 if (new_row >= 0) | |
2692 { | |
272 | 2693 IconData *idn = g_list_nth_data(vfi->list, new_row); |
9 | 2694 |
138 | 2695 vficon_select(vfi, idn); |
2696 vficon_send_layout_select(vfi, idn); | |
9 | 2697 } |
2698 } | |
2699 | |
2700 /* Thumb loader check */ | |
2701 if (fd == vfi->thumbs_fd) vfi->thumbs_fd = NULL; | |
111
3a69a7a3f461
Wed Nov 15 02:05:27 2006 John Ellis <johne@verizon.net>
gqview
parents:
85
diff
changeset
|
2702 if (vfi->thumbs_count > 0) vfi->thumbs_count--; |
9 | 2703 |
138 | 2704 if (vfi->prev_selection == id) vfi->prev_selection = NULL; |
2705 if (vfi->click_id == id) vfi->click_id = NULL; | |
9 | 2706 |
2707 /* remove pointer to this fd from grid */ | |
2708 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | |
138 | 2709 if (id->row >= 0 && |
2710 gtk_tree_model_iter_nth_child(store, &iter, NULL, id->row)) | |
9 | 2711 { |
2712 GList *list; | |
2713 | |
2714 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | |
138 | 2715 list = g_list_find(list, id); |
9 | 2716 if (list) list->data = NULL; |
2717 } | |
2718 | |
138 | 2719 vfi->list = g_list_remove(vfi->list, id); |
2720 file_data_unref(fd); | |
2721 g_free(id); | |
9 | 2722 |
2723 vficon_sync_idle(vfi); | |
2724 vficon_send_update(vfi); | |
2725 | |
2726 return TRUE; | |
2727 } | |
2728 | |
138 | 2729 gint vficon_maint_moved(ViewFileIcon *vfi, FileData *fd, GList *ignore_list) |
9 | 2730 { |
2731 gint ret = FALSE; | |
2732 gchar *buf; | |
2733 | |
138 | 2734 if (!fd->change->source || !vfi->path) return FALSE; |
2735 | |
2736 buf = remove_level_from_path(fd->change->source); | |
9 | 2737 |
2738 if (strcmp(buf, vfi->path) == 0) | |
2739 { | |
138 | 2740 ret = vficon_maint_removed(vfi, fd, ignore_list); |
9 | 2741 } |
2742 | |
2743 g_free(buf); | |
2744 | |
2745 return ret; | |
2746 } |