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