Mercurial > geeqie.yaz
comparison src/view_file_icon.c @ 138:71e1ebee420e
replaced gchar* path with FileData *fd
author | nadvornik |
---|---|
date | Tue, 11 Sep 2007 20:06:29 +0000 |
parents | 55166d93498d |
children | e57b0207e180 |
comparison
equal
deleted
inserted
replaced
137:be3328a58875 | 138:71e1ebee420e |
---|---|
41 #define VFICON_MAX_COLUMNS 32 | 41 #define VFICON_MAX_COLUMNS 32 |
42 #define THUMB_BORDER_PADDING 2 | 42 #define THUMB_BORDER_PADDING 2 |
43 | 43 |
44 #define VFICON_TIP_DELAY 500 | 44 #define VFICON_TIP_DELAY 500 |
45 | 45 |
46 #define ICON_DATA(x) ((IconData *)x) | |
47 #define FILE_DATA(x) ((FileData *)x) | |
48 | |
49 | |
50 enum { | 46 enum { |
51 FILE_COLUMN_POINTER = 0, | 47 FILE_COLUMN_POINTER = 0, |
52 FILE_COLUMN_COUNT | 48 FILE_COLUMN_COUNT |
53 }; | 49 }; |
54 | 50 |
60 } SelectionType; | 56 } SelectionType; |
61 | 57 |
62 typedef struct _IconData IconData; | 58 typedef struct _IconData IconData; |
63 struct _IconData | 59 struct _IconData |
64 { | 60 { |
65 FileData fd; | |
66 SelectionType selected; | 61 SelectionType selected; |
67 gint row; | 62 gint row; |
63 FileData *fd; | |
68 }; | 64 }; |
65 | |
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 } | |
69 | 83 |
70 | 84 |
71 static gint iconlist_read(const gchar *path, GList **list) | 85 static gint iconlist_read(const gchar *path, GList **list) |
72 { | 86 { |
73 GList *temp; | 87 GList *temp; |
80 { | 94 { |
81 FileData *fd; | 95 FileData *fd; |
82 IconData *id; | 96 IconData *id; |
83 | 97 |
84 fd = work->data; | 98 fd = work->data; |
99 g_assert(fd->magick == 0x12345678); | |
85 id = g_new0(IconData, 1); | 100 id = g_new0(IconData, 1); |
86 | 101 |
87 memcpy(id, fd, sizeof(FileData)); | |
88 id->selected = SELECTION_NONE; | 102 id->selected = SELECTION_NONE; |
89 id->row = -1; | 103 id->row = -1; |
104 id->fd = fd; | |
90 | 105 |
91 work->data = id; | 106 work->data = id; |
92 g_free(fd); | |
93 | |
94 work = work->next; | 107 work = work->next; |
95 } | 108 } |
96 | 109 |
97 *list = temp; | 110 *list = temp; |
98 | 111 |
99 return TRUE; | 112 return TRUE; |
100 } | 113 } |
101 | 114 |
102 static void iconlist_free(GList *list) | 115 static void iconlist_free(GList *list) |
103 { | 116 { |
104 filelist_free(list); | 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); | |
105 } | 144 } |
106 | 145 |
107 | 146 |
108 static void vficon_toggle_filenames(ViewFileIcon *vfi); | 147 static void vficon_toggle_filenames(ViewFileIcon *vfi); |
109 static void vficon_selection_remove(ViewFileIcon *vfi, FileData *fd, SelectionType mask, GtkTreeIter *iter); | 148 static void vficon_selection_remove(ViewFileIcon *vfi, IconData *id, SelectionType mask, GtkTreeIter *iter); |
110 static void vficon_move_focus(ViewFileIcon *vfi, gint row, gint col, gint relative); | 149 static void vficon_move_focus(ViewFileIcon *vfi, gint row, gint col, gint relative); |
111 static void vficon_set_focus(ViewFileIcon *vfi, FileData *fd); | 150 static void vficon_set_focus(ViewFileIcon *vfi, IconData *id); |
112 static void vficon_thumb_update(ViewFileIcon *vfi); | 151 static void vficon_thumb_update(ViewFileIcon *vfi); |
113 static void vficon_populate_at_new_size(ViewFileIcon *vfi, gint w, gint h, gint force); | 152 static void vficon_populate_at_new_size(ViewFileIcon *vfi, gint w, gint h, gint force); |
114 | 153 |
115 | 154 |
116 /* | 155 /* |
119 *----------------------------------------------------------------------------- | 158 *----------------------------------------------------------------------------- |
120 */ | 159 */ |
121 | 160 |
122 static GList *vficon_pop_menu_file_list(ViewFileIcon *vfi) | 161 static GList *vficon_pop_menu_file_list(ViewFileIcon *vfi) |
123 { | 162 { |
124 if (!vfi->click_fd) return NULL; | 163 if (!vfi->click_id) return NULL; |
125 | 164 |
126 if (ICON_DATA(vfi->click_fd)->selected & SELECTION_SELECTED) | 165 if (vfi->click_id->selected & SELECTION_SELECTED) |
127 { | 166 { |
128 return vficon_selection_get_list(vfi); | 167 return vficon_selection_get_list(vfi); |
129 } | 168 } |
130 | 169 |
131 return g_list_append(NULL, g_strdup(vfi->click_fd->path)); | 170 return g_list_append(NULL, file_data_ref(vfi->click_id->fd)); |
132 } | 171 } |
133 | 172 |
134 static void vficon_pop_menu_edit_cb(GtkWidget *widget, gpointer data) | 173 static void vficon_pop_menu_edit_cb(GtkWidget *widget, gpointer data) |
135 { | 174 { |
136 ViewFileIcon *vfi; | 175 ViewFileIcon *vfi; |
141 n = GPOINTER_TO_INT(data); | 180 n = GPOINTER_TO_INT(data); |
142 | 181 |
143 if (!vfi) return; | 182 if (!vfi) return; |
144 | 183 |
145 list = vficon_pop_menu_file_list(vfi); | 184 list = vficon_pop_menu_file_list(vfi); |
146 start_editor_from_path_list(n, list); | 185 start_editor_from_filelist(n, list); |
147 path_list_free(list); | 186 filelist_free(list); |
148 } | 187 } |
149 | 188 |
150 static void vficon_pop_menu_info_cb(GtkWidget *widget, gpointer data) | 189 static void vficon_pop_menu_info_cb(GtkWidget *widget, gpointer data) |
151 { | 190 { |
152 ViewFileIcon *vfi = data; | 191 ViewFileIcon *vfi = data; |
156 | 195 |
157 static void vficon_pop_menu_view_cb(GtkWidget *widget, gpointer data) | 196 static void vficon_pop_menu_view_cb(GtkWidget *widget, gpointer data) |
158 { | 197 { |
159 ViewFileIcon *vfi = data; | 198 ViewFileIcon *vfi = data; |
160 | 199 |
161 if (!vfi->click_fd) return; | 200 if (!vfi->click_id) return; |
162 | 201 |
163 if (ICON_DATA(vfi->click_fd)->selected & SELECTION_SELECTED) | 202 if (vfi->click_id->selected & SELECTION_SELECTED) |
164 { | 203 { |
165 GList *list; | 204 GList *list; |
166 | 205 |
167 list = vficon_selection_get_list(vfi); | 206 list = vficon_selection_get_list(vfi); |
168 view_window_new_from_list(list); | 207 view_window_new_from_list(list); |
169 path_list_free(list); | 208 filelist_free(list); |
170 } | 209 } |
171 else | 210 else |
172 { | 211 { |
173 view_window_new(vfi->click_fd->path); | 212 view_window_new(vfi->click_id->fd); |
174 } | 213 } |
175 } | 214 } |
176 | 215 |
177 static void vficon_pop_menu_copy_cb(GtkWidget *widget, gpointer data) | 216 static void vficon_pop_menu_copy_cb(GtkWidget *widget, gpointer data) |
178 { | 217 { |
260 } | 299 } |
261 | 300 |
262 static void vficon_popup_destroy_cb(GtkWidget *widget, gpointer data) | 301 static void vficon_popup_destroy_cb(GtkWidget *widget, gpointer data) |
263 { | 302 { |
264 ViewFileIcon *vfi = data; | 303 ViewFileIcon *vfi = data; |
265 vficon_selection_remove(vfi, vfi->click_fd, SELECTION_PRELIGHT, NULL); | 304 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); |
266 vfi->click_fd = NULL; | 305 vfi->click_id = NULL; |
267 vfi->popup = NULL; | 306 vfi->popup = NULL; |
268 } | 307 } |
269 | 308 |
270 static GtkWidget *vficon_pop_menu(ViewFileIcon *vfi, gint active) | 309 static GtkWidget *vficon_pop_menu(ViewFileIcon *vfi, gint active) |
271 { | 310 { |
326 static void vficon_send_update(ViewFileIcon *vfi) | 365 static void vficon_send_update(ViewFileIcon *vfi) |
327 { | 366 { |
328 if (vfi->func_status) vfi->func_status(vfi, vfi->data_status); | 367 if (vfi->func_status) vfi->func_status(vfi, vfi->data_status); |
329 } | 368 } |
330 | 369 |
331 static void vficon_send_layout_select(ViewFileIcon *vfi, FileData *fd) | 370 static void vficon_send_layout_select(ViewFileIcon *vfi, IconData *id) |
332 { | 371 { |
333 const gchar *read_ahead_path = NULL; | 372 FileData *read_ahead_fd = NULL; |
334 | 373 FileData *fd; |
335 if (!vfi->layout || !fd) return; | 374 |
336 | 375 if (!vfi->layout || !id) return; |
376 | |
377 fd = id->fd; | |
378 | |
337 if (enable_read_ahead) | 379 if (enable_read_ahead) |
338 { | 380 { |
339 FileData *fd_n; | 381 FileData *fd_n; |
340 gint row; | 382 gint row; |
341 | 383 |
342 row = g_list_index(vfi->list, fd); | 384 row = g_list_index(vfi->list, id); |
343 if (row > vficon_index_by_path(vfi, layout_image_get_path(vfi->layout)) && | 385 if (row > vficon_index_by_path(vfi, layout_image_get_path(vfi->layout)) && |
344 row + 1 < vficon_count(vfi, NULL)) | 386 row + 1 < vficon_count(vfi, NULL)) |
345 { | 387 { |
346 fd_n = vficon_index_get_data(vfi, row + 1); | 388 fd_n = vficon_index_get_data(vfi, row + 1); |
347 } | 389 } |
351 } | 393 } |
352 else | 394 else |
353 { | 395 { |
354 fd_n = NULL; | 396 fd_n = NULL; |
355 } | 397 } |
356 if (fd_n) read_ahead_path = fd_n->path; | 398 if (fd_n) read_ahead_fd = fd_n; |
357 } | 399 } |
358 | 400 |
359 layout_image_set_with_ahead(vfi->layout, fd->path, read_ahead_path); | 401 layout_image_set_with_ahead(vfi->layout, fd, read_ahead_fd); |
360 } | 402 } |
361 | 403 |
362 static void vficon_toggle_filenames(ViewFileIcon *vfi) | 404 static void vficon_toggle_filenames(ViewFileIcon *vfi) |
363 { | 405 { |
364 vfi->show_text = !vfi->show_text; | 406 vfi->show_text = !vfi->show_text; |
384 *------------------------------------------------------------------- | 426 *------------------------------------------------------------------- |
385 * misc utils | 427 * misc utils |
386 *------------------------------------------------------------------- | 428 *------------------------------------------------------------------- |
387 */ | 429 */ |
388 | 430 |
389 static gint vficon_find_position(ViewFileIcon *vfi, FileData *fd, gint *row, gint *col) | 431 static gint vficon_find_position(ViewFileIcon *vfi, IconData *id, gint *row, gint *col) |
390 { | 432 { |
391 gint n; | 433 gint n; |
392 | 434 |
393 n = g_list_index(vfi->list, fd); | 435 n = g_list_index(vfi->list, id); |
394 | 436 |
395 if (n < 0) return FALSE; | 437 if (n < 0) return FALSE; |
396 | 438 |
397 *row = n / vfi->columns; | 439 *row = n / vfi->columns; |
398 *col = n - (*row * vfi->columns); | 440 *col = n - (*row * vfi->columns); |
399 | 441 |
400 return TRUE; | 442 return TRUE; |
401 } | 443 } |
402 | 444 |
403 static gint vficon_find_iter(ViewFileIcon *vfi, FileData *fd, GtkTreeIter *iter, gint *column) | 445 static gint vficon_find_iter(ViewFileIcon *vfi, IconData *id, GtkTreeIter *iter, gint *column) |
404 { | 446 { |
405 GtkTreeModel *store; | 447 GtkTreeModel *store; |
406 gint row, col; | 448 gint row, col; |
407 | 449 |
408 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | 450 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); |
409 if (!vficon_find_position(vfi, fd, &row, &col)) return FALSE; | 451 if (!vficon_find_position(vfi, id, &row, &col)) return FALSE; |
410 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE; | 452 if (!gtk_tree_model_iter_nth_child(store, iter, NULL, row)) return FALSE; |
411 if (column) *column = col; | 453 if (column) *column = col; |
412 | 454 |
413 return TRUE; | 455 return TRUE; |
414 } | 456 } |
415 | 457 |
416 static FileData *vficon_find_data(ViewFileIcon *vfi, gint row, gint col, GtkTreeIter *iter) | 458 static IconData *vficon_find_data(ViewFileIcon *vfi, gint row, gint col, GtkTreeIter *iter) |
417 { | 459 { |
418 GtkTreeModel *store; | 460 GtkTreeModel *store; |
419 GtkTreeIter p; | 461 GtkTreeIter p; |
420 | 462 |
421 if (row < 0 || col < 0) return NULL; | 463 if (row < 0 || col < 0) return NULL; |
434 } | 476 } |
435 | 477 |
436 return NULL; | 478 return NULL; |
437 } | 479 } |
438 | 480 |
439 static FileData *vficon_find_data_by_coord(ViewFileIcon *vfi, gint x, gint y, GtkTreeIter *iter) | 481 static IconData *vficon_find_data_by_coord(ViewFileIcon *vfi, gint x, gint y, GtkTreeIter *iter) |
440 { | 482 { |
441 GtkTreePath *tpath; | 483 GtkTreePath *tpath; |
442 GtkTreeViewColumn *column; | 484 GtkTreeViewColumn *column; |
443 | 485 |
444 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), x, y, | 486 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), x, y, |
479 | 521 |
480 if (vfi->tip_window) return; | 522 if (vfi->tip_window) return; |
481 | 523 |
482 gdk_window_get_pointer(gtk_tree_view_get_bin_window(GTK_TREE_VIEW(vfi->listview)), &x, &y, NULL); | 524 gdk_window_get_pointer(gtk_tree_view_get_bin_window(GTK_TREE_VIEW(vfi->listview)), &x, &y, NULL); |
483 | 525 |
484 vfi->tip_fd = vficon_find_data_by_coord(vfi, x, y, NULL); | 526 vfi->tip_id = vficon_find_data_by_coord(vfi, x, y, NULL); |
485 if (!vfi->tip_fd) return; | 527 if (!vfi->tip_id) return; |
486 | 528 |
487 vfi->tip_window = gtk_window_new(GTK_WINDOW_POPUP); | 529 vfi->tip_window = gtk_window_new(GTK_WINDOW_POPUP); |
488 gtk_window_set_resizable(GTK_WINDOW(vfi->tip_window), FALSE); | 530 gtk_window_set_resizable(GTK_WINDOW(vfi->tip_window), FALSE); |
489 gtk_container_set_border_width(GTK_CONTAINER(vfi->tip_window), 2); | 531 gtk_container_set_border_width(GTK_CONTAINER(vfi->tip_window), 2); |
490 | 532 |
491 label = gtk_label_new(vfi->tip_fd->name); | 533 label = gtk_label_new(vfi->tip_id->fd->name); |
492 | 534 |
493 g_object_set_data(G_OBJECT(vfi->tip_window), "tip_label", label); | 535 g_object_set_data(G_OBJECT(vfi->tip_window), "tip_label", label); |
494 gtk_container_add(GTK_CONTAINER(vfi->tip_window), label); | 536 gtk_container_add(GTK_CONTAINER(vfi->tip_window), label); |
495 gtk_widget_show(label); | 537 gtk_widget_show(label); |
496 | 538 |
548 | 590 |
549 if (vfi->tip_delay_id != -1) g_source_remove(vfi->tip_delay_id); | 591 if (vfi->tip_delay_id != -1) g_source_remove(vfi->tip_delay_id); |
550 vfi->tip_delay_id = -1; | 592 vfi->tip_delay_id = -1; |
551 } | 593 } |
552 | 594 |
553 static void tip_update(ViewFileIcon *vfi, FileData *fd) | 595 static void tip_update(ViewFileIcon *vfi, IconData *id) |
554 { | 596 { |
555 if (vfi->tip_window) | 597 if (vfi->tip_window) |
556 { | 598 { |
557 gint x, y; | 599 gint x, y; |
558 | 600 |
559 gdk_window_get_pointer(NULL, &x, &y, NULL); | 601 gdk_window_get_pointer(NULL, &x, &y, NULL); |
560 gtk_window_move(GTK_WINDOW(vfi->tip_window), x + 16, y + 16); | 602 gtk_window_move(GTK_WINDOW(vfi->tip_window), x + 16, y + 16); |
561 | 603 |
562 if (fd != vfi->tip_fd) | 604 if (id != vfi->tip_id) |
563 { | 605 { |
564 GtkWidget *label; | 606 GtkWidget *label; |
565 | 607 |
566 vfi->tip_fd = fd; | 608 vfi->tip_id = id; |
567 | 609 |
568 if (!vfi->tip_fd) | 610 if (!vfi->tip_id) |
569 { | 611 { |
570 tip_hide(vfi); | 612 tip_hide(vfi); |
571 tip_schedule(vfi); | 613 tip_schedule(vfi); |
572 return; | 614 return; |
573 } | 615 } |
574 | 616 |
575 label = g_object_get_data(G_OBJECT(vfi->tip_window), "tip_label"); | 617 label = g_object_get_data(G_OBJECT(vfi->tip_window), "tip_label"); |
576 gtk_label_set_text(GTK_LABEL(label), vfi->tip_fd->name); | 618 gtk_label_set_text(GTK_LABEL(label), vfi->tip_id->fd->name); |
577 } | 619 } |
578 } | 620 } |
579 else | 621 else |
580 { | 622 { |
581 tip_schedule(vfi); | 623 tip_schedule(vfi); |
595 ViewFileIcon *vfi = data; | 637 ViewFileIcon *vfi = data; |
596 GList *list = NULL; | 638 GList *list = NULL; |
597 gchar *uri_text = NULL; | 639 gchar *uri_text = NULL; |
598 gint total; | 640 gint total; |
599 | 641 |
600 if (!vfi->click_fd) return; | 642 if (!vfi->click_id) return; |
601 | 643 |
602 if (ICON_DATA(vfi->click_fd)->selected & SELECTION_SELECTED) | 644 if (vfi->click_id->selected & SELECTION_SELECTED) |
603 { | 645 { |
604 list = vficon_selection_get_list(vfi); | 646 list = vficon_selection_get_list(vfi); |
605 } | 647 } |
606 else | 648 else |
607 { | 649 { |
608 const gchar *path = vfi->click_fd->path; | 650 list = g_list_append(NULL, file_data_ref(vfi->click_id->fd)); |
609 | |
610 list = g_list_append(NULL, g_strdup(path)); | |
611 } | 651 } |
612 | 652 |
613 if (!list) return; | 653 if (!list) return; |
614 uri_text = uri_text_from_list(list, &total, (info == TARGET_TEXT_PLAIN)); | 654 uri_text = uri_text_from_filelist(list, &total, (info == TARGET_TEXT_PLAIN)); |
615 path_list_free(list); | 655 filelist_free(list); |
616 | 656 |
617 if (debug) printf(uri_text); | 657 if (debug) printf(uri_text); |
618 | 658 |
619 gtk_selection_data_set(selection_data, selection_data->target, | 659 gtk_selection_data_set(selection_data, selection_data->target, |
620 8, (guchar *)uri_text, total); | 660 8, (guchar *)uri_text, total); |
625 { | 665 { |
626 ViewFileIcon *vfi = data; | 666 ViewFileIcon *vfi = data; |
627 | 667 |
628 tip_unschedule(vfi); | 668 tip_unschedule(vfi); |
629 | 669 |
630 if (vfi->click_fd && vfi->click_fd->pixbuf) | 670 if (vfi->click_id && vfi->click_id->fd->pixbuf) |
631 { | 671 { |
632 gint items; | 672 gint items; |
633 | 673 |
634 if (ICON_DATA(vfi->click_fd)->selected & SELECTION_SELECTED) | 674 if (vfi->click_id->selected & SELECTION_SELECTED) |
635 items = g_list_length(vfi->selection); | 675 items = g_list_length(vfi->selection); |
636 else | 676 else |
637 items = 1; | 677 items = 1; |
638 | 678 |
639 dnd_set_drag_icon(widget, context, vfi->click_fd->pixbuf, items); | 679 dnd_set_drag_icon(widget, context, vfi->click_id->fd->pixbuf, items); |
640 } | 680 } |
641 } | 681 } |
642 | 682 |
643 static void vficon_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | 683 static void vficon_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) |
644 { | 684 { |
645 ViewFileIcon *vfi = data; | 685 ViewFileIcon *vfi = data; |
646 | 686 |
647 vficon_selection_remove(vfi, vfi->click_fd, SELECTION_PRELIGHT, NULL); | 687 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); |
648 | 688 |
649 if (context->action == GDK_ACTION_MOVE) | 689 if (context->action == GDK_ACTION_MOVE) |
650 { | 690 { |
651 vficon_refresh(vfi); | 691 vficon_refresh(vfi); |
652 } | 692 } |
671 *------------------------------------------------------------------- | 711 *------------------------------------------------------------------- |
672 * cell updates | 712 * cell updates |
673 *------------------------------------------------------------------- | 713 *------------------------------------------------------------------- |
674 */ | 714 */ |
675 | 715 |
676 static void vficon_selection_set(ViewFileIcon *vfi, FileData *fd, SelectionType value, GtkTreeIter *iter) | 716 static void vficon_selection_set(ViewFileIcon *vfi, IconData *id, SelectionType value, GtkTreeIter *iter) |
677 { | 717 { |
678 IconData *id; | |
679 GtkTreeModel *store; | 718 GtkTreeModel *store; |
680 GList *list; | 719 GList *list; |
681 | 720 |
682 if (!fd) return; | 721 if (!id) return; |
683 | 722 |
684 id = ICON_DATA(fd); | |
685 | 723 |
686 if (id->selected == value) return; | 724 if (id->selected == value) return; |
687 id->selected = value; | 725 id->selected = value; |
688 | 726 |
689 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | 727 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); |
694 } | 732 } |
695 else | 733 else |
696 { | 734 { |
697 GtkTreeIter row; | 735 GtkTreeIter row; |
698 | 736 |
699 if (vficon_find_iter(vfi, fd, &row, NULL)) | 737 if (vficon_find_iter(vfi, id, &row, NULL)) |
700 { | 738 { |
701 gtk_tree_model_get(store, &row, FILE_COLUMN_POINTER, &list, -1); | 739 gtk_tree_model_get(store, &row, FILE_COLUMN_POINTER, &list, -1); |
702 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, FILE_COLUMN_POINTER, list, -1); | 740 if (list) gtk_list_store_set(GTK_LIST_STORE(store), &row, FILE_COLUMN_POINTER, list, -1); |
703 } | 741 } |
704 } | 742 } |
705 } | 743 } |
706 | 744 |
707 static void vficon_selection_add(ViewFileIcon *vfi, FileData *fd, SelectionType mask, GtkTreeIter *iter) | 745 static void vficon_selection_add(ViewFileIcon *vfi, IconData *id, SelectionType mask, GtkTreeIter *iter) |
708 { | 746 { |
709 if (!fd) return; | 747 if (!id) return; |
710 | 748 |
711 vficon_selection_set(vfi, fd, ICON_DATA(fd)->selected | mask, iter); | 749 vficon_selection_set(vfi, id, id->selected | mask, iter); |
712 } | 750 } |
713 | 751 |
714 static void vficon_selection_remove(ViewFileIcon *vfi, FileData *fd, SelectionType mask, GtkTreeIter *iter) | 752 static void vficon_selection_remove(ViewFileIcon *vfi, IconData *id, SelectionType mask, GtkTreeIter *iter) |
715 { | 753 { |
716 if (!fd) return; | 754 if (!id) return; |
717 | 755 |
718 vficon_selection_set(vfi, fd, ICON_DATA(fd)->selected & ~mask, iter); | 756 vficon_selection_set(vfi, id, id->selected & ~mask, iter); |
719 } | 757 } |
720 | 758 |
721 /* | 759 /* |
722 *------------------------------------------------------------------- | 760 *------------------------------------------------------------------- |
723 * selections | 761 * selections |
729 GList *work; | 767 GList *work; |
730 | 768 |
731 work = vfi->selection; | 769 work = vfi->selection; |
732 while (work) | 770 while (work) |
733 { | 771 { |
734 FileData *fd = work->data; | 772 IconData *id = work->data; |
735 work = work->next; | 773 work = work->next; |
736 if (!g_list_find(vfi->list, fd)) | 774 if (vficon_index_by_id(vfi, id) < 0) |
737 { | 775 { |
738 vfi->selection = g_list_remove(vfi->selection, fd); | 776 vfi->selection = g_list_remove(vfi->selection, id); |
739 } | 777 } |
740 } | 778 } |
741 } | 779 } |
742 | 780 |
743 void vficon_select_all(ViewFileIcon *vfi) | 781 void vficon_select_all(ViewFileIcon *vfi) |
748 vfi->selection = NULL; | 786 vfi->selection = NULL; |
749 | 787 |
750 work = vfi->list; | 788 work = vfi->list; |
751 while (work) | 789 while (work) |
752 { | 790 { |
753 vfi->selection = g_list_append(vfi->selection, work->data); | 791 IconData *id = work->data; |
792 vfi->selection = g_list_append(vfi->selection, id); | |
754 vficon_selection_add(vfi, work->data, SELECTION_SELECTED, NULL); | 793 vficon_selection_add(vfi, work->data, SELECTION_SELECTED, NULL); |
755 work = work->next; | 794 work = work->next; |
756 } | 795 } |
757 | 796 |
758 vficon_send_update(vfi); | 797 vficon_send_update(vfi); |
773 vfi->selection = NULL; | 812 vfi->selection = NULL; |
774 | 813 |
775 vficon_send_update(vfi); | 814 vficon_send_update(vfi); |
776 } | 815 } |
777 | 816 |
778 static void vficon_select(ViewFileIcon *vfi, FileData *fd) | 817 static void vficon_select(ViewFileIcon *vfi, IconData *id) |
779 { | 818 { |
780 vfi->prev_selection = fd; | 819 vfi->prev_selection = id; |
781 | 820 |
782 if (!fd || ICON_DATA(fd)->selected & SELECTION_SELECTED) return; | 821 if (!id || id->selected & SELECTION_SELECTED) return; |
783 | 822 |
784 vfi->selection = g_list_append(vfi->selection, fd); | 823 vfi->selection = g_list_append(vfi->selection, id); |
785 vficon_selection_add(vfi, fd, SELECTION_SELECTED, NULL); | 824 vficon_selection_add(vfi, id, SELECTION_SELECTED, NULL); |
786 | 825 |
787 vficon_send_update(vfi); | 826 vficon_send_update(vfi); |
788 } | 827 } |
789 | 828 |
790 static void vficon_unselect(ViewFileIcon *vfi, FileData *fd) | 829 static void vficon_unselect(ViewFileIcon *vfi, IconData *id) |
791 { | 830 { |
792 vfi->prev_selection = fd; | 831 vfi->prev_selection = id; |
793 | 832 |
794 if (!fd || !(ICON_DATA(fd)->selected & SELECTION_SELECTED) ) return; | 833 if (!id || !(id->selected & SELECTION_SELECTED) ) return; |
795 | 834 |
796 vfi->selection = g_list_remove(vfi->selection, fd); | 835 vfi->selection = g_list_remove(vfi->selection, id); |
797 vficon_selection_remove(vfi, fd, SELECTION_SELECTED, NULL); | 836 vficon_selection_remove(vfi, id, SELECTION_SELECTED, NULL); |
798 | 837 |
799 vficon_send_update(vfi); | 838 vficon_send_update(vfi); |
800 } | 839 } |
801 | 840 |
802 static void vficon_select_util(ViewFileIcon *vfi, FileData *fd, gint select) | 841 static void vficon_select_util(ViewFileIcon *vfi, IconData *id, gint select) |
803 { | 842 { |
804 if (select) | 843 if (select) |
805 { | 844 { |
806 vficon_select(vfi, fd); | 845 vficon_select(vfi, id); |
807 } | 846 } |
808 else | 847 else |
809 { | 848 { |
810 vficon_unselect(vfi, fd); | 849 vficon_unselect(vfi, id); |
811 } | 850 } |
812 } | 851 } |
813 | 852 |
814 static void vficon_select_region_util(ViewFileIcon *vfi, FileData *start, FileData *end, gint select) | 853 static void vficon_select_region_util(ViewFileIcon *vfi, IconData *start, IconData *end, gint select) |
815 { | 854 { |
816 gint row1, col1; | 855 gint row1, col1; |
817 gint row2, col2; | 856 gint row2, col2; |
818 gint t; | 857 gint t; |
819 gint i, j; | 858 gint i, j; |
824 vfi->prev_selection = end; | 863 vfi->prev_selection = end; |
825 | 864 |
826 if (!collection_rectangular_selection) | 865 if (!collection_rectangular_selection) |
827 { | 866 { |
828 GList *work; | 867 GList *work; |
829 FileData *fd; | 868 IconData *id; |
830 | 869 |
831 if (g_list_index(vfi->list, start) > g_list_index(vfi->list, end)) | 870 if (g_list_index(vfi->list, start) > g_list_index(vfi->list, end)) |
832 { | 871 { |
833 fd = start; | 872 id = start; |
834 start = end; | 873 start = end; |
835 end = fd; | 874 end = id; |
836 } | 875 } |
837 | 876 |
838 work = g_list_find(vfi->list, start); | 877 work = g_list_find(vfi->list, start); |
839 while (work) | 878 while (work) |
840 { | 879 { |
841 fd = work->data; | 880 id = work->data; |
842 vficon_select_util(vfi, fd, select); | 881 vficon_select_util(vfi, id, select); |
843 | 882 |
844 if (work->data != end) | 883 if (work->data != end) |
845 work = work->next; | 884 work = work->next; |
846 else | 885 else |
847 work = NULL; | 886 work = NULL; |
866 | 905 |
867 for (i = row1; i <= row2; i++) | 906 for (i = row1; i <= row2; i++) |
868 { | 907 { |
869 for (j = col1; j <= col2; j++) | 908 for (j = col1; j <= col2; j++) |
870 { | 909 { |
871 FileData *fd = vficon_find_data(vfi, i, j, NULL); | 910 IconData *id = vficon_find_data(vfi, i, j, NULL); |
872 if (fd) vficon_select_util(vfi, fd, select); | 911 if (id) vficon_select_util(vfi, id, select); |
873 } | 912 } |
874 } | 913 } |
875 } | 914 } |
876 | 915 |
877 gint vficon_index_is_selected(ViewFileIcon *vfi, gint row) | 916 gint vficon_index_is_selected(ViewFileIcon *vfi, gint row) |
878 { | 917 { |
879 FileData *fd = g_list_nth_data(vfi->list, row); | 918 IconData *id = g_list_nth_data(vfi->list, row); |
880 | 919 |
881 if (!fd) return FALSE; | 920 if (!id) return FALSE; |
882 | 921 |
883 return (ICON_DATA(fd)->selected & SELECTION_SELECTED); | 922 return (id->selected & SELECTION_SELECTED); |
884 } | 923 } |
885 | 924 |
886 gint vficon_selection_count(ViewFileIcon *vfi, gint64 *bytes) | 925 gint vficon_selection_count(ViewFileIcon *vfi, gint64 *bytes) |
887 { | 926 { |
888 if (bytes) | 927 if (bytes) |
891 GList *work; | 930 GList *work; |
892 | 931 |
893 work = vfi->selection; | 932 work = vfi->selection; |
894 while (work) | 933 while (work) |
895 { | 934 { |
896 FileData *fd = work->data; | 935 IconData *id = work->data; |
936 FileData *fd = id->fd; | |
937 g_assert(fd->magick == 0x12345678); | |
897 b += fd->size; | 938 b += fd->size; |
898 | 939 |
899 work = work->next; | 940 work = work->next; |
900 } | 941 } |
901 | 942 |
911 GList *work; | 952 GList *work; |
912 | 953 |
913 work = vfi->selection; | 954 work = vfi->selection; |
914 while (work) | 955 while (work) |
915 { | 956 { |
916 FileData *fd = work->data; | 957 IconData *id = work->data; |
917 | 958 FileData *fd = id->fd; |
918 list = g_list_prepend(list, g_strdup(fd->path)); | 959 g_assert(fd->magick == 0x12345678); |
960 | |
961 list = g_list_prepend(list, file_data_ref(fd)); | |
919 | 962 |
920 work = work->next; | 963 work = work->next; |
921 } | 964 } |
922 | 965 |
923 list = g_list_reverse(list); | 966 list = g_list_reverse(list); |
938 } | 981 } |
939 | 982 |
940 return g_list_reverse(list); | 983 return g_list_reverse(list); |
941 } | 984 } |
942 | 985 |
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 | |
943 void vficon_select_by_path(ViewFileIcon *vfi, const gchar *path) | 1000 void vficon_select_by_path(ViewFileIcon *vfi, const gchar *path) |
944 { | 1001 { |
945 FileData *fd; | 1002 IconData *id = NULL; |
946 GList *work; | 1003 GList *work; |
947 | 1004 |
948 if (!path) return; | 1005 if (!path) return; |
949 | 1006 |
950 fd = NULL; | |
951 work = vfi->list; | 1007 work = vfi->list; |
952 while (work && !fd) | 1008 while (work && !id) |
953 { | 1009 { |
954 FileData *chk = work->data; | 1010 IconData *chk = work->data; |
955 work = work->next; | 1011 work = work->next; |
956 if (strcmp(chk->path, path) == 0) fd = chk; | 1012 if (strcmp(chk->fd->path, path) == 0) id = chk; |
957 } | 1013 } |
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; | |
958 | 1021 |
959 if (!fd) return; | 1022 if (!fd) return; |
960 | 1023 work = vfi->list; |
961 if (!(ICON_DATA(fd)->selected & SELECTION_SELECTED)) | 1024 while (work && !id) |
962 { | 1025 { |
963 vficon_select_none(vfi); | 1026 IconData *chk = work->data; |
964 vficon_select(vfi, fd); | 1027 work = work->next; |
965 } | 1028 if (chk->fd == fd) id = chk; |
966 | 1029 } |
967 vficon_set_focus(vfi, fd); | 1030 vficon_select_by_id(vfi, id); |
968 } | 1031 } |
1032 | |
1033 | |
969 | 1034 |
970 /* | 1035 /* |
971 *------------------------------------------------------------------- | 1036 *------------------------------------------------------------------- |
972 * focus | 1037 * focus |
973 *------------------------------------------------------------------- | 1038 *------------------------------------------------------------------- |
1054 } | 1119 } |
1055 | 1120 |
1056 vficon_set_focus(vfi, vficon_find_data(vfi, new_row, new_col, NULL)); | 1121 vficon_set_focus(vfi, vficon_find_data(vfi, new_row, new_col, NULL)); |
1057 } | 1122 } |
1058 | 1123 |
1059 static void vficon_set_focus(ViewFileIcon *vfi, FileData *fd) | 1124 static void vficon_set_focus(ViewFileIcon *vfi, IconData *id) |
1060 { | 1125 { |
1061 GtkTreeIter iter; | 1126 GtkTreeIter iter; |
1062 gint row, col; | 1127 gint row, col; |
1063 | 1128 |
1064 if (g_list_find(vfi->list, vfi->focus_fd)) | 1129 if (g_list_find(vfi->list, vfi->focus_id)) |
1065 { | 1130 { |
1066 if (fd == vfi->focus_fd) | 1131 if (id == vfi->focus_id) |
1067 { | 1132 { |
1068 /* ensure focus row col are correct */ | 1133 /* ensure focus row col are correct */ |
1069 vficon_find_position(vfi, vfi->focus_fd, &vfi->focus_row, &vfi->focus_column); | 1134 vficon_find_position(vfi, vfi->focus_id, &vfi->focus_row, &vfi->focus_column); |
1070 return; | 1135 return; |
1071 } | 1136 } |
1072 vficon_selection_remove(vfi, vfi->focus_fd, SELECTION_FOCUS, NULL); | 1137 vficon_selection_remove(vfi, vfi->focus_id, SELECTION_FOCUS, NULL); |
1073 } | 1138 } |
1074 | 1139 |
1075 if (!vficon_find_position(vfi, fd, &row, &col)) | 1140 if (!vficon_find_position(vfi, id, &row, &col)) |
1076 { | 1141 { |
1077 vfi->focus_fd = NULL; | 1142 vfi->focus_id = NULL; |
1078 vfi->focus_row = -1; | 1143 vfi->focus_row = -1; |
1079 vfi->focus_column = -1; | 1144 vfi->focus_column = -1; |
1080 return; | 1145 return; |
1081 } | 1146 } |
1082 | 1147 |
1083 vfi->focus_fd = fd; | 1148 vfi->focus_id = id; |
1084 vfi->focus_row = row; | 1149 vfi->focus_row = row; |
1085 vfi->focus_column = col; | 1150 vfi->focus_column = col; |
1086 vficon_selection_add(vfi, vfi->focus_fd, SELECTION_FOCUS, NULL); | 1151 vficon_selection_add(vfi, vfi->focus_id, SELECTION_FOCUS, NULL); |
1087 | 1152 |
1088 if (vficon_find_iter(vfi, vfi->focus_fd, &iter, NULL)) | 1153 if (vficon_find_iter(vfi, vfi->focus_id, &iter, NULL)) |
1089 { | 1154 { |
1090 GtkTreePath *tpath; | 1155 GtkTreePath *tpath; |
1091 GtkTreeViewColumn *column; | 1156 GtkTreeViewColumn *column; |
1092 GtkTreeModel *store; | 1157 GtkTreeModel *store; |
1093 | 1158 |
1105 static void vficon_update_focus(ViewFileIcon *vfi) | 1170 static void vficon_update_focus(ViewFileIcon *vfi) |
1106 { | 1171 { |
1107 gint new_row = 0; | 1172 gint new_row = 0; |
1108 gint new_col = 0; | 1173 gint new_col = 0; |
1109 | 1174 |
1110 if (vfi->focus_fd && vficon_find_position(vfi, vfi->focus_fd, &new_row, &new_col)) | 1175 if (vfi->focus_id && vficon_find_position(vfi, vfi->focus_id, &new_row, &new_col)) |
1111 { | 1176 { |
1112 /* first find the old focus, if it exists and is valid */ | 1177 /* first find the old focus, if it exists and is valid */ |
1113 } | 1178 } |
1114 else | 1179 else |
1115 { | 1180 { |
1154 GtkTreeIter iter; | 1219 GtkTreeIter iter; |
1155 gint column; | 1220 gint column; |
1156 GtkTreePath *tpath; | 1221 GtkTreePath *tpath; |
1157 gint cw, ch; | 1222 gint cw, ch; |
1158 | 1223 |
1159 if (!vficon_find_iter(vfi, vfi->click_fd, &iter, &column)) return; | 1224 if (!vficon_find_iter(vfi, vfi->click_id, &iter, &column)) return; |
1160 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | 1225 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); |
1161 tpath = gtk_tree_model_get_path(store, &iter); | 1226 tpath = gtk_tree_model_get_path(store, &iter); |
1162 tree_view_get_cell_clamped(GTK_TREE_VIEW(vfi->listview), tpath, column, FALSE, x, y, &cw, &ch); | 1227 tree_view_get_cell_clamped(GTK_TREE_VIEW(vfi->listview), tpath, column, FALSE, x, y, &cw, &ch); |
1163 gtk_tree_path_free(tpath); | 1228 gtk_tree_path_free(tpath); |
1164 *y += ch; | 1229 *y += ch; |
1168 static gint vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | 1233 static gint vficon_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
1169 { | 1234 { |
1170 ViewFileIcon *vfi = data; | 1235 ViewFileIcon *vfi = data; |
1171 gint focus_row = 0; | 1236 gint focus_row = 0; |
1172 gint focus_col = 0; | 1237 gint focus_col = 0; |
1173 FileData *fd; | 1238 IconData *id; |
1174 gint stop_signal; | 1239 gint stop_signal; |
1175 | 1240 |
1176 stop_signal = TRUE; | 1241 stop_signal = TRUE; |
1177 switch (event->keyval) | 1242 switch (event->keyval) |
1178 { | 1243 { |
1201 case GDK_End: case GDK_KP_End: | 1266 case GDK_End: case GDK_KP_End: |
1202 focus_row = vfi->rows - 1 - vfi->focus_row; | 1267 focus_row = vfi->rows - 1 - vfi->focus_row; |
1203 focus_col = vfi->columns - 1 - vfi->focus_column; | 1268 focus_col = vfi->columns - 1 - vfi->focus_column; |
1204 break; | 1269 break; |
1205 case GDK_space: | 1270 case GDK_space: |
1206 fd = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); | 1271 id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); |
1207 if (fd) | 1272 if (id) |
1208 { | 1273 { |
1209 vfi->click_fd = fd; | 1274 vfi->click_id = id; |
1210 if (event->state & GDK_CONTROL_MASK) | 1275 if (event->state & GDK_CONTROL_MASK) |
1211 { | 1276 { |
1212 gint selected; | 1277 gint selected; |
1213 | 1278 |
1214 selected = ICON_DATA(fd)->selected & SELECTION_SELECTED; | 1279 selected = id->selected & SELECTION_SELECTED; |
1215 if (selected) | 1280 if (selected) |
1216 { | 1281 { |
1217 vficon_unselect(vfi, fd); | 1282 vficon_unselect(vfi, id); |
1218 } | 1283 } |
1219 else | 1284 else |
1220 { | 1285 { |
1221 vficon_select(vfi, fd); | 1286 vficon_select(vfi, id); |
1222 vficon_send_layout_select(vfi, fd); | 1287 vficon_send_layout_select(vfi, id); |
1223 } | 1288 } |
1224 } | 1289 } |
1225 else | 1290 else |
1226 { | 1291 { |
1227 vficon_select_none(vfi); | 1292 vficon_select_none(vfi); |
1228 vficon_select(vfi, fd); | 1293 vficon_select(vfi, id); |
1229 vficon_send_layout_select(vfi, fd); | 1294 vficon_send_layout_select(vfi, id); |
1230 } | 1295 } |
1231 } | 1296 } |
1232 break; | 1297 break; |
1233 case GDK_Menu: | 1298 case GDK_Menu: |
1234 fd = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); | 1299 id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); |
1235 vfi->click_fd = fd; | 1300 vfi->click_id = id; |
1236 | 1301 |
1237 vficon_selection_add(vfi, vfi->click_fd, SELECTION_PRELIGHT, NULL); | 1302 vficon_selection_add(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); |
1238 tip_unschedule(vfi); | 1303 tip_unschedule(vfi); |
1239 | 1304 |
1240 vfi->popup = vficon_pop_menu(vfi, (fd != NULL)); | 1305 vfi->popup = vficon_pop_menu(vfi, (id != NULL)); |
1241 gtk_menu_popup(GTK_MENU(vfi->popup), NULL, NULL, vfi_menu_position_cb, vfi, 0, GDK_CURRENT_TIME); | 1306 gtk_menu_popup(GTK_MENU(vfi->popup), NULL, NULL, vfi_menu_position_cb, vfi, 0, GDK_CURRENT_TIME); |
1242 break; | 1307 break; |
1243 default: | 1308 default: |
1244 stop_signal = FALSE; | 1309 stop_signal = FALSE; |
1245 break; | 1310 break; |
1246 } | 1311 } |
1247 | 1312 |
1248 if (focus_row != 0 || focus_col != 0) | 1313 if (focus_row != 0 || focus_col != 0) |
1249 { | 1314 { |
1250 FileData *new_fd; | 1315 IconData *new_id; |
1251 FileData *old_fd; | 1316 IconData *old_id; |
1252 | 1317 |
1253 old_fd = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); | 1318 old_id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); |
1254 vficon_move_focus(vfi, focus_row, focus_col, TRUE); | 1319 vficon_move_focus(vfi, focus_row, focus_col, TRUE); |
1255 new_fd = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); | 1320 new_id = vficon_find_data(vfi, vfi->focus_row, vfi->focus_column, NULL); |
1256 | 1321 |
1257 if (new_fd != old_fd) | 1322 if (new_id != old_id) |
1258 { | 1323 { |
1259 if (event->state & GDK_SHIFT_MASK) | 1324 if (event->state & GDK_SHIFT_MASK) |
1260 { | 1325 { |
1261 if (!collection_rectangular_selection) | 1326 if (!collection_rectangular_selection) |
1262 { | 1327 { |
1263 vficon_select_region_util(vfi, old_fd, new_fd, FALSE); | 1328 vficon_select_region_util(vfi, old_id, new_id, FALSE); |
1264 } | 1329 } |
1265 else | 1330 else |
1266 { | 1331 { |
1267 vficon_select_region_util(vfi, vfi->click_fd, old_fd, FALSE); | 1332 vficon_select_region_util(vfi, vfi->click_id, old_id, FALSE); |
1268 } | 1333 } |
1269 vficon_select_region_util(vfi, vfi->click_fd, new_fd, TRUE); | 1334 vficon_select_region_util(vfi, vfi->click_id, new_id, TRUE); |
1270 vficon_send_layout_select(vfi, new_fd); | 1335 vficon_send_layout_select(vfi, new_id); |
1271 } | 1336 } |
1272 else if (event->state & GDK_CONTROL_MASK) | 1337 else if (event->state & GDK_CONTROL_MASK) |
1273 { | 1338 { |
1274 vfi->click_fd = new_fd; | 1339 vfi->click_id = new_id; |
1275 } | 1340 } |
1276 else | 1341 else |
1277 { | 1342 { |
1278 vfi->click_fd = new_fd; | 1343 vfi->click_id = new_id; |
1279 vficon_select_none(vfi); | 1344 vficon_select_none(vfi); |
1280 vficon_select(vfi, new_fd); | 1345 vficon_select(vfi, new_id); |
1281 vficon_send_layout_select(vfi, new_fd); | 1346 vficon_send_layout_select(vfi, new_id); |
1282 } | 1347 } |
1283 } | 1348 } |
1284 } | 1349 } |
1285 | 1350 |
1286 if (stop_signal) | 1351 if (stop_signal) |
1301 */ | 1366 */ |
1302 | 1367 |
1303 static gint vficon_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | 1368 static gint vficon_motion_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
1304 { | 1369 { |
1305 ViewFileIcon *vfi = data; | 1370 ViewFileIcon *vfi = data; |
1306 FileData *fd; | 1371 IconData *id; |
1307 | 1372 |
1308 fd = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, NULL); | 1373 id = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, NULL); |
1309 tip_update(vfi, fd); | 1374 tip_update(vfi, id); |
1310 | 1375 |
1311 return FALSE; | 1376 return FALSE; |
1312 } | 1377 } |
1313 | 1378 |
1314 static gint vficon_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | 1379 static gint vficon_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
1315 { | 1380 { |
1316 ViewFileIcon *vfi = data; | 1381 ViewFileIcon *vfi = data; |
1317 GtkTreeIter iter; | 1382 GtkTreeIter iter; |
1318 FileData *fd; | 1383 IconData *id; |
1319 | 1384 |
1320 tip_unschedule(vfi); | 1385 tip_unschedule(vfi); |
1321 | 1386 |
1322 fd = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, &iter); | 1387 id = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, &iter); |
1323 | 1388 |
1324 vfi->click_fd = fd; | 1389 vfi->click_id = id; |
1325 vficon_selection_add(vfi, vfi->click_fd, SELECTION_PRELIGHT, &iter); | 1390 vficon_selection_add(vfi, vfi->click_id, SELECTION_PRELIGHT, &iter); |
1326 | 1391 |
1327 switch (bevent->button) | 1392 switch (bevent->button) |
1328 { | 1393 { |
1329 case 1: | 1394 case 1: |
1330 if (!GTK_WIDGET_HAS_FOCUS(vfi->listview)) | 1395 if (!GTK_WIDGET_HAS_FOCUS(vfi->listview)) |
1333 } | 1398 } |
1334 #if 0 | 1399 #if 0 |
1335 if (bevent->type == GDK_2BUTTON_PRESS && | 1400 if (bevent->type == GDK_2BUTTON_PRESS && |
1336 vfi->layout) | 1401 vfi->layout) |
1337 { | 1402 { |
1338 vficon_selection_remove(vfi, vfi->click_fd, SELECTION_PRELIGHT, &iter); | 1403 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, &iter); |
1339 layout_image_full_screen_start(vfi->layout); | 1404 layout_image_full_screen_start(vfi->layout); |
1340 } | 1405 } |
1341 #endif | 1406 #endif |
1342 break; | 1407 break; |
1343 case 3: | 1408 case 3: |
1344 vfi->popup = vficon_pop_menu(vfi, (fd != NULL)); | 1409 vfi->popup = vficon_pop_menu(vfi, (id != NULL)); |
1345 gtk_menu_popup(GTK_MENU(vfi->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time); | 1410 gtk_menu_popup(GTK_MENU(vfi->popup), NULL, NULL, NULL, NULL, bevent->button, bevent->time); |
1346 break; | 1411 break; |
1347 default: | 1412 default: |
1348 break; | 1413 break; |
1349 } | 1414 } |
1353 | 1418 |
1354 static gint vficon_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | 1419 static gint vficon_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
1355 { | 1420 { |
1356 ViewFileIcon *vfi = data; | 1421 ViewFileIcon *vfi = data; |
1357 GtkTreeIter iter; | 1422 GtkTreeIter iter; |
1358 FileData *fd = NULL; | 1423 IconData *id = NULL; |
1359 gint was_selected = FALSE; | 1424 gint was_selected = FALSE; |
1360 | 1425 |
1361 tip_schedule(vfi); | 1426 tip_schedule(vfi); |
1362 | 1427 |
1363 if ((gint)bevent->x != 0 || (gint) bevent->y != 0) | 1428 if ((gint)bevent->x != 0 || (gint) bevent->y != 0) |
1364 { | 1429 { |
1365 fd = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, &iter); | 1430 id = vficon_find_data_by_coord(vfi, (gint)bevent->x, (gint)bevent->y, &iter); |
1366 } | 1431 } |
1367 | 1432 |
1368 if (vfi->click_fd) | 1433 if (vfi->click_id) |
1369 { | 1434 { |
1370 vficon_selection_remove(vfi, vfi->click_fd, SELECTION_PRELIGHT, NULL); | 1435 vficon_selection_remove(vfi, vfi->click_id, SELECTION_PRELIGHT, NULL); |
1371 } | 1436 } |
1372 | 1437 |
1373 if (fd) was_selected = (ICON_DATA(fd)->selected & SELECTION_SELECTED); | 1438 if (id) was_selected = (id->selected & SELECTION_SELECTED); |
1374 | 1439 |
1375 if (bevent->button == 1 && | 1440 if (bevent->button == 1 && |
1376 fd && vfi->click_fd == fd) | 1441 id && vfi->click_id == id) |
1377 { | 1442 { |
1378 vficon_set_focus(vfi, fd); | 1443 vficon_set_focus(vfi, id); |
1379 | 1444 |
1380 if (bevent->state & GDK_CONTROL_MASK) | 1445 if (bevent->state & GDK_CONTROL_MASK) |
1381 { | 1446 { |
1382 gint select; | 1447 gint select; |
1383 | 1448 |
1384 select = !(ICON_DATA(fd)->selected & SELECTION_SELECTED); | 1449 select = !(id->selected & SELECTION_SELECTED); |
1385 if ((bevent->state & GDK_SHIFT_MASK) && vfi->prev_selection) | 1450 if ((bevent->state & GDK_SHIFT_MASK) && vfi->prev_selection) |
1386 { | 1451 { |
1387 vficon_select_region_util(vfi, vfi->prev_selection, fd, select); | 1452 vficon_select_region_util(vfi, vfi->prev_selection, id, select); |
1388 } | 1453 } |
1389 else | 1454 else |
1390 { | 1455 { |
1391 vficon_select_util(vfi, fd, select); | 1456 vficon_select_util(vfi, id, select); |
1392 } | 1457 } |
1393 } | 1458 } |
1394 else | 1459 else |
1395 { | 1460 { |
1396 vficon_select_none(vfi); | 1461 vficon_select_none(vfi); |
1397 | 1462 |
1398 if ((bevent->state & GDK_SHIFT_MASK) && | 1463 if ((bevent->state & GDK_SHIFT_MASK) && |
1399 vfi->prev_selection) | 1464 vfi->prev_selection) |
1400 { | 1465 { |
1401 vficon_select_region_util(vfi, vfi->prev_selection, fd, TRUE); | 1466 vficon_select_region_util(vfi, vfi->prev_selection, id, TRUE); |
1402 } | 1467 } |
1403 else | 1468 else |
1404 { | 1469 { |
1405 vficon_select_util(vfi, fd, TRUE); | 1470 vficon_select_util(vfi, id, TRUE); |
1406 was_selected = FALSE; | 1471 was_selected = FALSE; |
1407 } | 1472 } |
1408 } | 1473 } |
1409 } | 1474 } |
1410 else if (bevent->button == 2 && | 1475 else if (bevent->button == 2 && |
1411 fd && vfi->click_fd == fd) | 1476 id && vfi->click_id == id) |
1412 { | 1477 { |
1413 vficon_select_util(vfi, fd, !(ICON_DATA(fd)->selected & SELECTION_SELECTED)); | 1478 vficon_select_util(vfi, id, !(id->selected & SELECTION_SELECTED)); |
1414 } | 1479 } |
1415 | 1480 |
1416 if (fd && !was_selected && | 1481 if (id && !was_selected && |
1417 (ICON_DATA(fd)->selected & SELECTION_SELECTED)) | 1482 (id->selected & SELECTION_SELECTED)) |
1418 { | 1483 { |
1419 vficon_send_layout_select(vfi, fd); | 1484 vficon_send_layout_select(vfi, id); |
1420 } | 1485 } |
1421 | 1486 |
1422 return TRUE; | 1487 return TRUE; |
1423 } | 1488 } |
1424 | 1489 |
1460 { | 1525 { |
1461 GtkTreeModel *store; | 1526 GtkTreeModel *store; |
1462 GtkTreeIter iter; | 1527 GtkTreeIter iter; |
1463 GList *list; | 1528 GList *list; |
1464 | 1529 |
1465 if (!vficon_find_iter(vfi, fd, &iter, NULL)) return; | 1530 if (!vficon_find_iter(vfi, vficon_icon_data(vfi, fd), &iter, NULL)) return; |
1466 | 1531 |
1467 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | 1532 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); |
1468 | 1533 |
1469 if (pb) g_object_ref(pb); | 1534 if (pb) g_object_ref(pb); |
1470 if (fd->pixbuf) g_object_unref(fd->pixbuf); | 1535 if (fd->pixbuf) g_object_unref(fd->pixbuf); |
1493 { | 1558 { |
1494 GtkTreeModel *store; | 1559 GtkTreeModel *store; |
1495 GtkTreePath *tpath; | 1560 GtkTreePath *tpath; |
1496 gint row; | 1561 gint row; |
1497 GList *work; | 1562 GList *work; |
1498 FileData *visible_fd = NULL; | 1563 IconData *visible_id = NULL; |
1499 | 1564 |
1500 vficon_verify_selections(vfi); | 1565 vficon_verify_selections(vfi); |
1501 | 1566 |
1502 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | 1567 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); |
1503 | 1568 |
1509 | 1574 |
1510 gtk_tree_model_get_iter(store, &iter, tpath); | 1575 gtk_tree_model_get_iter(store, &iter, tpath); |
1511 gtk_tree_path_free(tpath); | 1576 gtk_tree_path_free(tpath); |
1512 | 1577 |
1513 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | 1578 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); |
1514 if (list) visible_fd = list->data; | 1579 if (list) visible_id = list->data; |
1515 } | 1580 } |
1516 | 1581 |
1517 vficon_clear_store(vfi); | 1582 vficon_clear_store(vfi); |
1518 | 1583 |
1519 if (resize) | 1584 if (resize) |
1557 row++; | 1622 row++; |
1558 | 1623 |
1559 list = vficon_add_row(vfi, &iter); | 1624 list = vficon_add_row(vfi, &iter); |
1560 while (work && list) | 1625 while (work && list) |
1561 { | 1626 { |
1562 FileData *fd; | 1627 IconData *id; |
1563 | 1628 |
1564 fd = work->data; | 1629 id = work->data; |
1565 ICON_DATA(fd)->row = row; | 1630 id->row = row; |
1566 | 1631 |
1567 list->data = work->data; | 1632 list->data = work->data; |
1568 list = list->next; | 1633 list = list->next; |
1569 work = work->next; | 1634 work = work->next; |
1570 } | 1635 } |
1571 } | 1636 } |
1572 | 1637 |
1573 if (visible_fd && | 1638 if (visible_id && |
1574 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), 0, 0, &tpath, NULL, NULL, NULL)) | 1639 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vfi->listview), 0, 0, &tpath, NULL, NULL, NULL)) |
1575 { | 1640 { |
1576 GtkTreeIter iter; | 1641 GtkTreeIter iter; |
1577 GList *list; | 1642 GList *list; |
1578 | 1643 |
1579 gtk_tree_model_get_iter(store, &iter, tpath); | 1644 gtk_tree_model_get_iter(store, &iter, tpath); |
1580 gtk_tree_path_free(tpath); | 1645 gtk_tree_path_free(tpath); |
1581 | 1646 |
1582 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | 1647 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); |
1583 if (g_list_find(list, visible_fd) == NULL && | 1648 if (g_list_find(list, visible_id) == NULL && |
1584 vficon_find_iter(vfi, visible_fd, &iter, NULL)) | 1649 vficon_find_iter(vfi, visible_id, &iter, NULL)) |
1585 { | 1650 { |
1586 tree_view_row_make_visible(GTK_TREE_VIEW(vfi->listview), &iter, FALSE); | 1651 tree_view_row_make_visible(GTK_TREE_VIEW(vfi->listview), &iter, FALSE); |
1587 } | 1652 } |
1588 } | 1653 } |
1589 | 1654 |
1642 list = vficon_add_row(vfi, &iter); | 1707 list = vficon_add_row(vfi, &iter); |
1643 } | 1708 } |
1644 | 1709 |
1645 while (list) | 1710 while (list) |
1646 { | 1711 { |
1647 FileData *fd; | 1712 IconData *id; |
1648 | 1713 |
1649 if (work) | 1714 if (work) |
1650 { | 1715 { |
1651 fd = work->data; | 1716 id = work->data; |
1652 work = work->next; | 1717 work = work->next; |
1653 c++; | 1718 c++; |
1654 | 1719 |
1655 ICON_DATA(fd)->row = r; | 1720 id->row = r; |
1656 } | 1721 } |
1657 else | 1722 else |
1658 { | 1723 { |
1659 fd = NULL; | 1724 id = NULL; |
1660 } | 1725 } |
1661 | 1726 |
1662 list->data = fd; | 1727 list->data = id; |
1663 list = list->next; | 1728 list = list->next; |
1664 } | 1729 } |
1665 } | 1730 } |
1666 | 1731 |
1667 r++; | 1732 r++; |
1721 vfi->sort_method = type; | 1786 vfi->sort_method = type; |
1722 vfi->sort_ascend = ascend; | 1787 vfi->sort_ascend = ascend; |
1723 | 1788 |
1724 if (!vfi->list) return; | 1789 if (!vfi->list) return; |
1725 | 1790 |
1726 vfi->list = filelist_sort(vfi->list, vfi->sort_method, vfi->sort_ascend); | 1791 vfi->list = iconlist_sort(vfi->list, vfi->sort_method, vfi->sort_ascend); |
1727 vficon_sync(vfi); | 1792 vficon_sync(vfi); |
1728 } | 1793 } |
1729 | 1794 |
1730 /* | 1795 /* |
1731 *----------------------------------------------------------------------------- | 1796 *----------------------------------------------------------------------------- |
1827 | 1892 |
1828 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | 1893 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); |
1829 | 1894 |
1830 while (!fd && list) | 1895 while (!fd && list) |
1831 { | 1896 { |
1832 FileData *tfd = list->data; | 1897 IconData *id = list->data; |
1833 if (tfd && !tfd->pixbuf) fd = tfd; | 1898 if (id && !id->fd->pixbuf) fd = id->fd; |
1834 list = list->next; | 1899 list = list->next; |
1835 } | 1900 } |
1836 | 1901 |
1837 valid = gtk_tree_model_iter_next(store, &iter); | 1902 valid = gtk_tree_model_iter_next(store, &iter); |
1838 } | 1903 } |
1843 if (!fd) | 1908 if (!fd) |
1844 { | 1909 { |
1845 GList *work = vfi->list; | 1910 GList *work = vfi->list; |
1846 while (work && !fd) | 1911 while (work && !fd) |
1847 { | 1912 { |
1848 FileData *fd_p = work->data; | 1913 IconData *id = work->data; |
1914 FileData *fd_p = id->fd; | |
1849 work = work->next; | 1915 work = work->next; |
1850 | 1916 |
1851 if (!fd_p->pixbuf) fd = fd_p; | 1917 if (!fd_p->pixbuf) fd = fd_p; |
1852 } | 1918 } |
1853 } | 1919 } |
1900 *----------------------------------------------------------------------------- | 1966 *----------------------------------------------------------------------------- |
1901 */ | 1967 */ |
1902 | 1968 |
1903 FileData *vficon_index_get_data(ViewFileIcon *vfi, gint row) | 1969 FileData *vficon_index_get_data(ViewFileIcon *vfi, gint row) |
1904 { | 1970 { |
1905 return FILE_DATA(g_list_nth_data(vfi->list, row)); | 1971 IconData *id; |
1972 | |
1973 id = g_list_nth_data(vfi->list, row); | |
1974 return id ? id->fd : NULL; | |
1906 } | 1975 } |
1907 | 1976 |
1908 gchar *vficon_index_get_path(ViewFileIcon *vfi, gint row) | 1977 gchar *vficon_index_get_path(ViewFileIcon *vfi, gint row) |
1909 { | 1978 { |
1910 FileData *fd; | 1979 FileData *fd; |
1911 | 1980 IconData *id; |
1912 fd = g_list_nth_data(vfi->list, row); | 1981 |
1982 id = g_list_nth_data(vfi->list, row); | |
1983 fd = id ? id->fd : NULL; | |
1913 | 1984 |
1914 return (fd ? fd->path : NULL); | 1985 return (fd ? fd->path : NULL); |
1915 } | 1986 } |
1916 | 1987 |
1917 gint vficon_index_by_path(ViewFileIcon *vfi, const gchar *path) | 1988 gint vficon_index_by_path(ViewFileIcon *vfi, const gchar *path) |
1922 if (!path) return -1; | 1993 if (!path) return -1; |
1923 | 1994 |
1924 work = vfi->list; | 1995 work = vfi->list; |
1925 while (work) | 1996 while (work) |
1926 { | 1997 { |
1927 FileData *fd = work->data; | 1998 IconData *id = work->data; |
1999 FileData *fd = id->fd; | |
1928 if (strcmp(path, fd->path) == 0) return p; | 2000 if (strcmp(path, fd->path) == 0) return p; |
1929 work = work->next; | 2001 work = work->next; |
1930 p++; | 2002 p++; |
1931 } | 2003 } |
1932 | 2004 |
1933 return -1; | 2005 return -1; |
1934 } | 2006 } |
1935 | 2007 |
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 | |
1936 gint vficon_count(ViewFileIcon *vfi, gint64 *bytes) | 2047 gint vficon_count(ViewFileIcon *vfi, gint64 *bytes) |
1937 { | 2048 { |
1938 if (bytes) | 2049 if (bytes) |
1939 { | 2050 { |
1940 gint64 b = 0; | 2051 gint64 b = 0; |
1941 GList *work; | 2052 GList *work; |
1942 | 2053 |
1943 work = vfi->list; | 2054 work = vfi->list; |
1944 while (work) | 2055 while (work) |
1945 { | 2056 { |
1946 FileData *fd = work->data; | 2057 |
2058 IconData *id = work->data; | |
2059 FileData *fd = id->fd; | |
1947 work = work->next; | 2060 work = work->next; |
1948 b += fd->size; | 2061 b += fd->size; |
1949 } | 2062 } |
1950 | 2063 |
1951 *bytes = b; | 2064 *bytes = b; |
1960 GList *work; | 2073 GList *work; |
1961 | 2074 |
1962 work = vfi->list; | 2075 work = vfi->list; |
1963 while (work) | 2076 while (work) |
1964 { | 2077 { |
1965 FileData *fd = work->data; | 2078 IconData *id = work->data; |
2079 FileData *fd = id->fd; | |
1966 work = work->next; | 2080 work = work->next; |
1967 | 2081 |
1968 list = g_list_prepend(list, g_strdup(fd->path)); | 2082 list = g_list_prepend(list, file_data_ref(fd)); |
1969 } | 2083 } |
1970 | 2084 |
1971 return g_list_reverse(list); | 2085 return g_list_reverse(list); |
1972 } | 2086 } |
1973 | 2087 |
1980 static gint vficon_refresh_real(ViewFileIcon *vfi, gint keep_position) | 2094 static gint vficon_refresh_real(ViewFileIcon *vfi, gint keep_position) |
1981 { | 2095 { |
1982 gint ret = TRUE; | 2096 gint ret = TRUE; |
1983 GList *old_list; | 2097 GList *old_list; |
1984 GList *work; | 2098 GList *work; |
1985 FileData *focus_fd; | 2099 IconData *focus_id; |
1986 | 2100 |
1987 focus_fd = vfi->focus_fd; | 2101 focus_id = vfi->focus_id; |
1988 | 2102 |
1989 old_list = vfi->list; | 2103 old_list = vfi->list; |
1990 vfi->list = NULL; | 2104 vfi->list = NULL; |
1991 | 2105 |
1992 if (vfi->path) | 2106 if (vfi->path) |
1996 | 2110 |
1997 /* check for same files from old_list */ | 2111 /* check for same files from old_list */ |
1998 work = old_list; | 2112 work = old_list; |
1999 while (work) | 2113 while (work) |
2000 { | 2114 { |
2115 IconData *id; | |
2001 FileData *fd; | 2116 FileData *fd; |
2117 | |
2002 GList *needle; | 2118 GList *needle; |
2003 | 2119 |
2004 fd = work->data; | 2120 id = work->data; |
2121 fd = id->fd; | |
2122 | |
2005 needle = vfi->list; | 2123 needle = vfi->list; |
2006 while (needle) | 2124 while (needle) |
2007 { | 2125 { |
2008 FileData *fdn = needle->data; | 2126 IconData *idn = needle->data; |
2127 FileData *fdn = idn->fd; | |
2009 if (strcmp(fd->name, fdn->name) == 0) | 2128 if (strcmp(fd->name, fdn->name) == 0) |
2010 { | 2129 { |
2011 /* swap, to retain old thumb, selection */ | 2130 /* swap, to retain old thumb, selection */ |
2012 needle->data = fd; | 2131 needle->data = id; |
2013 work->data = fdn; | 2132 work->data = idn; |
2014 needle = NULL; | 2133 needle = NULL; |
2015 | 2134 |
2016 if (fd->date != fdn->date || fd->size != fdn->size) | 2135 if (fd->date != fdn->date || fd->size != fdn->size) |
2017 { | 2136 { |
2018 /* file changed, update */ | 2137 /* file changed, update */ |
2138 /* FIXME | |
2019 fd->date = fdn->date; | 2139 fd->date = fdn->date; |
2020 fd->size = fdn->size; | 2140 fd->size = fdn->size; |
2021 vficon_set_thumb(vfi, fd, NULL); | 2141 vficon_set_thumb(vfi, fd, NULL); |
2142 */ | |
2022 } | 2143 } |
2023 } | 2144 } |
2024 else | 2145 else |
2025 { | 2146 { |
2026 needle = needle->next; | 2147 needle = needle->next; |
2028 } | 2149 } |
2029 | 2150 |
2030 work = work->next; | 2151 work = work->next; |
2031 } | 2152 } |
2032 | 2153 |
2033 vfi->list = filelist_sort(vfi->list, vfi->sort_method, vfi->sort_ascend); | 2154 vfi->list = iconlist_sort(vfi->list, vfi->sort_method, vfi->sort_ascend); |
2034 | 2155 |
2035 work = old_list; | 2156 work = old_list; |
2036 while (work) | 2157 while (work) |
2037 { | 2158 { |
2038 FileData *fd = work->data; | 2159 IconData *id = work->data; |
2160 FileData *fd = id->fd; | |
2039 work = work->next; | 2161 work = work->next; |
2040 | 2162 |
2041 if (fd == vfi->prev_selection) vfi->prev_selection = NULL; | 2163 if (id == vfi->prev_selection) vfi->prev_selection = NULL; |
2042 if (fd == vfi->click_fd) vfi->click_fd = NULL; | 2164 if (id == vfi->click_id) vfi->click_id = NULL; |
2043 } | 2165 } |
2044 | 2166 |
2045 vficon_populate(vfi, TRUE, keep_position); | 2167 vficon_populate(vfi, TRUE, keep_position); |
2046 | 2168 |
2047 /* attempt to keep focus on same icon when refreshing */ | 2169 /* attempt to keep focus on same icon when refreshing */ |
2048 if (focus_fd && g_list_find(vfi->list, focus_fd)) | 2170 if (focus_id && g_list_find(vfi->list, focus_id)) |
2049 { | 2171 { |
2050 vficon_set_focus(vfi, focus_fd); | 2172 vficon_set_focus(vfi, focus_id); |
2051 } | 2173 } |
2052 | 2174 |
2053 iconlist_free(old_list); | 2175 iconlist_free(old_list); |
2054 | 2176 |
2055 return ret; | 2177 return ret; |
2078 { | 2200 { |
2079 ColumnData *cd = data; | 2201 ColumnData *cd = data; |
2080 ViewFileIcon *vfi; | 2202 ViewFileIcon *vfi; |
2081 GtkStyle *style; | 2203 GtkStyle *style; |
2082 GList *list; | 2204 GList *list; |
2083 FileData *fd; | |
2084 GdkColor color_fg; | 2205 GdkColor color_fg; |
2085 GdkColor color_bg; | 2206 GdkColor color_bg; |
2207 IconData *id; | |
2086 | 2208 |
2087 vfi = cd->vfi; | 2209 vfi = cd->vfi; |
2088 | 2210 |
2089 gtk_tree_model_get(tree_model, iter, FILE_COLUMN_POINTER, &list, -1); | 2211 gtk_tree_model_get(tree_model, iter, FILE_COLUMN_POINTER, &list, -1); |
2090 fd = g_list_nth_data(list, cd->number); | 2212 |
2091 | 2213 id = g_list_nth_data(list, cd->number); |
2214 | |
2215 if (id) g_assert(id->fd->magick == 0x12345678); | |
2216 | |
2092 style = gtk_widget_get_style(vfi->listview); | 2217 style = gtk_widget_get_style(vfi->listview); |
2093 if (fd && ICON_DATA(fd)->selected & SELECTION_SELECTED) | 2218 if (id && id->selected & SELECTION_SELECTED) |
2094 { | 2219 { |
2095 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg)); | 2220 memcpy(&color_fg, &style->text[GTK_STATE_SELECTED], sizeof(color_fg)); |
2096 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg)); | 2221 memcpy(&color_bg, &style->base[GTK_STATE_SELECTED], sizeof(color_bg)); |
2097 } | 2222 } |
2098 else | 2223 else |
2099 { | 2224 { |
2100 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg)); | 2225 memcpy(&color_fg, &style->text[GTK_STATE_NORMAL], sizeof(color_fg)); |
2101 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg)); | 2226 memcpy(&color_bg, &style->base[GTK_STATE_NORMAL], sizeof(color_bg)); |
2102 } | 2227 } |
2103 | 2228 |
2104 if (fd && ICON_DATA(fd)->selected & SELECTION_PRELIGHT) | 2229 if (id && id->selected & SELECTION_PRELIGHT) |
2105 { | 2230 { |
2106 #if 0 | 2231 #if 0 |
2107 shift_color(&color_fg, -1, 0); | 2232 shift_color(&color_fg, -1, 0); |
2108 #endif | 2233 #endif |
2109 shift_color(&color_bg, -1, 0); | 2234 shift_color(&color_bg, -1, 0); |
2110 } | 2235 } |
2111 | 2236 |
2112 if (GQV_IS_CELL_RENDERER_ICON(cell)) | 2237 if (GQV_IS_CELL_RENDERER_ICON(cell)) |
2113 { | 2238 { |
2114 if (fd) | 2239 if (id) |
2115 { | 2240 { |
2116 g_object_set(cell, "pixbuf", fd->pixbuf, | 2241 g_object_set(cell, "pixbuf", id->fd->pixbuf, |
2117 "text", fd->name, | 2242 "text", id->fd->name, |
2118 "cell-background-gdk", &color_bg, | 2243 "cell-background-gdk", &color_bg, |
2119 "cell-background-set", TRUE, | 2244 "cell-background-set", TRUE, |
2120 "foreground-gdk", &color_fg, | 2245 "foreground-gdk", &color_fg, |
2121 "foreground-set", TRUE, | 2246 "foreground-set", TRUE, |
2122 "has-focus", (vfi->focus_fd == fd), NULL); | 2247 "has-focus", (vfi->focus_id == id), NULL); |
2123 } | 2248 } |
2124 else | 2249 else |
2125 { | 2250 { |
2126 g_object_set(cell, "pixbuf", NULL, | 2251 g_object_set(cell, "pixbuf", NULL, |
2127 "text", NULL, | 2252 "text", NULL, |
2183 vfi->list = NULL; | 2308 vfi->list = NULL; |
2184 | 2309 |
2185 /* NOTE: populate will clear the store for us */ | 2310 /* NOTE: populate will clear the store for us */ |
2186 ret = vficon_refresh_real(vfi, FALSE); | 2311 ret = vficon_refresh_real(vfi, FALSE); |
2187 | 2312 |
2188 vfi->focus_fd = NULL; | 2313 vfi->focus_id = NULL; |
2189 vficon_move_focus(vfi, 0, 0, FALSE); | 2314 vficon_move_focus(vfi, 0, 0, FALSE); |
2190 | 2315 |
2191 return ret; | 2316 return ret; |
2192 } | 2317 } |
2193 | 2318 |
2234 vfi->tip_window = NULL; | 2359 vfi->tip_window = NULL; |
2235 vfi->tip_delay_id = -1; | 2360 vfi->tip_delay_id = -1; |
2236 | 2361 |
2237 vfi->focus_row = 0; | 2362 vfi->focus_row = 0; |
2238 vfi->focus_column = 0; | 2363 vfi->focus_column = 0; |
2239 vfi->focus_fd = NULL; | 2364 vfi->focus_id = NULL; |
2240 | 2365 |
2241 vfi->show_text = show_icon_names; | 2366 vfi->show_text = show_icon_names; |
2242 | 2367 |
2243 vfi->sync_idle_id = -1; | 2368 vfi->sync_idle_id = -1; |
2244 | 2369 |
2334 row ++; | 2459 row ++; |
2335 | 2460 |
2336 work = ignore_list; | 2461 work = ignore_list; |
2337 while (work) | 2462 while (work) |
2338 { | 2463 { |
2339 gint f = vficon_index_by_path(vfi, work->data); | 2464 FileData *fd = work->data; |
2465 gint f = vficon_index_by_fd(vfi, work->data); | |
2466 g_assert(fd->magick == 0x12345678); | |
2340 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f)); | 2467 if (f >= 0) list = g_list_prepend(list, GINT_TO_POINTER(f)); |
2341 work = work->next; | 2468 work = work->next; |
2342 } | 2469 } |
2343 | 2470 |
2344 while (list) | 2471 while (list) |
2378 { | 2505 { |
2379 return row; | 2506 return row; |
2380 } | 2507 } |
2381 } | 2508 } |
2382 | 2509 |
2383 gint vficon_maint_renamed(ViewFileIcon *vfi, const gchar *source, const gchar *dest) | 2510 gint vficon_maint_renamed(ViewFileIcon *vfi, FileData *fd) |
2384 { | 2511 { |
2385 gint ret = FALSE; | 2512 gint ret = FALSE; |
2386 gint row; | 2513 gint row; |
2387 gchar *source_base; | 2514 gchar *source_base; |
2388 gchar *dest_base; | 2515 gchar *dest_base; |
2389 GList *work; | 2516 IconData *id = vficon_icon_data(vfi, fd); |
2390 FileData *fd; | 2517 |
2391 | 2518 if (!id) return FALSE; |
2392 row = vficon_index_by_path(vfi, source); | 2519 |
2520 row = vficon_index_by_id(vfi, id); | |
2393 if (row < 0) return FALSE; | 2521 if (row < 0) return FALSE; |
2394 | 2522 |
2395 source_base = remove_level_from_path(source); | 2523 source_base = remove_level_from_path(fd->change->source); |
2396 dest_base = remove_level_from_path(dest); | 2524 dest_base = remove_level_from_path(fd->change->dest); |
2397 | |
2398 work = g_list_nth(vfi->list, row); | |
2399 fd = work->data; | |
2400 | 2525 |
2401 if (strcmp(source_base, dest_base) == 0) | 2526 if (strcmp(source_base, dest_base) == 0) |
2402 { | 2527 { |
2403 vfi->list = g_list_remove(vfi->list, fd); | 2528 vfi->list = g_list_remove(vfi->list, id); |
2404 g_free(fd->path); | 2529 vfi->list = iconlist_insert_sort(vfi->list, id, vfi->sort_method, vfi->sort_ascend); |
2405 | |
2406 fd->path = g_strdup(dest); | |
2407 fd->name = filename_from_path(fd->path); | |
2408 | |
2409 vfi->list = filelist_insert_sort(vfi->list, fd, vfi->sort_method, vfi->sort_ascend); | |
2410 | 2530 |
2411 vficon_sync_idle(vfi); | 2531 vficon_sync_idle(vfi); |
2412 ret = TRUE; | 2532 ret = TRUE; |
2413 } | 2533 } |
2414 else | 2534 else |
2415 { | 2535 { |
2416 ret = vficon_maint_removed(vfi, source, NULL); | 2536 ret = vficon_maint_removed(vfi, fd, NULL); |
2417 } | 2537 } |
2418 | 2538 |
2419 g_free(source_base); | 2539 g_free(source_base); |
2420 g_free(dest_base); | 2540 g_free(dest_base); |
2421 | 2541 |
2422 return ret; | 2542 return ret; |
2423 } | 2543 } |
2424 | 2544 |
2425 gint vficon_maint_removed(ViewFileIcon *vfi, const gchar *path, GList *ignore_list) | 2545 gint vficon_maint_removed(ViewFileIcon *vfi, FileData *fd, GList *ignore_list) |
2426 { | 2546 { |
2427 FileData *fd; | |
2428 gint row; | 2547 gint row; |
2429 gint new_row = -1; | 2548 gint new_row = -1; |
2430 GtkTreeModel *store; | 2549 GtkTreeModel *store; |
2431 GtkTreeIter iter; | 2550 GtkTreeIter iter; |
2432 | 2551 IconData *id = vficon_icon_data(vfi, fd); |
2433 row = vficon_index_by_path(vfi, path); | 2552 |
2553 if (!id) return FALSE; | |
2554 | |
2555 row = g_list_index(vfi->list, id); | |
2434 if (row < 0) return FALSE; | 2556 if (row < 0) return FALSE; |
2435 | 2557 |
2436 fd = g_list_nth_data(vfi->list, row); | 2558 if ((id->selected & SELECTION_SELECTED) && |
2437 if (!fd) return FALSE; | |
2438 | |
2439 if ((ICON_DATA(fd)->selected & SELECTION_SELECTED) && | |
2440 layout_image_get_collection(vfi->layout, NULL) == NULL) | 2559 layout_image_get_collection(vfi->layout, NULL) == NULL) |
2441 { | 2560 { |
2442 vficon_unselect(vfi, fd); | 2561 vficon_unselect(vfi, id); |
2443 | 2562 |
2444 if (!vfi->selection) | 2563 if (!vfi->selection) |
2445 { | 2564 { |
2446 gint n; | 2565 gint n; |
2447 | 2566 |
2468 GList *work; | 2587 GList *work; |
2469 | 2588 |
2470 work = vfi->selection; | 2589 work = vfi->selection; |
2471 while (work) | 2590 while (work) |
2472 { | 2591 { |
2592 IconData *ignore_id; | |
2473 FileData *ignore_fd; | 2593 FileData *ignore_fd; |
2474 GList *tmp; | 2594 GList *tmp; |
2475 gint match = FALSE; | 2595 gint match = FALSE; |
2476 | 2596 |
2477 ignore_fd = work->data; | 2597 ignore_id = work->data; |
2598 ignore_fd = ignore_id->fd; | |
2599 g_assert(ignore_fd->magick == 0x12345678); | |
2478 work = work->next; | 2600 work = work->next; |
2479 | 2601 |
2480 tmp = ignore_list; | 2602 tmp = ignore_list; |
2481 while (tmp && !match) | 2603 while (tmp && !match) |
2482 { | 2604 { |
2483 const gchar *ignore_path; | 2605 FileData *ignore_list_fd = tmp->data; |
2484 | 2606 g_assert(ignore_list_fd->magick == 0x12345678); |
2485 ignore_path = tmp->data; | |
2486 tmp = tmp->next; | 2607 tmp = tmp->next; |
2487 | 2608 |
2488 if (strcmp(ignore_fd->path, ignore_path) == 0) | 2609 if (ignore_list_fd == ignore_fd) |
2489 { | 2610 { |
2490 match = TRUE; | 2611 match = TRUE; |
2491 } | 2612 } |
2492 } | 2613 } |
2493 if (!match) | 2614 if (!match) |
2494 { | 2615 { |
2495 new_row = g_list_index(vfi->list, ignore_fd); | 2616 new_row = g_list_index(vfi->list, ignore_id); |
2496 work = NULL; | 2617 work = NULL; |
2497 } | 2618 } |
2498 } | 2619 } |
2499 if (new_row == -1) | 2620 if (new_row == -1) |
2500 { | 2621 { |
2507 new_row = g_list_index(vfi->list, vfi->selection->data); | 2628 new_row = g_list_index(vfi->list, vfi->selection->data); |
2508 } | 2629 } |
2509 if (new_row >= 0) | 2630 if (new_row >= 0) |
2510 { | 2631 { |
2511 FileData *fdn; | 2632 FileData *fdn; |
2633 IconData *idn = vficon_icon_data(vfi,fdn); | |
2512 | 2634 |
2513 fdn = g_list_nth_data(vfi->list, new_row); | 2635 fdn = g_list_nth_data(vfi->list, new_row); |
2514 vficon_select(vfi, fdn); | 2636 vficon_select(vfi, idn); |
2515 vficon_send_layout_select(vfi, fdn); | 2637 vficon_send_layout_select(vfi, idn); |
2516 } | 2638 } |
2517 } | 2639 } |
2518 | 2640 |
2519 /* Thumb loader check */ | 2641 /* Thumb loader check */ |
2520 if (fd == vfi->thumbs_fd) vfi->thumbs_fd = NULL; | 2642 if (fd == vfi->thumbs_fd) vfi->thumbs_fd = NULL; |
2521 if (vfi->thumbs_count > 0) vfi->thumbs_count--; | 2643 if (vfi->thumbs_count > 0) vfi->thumbs_count--; |
2522 | 2644 |
2523 if (vfi->prev_selection == fd) vfi->prev_selection = NULL; | 2645 if (vfi->prev_selection == id) vfi->prev_selection = NULL; |
2524 if (vfi->click_fd == fd) vfi->click_fd = NULL; | 2646 if (vfi->click_id == id) vfi->click_id = NULL; |
2525 | 2647 |
2526 /* remove pointer to this fd from grid */ | 2648 /* remove pointer to this fd from grid */ |
2527 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); | 2649 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vfi->listview)); |
2528 if (ICON_DATA(fd)->row >= 0 && | 2650 if (id->row >= 0 && |
2529 gtk_tree_model_iter_nth_child(store, &iter, NULL, ICON_DATA(fd)->row)) | 2651 gtk_tree_model_iter_nth_child(store, &iter, NULL, id->row)) |
2530 { | 2652 { |
2531 GList *list; | 2653 GList *list; |
2532 | 2654 |
2533 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); | 2655 gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1); |
2534 list = g_list_find(list, fd); | 2656 list = g_list_find(list, id); |
2535 if (list) list->data = NULL; | 2657 if (list) list->data = NULL; |
2536 } | 2658 } |
2537 | 2659 |
2538 vfi->list = g_list_remove(vfi->list, fd); | 2660 vfi->list = g_list_remove(vfi->list, id); |
2539 file_data_free(fd); | 2661 file_data_unref(fd); |
2662 g_free(id); | |
2540 | 2663 |
2541 vficon_sync_idle(vfi); | 2664 vficon_sync_idle(vfi); |
2542 vficon_send_update(vfi); | 2665 vficon_send_update(vfi); |
2543 | 2666 |
2544 return TRUE; | 2667 return TRUE; |
2545 } | 2668 } |
2546 | 2669 |
2547 gint vficon_maint_moved(ViewFileIcon *vfi, const gchar *source, const gchar *dest, GList *ignore_list) | 2670 gint vficon_maint_moved(ViewFileIcon *vfi, FileData *fd, GList *ignore_list) |
2548 { | 2671 { |
2549 gint ret = FALSE; | 2672 gint ret = FALSE; |
2550 gchar *buf; | 2673 gchar *buf; |
2551 | 2674 |
2552 if (!source || !vfi->path) return FALSE; | 2675 if (!fd->change->source || !vfi->path) return FALSE; |
2553 | 2676 |
2554 buf = remove_level_from_path(source); | 2677 buf = remove_level_from_path(fd->change->source); |
2555 | 2678 |
2556 if (strcmp(buf, vfi->path) == 0) | 2679 if (strcmp(buf, vfi->path) == 0) |
2557 { | 2680 { |
2558 ret = vficon_maint_removed(vfi, source, ignore_list); | 2681 ret = vficon_maint_removed(vfi, fd, ignore_list); |
2559 } | 2682 } |
2560 | 2683 |
2561 g_free(buf); | 2684 g_free(buf); |
2562 | 2685 |
2563 return ret; | 2686 return ret; |