Mercurial > geeqie
comparison src/view_dir_list.c @ 383:499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
to view_dir.c.
author | zas_ |
---|---|
date | Wed, 16 Apr 2008 16:05:12 +0000 |
parents | ff63dcb0425c |
children | 392dd6541d51 |
comparison
equal
deleted
inserted
replaced
382:eceeced4cbb9 | 383:499d7ba62261 |
---|---|
40 *----------------------------------------------------------------------------- | 40 *----------------------------------------------------------------------------- |
41 * misc | 41 * misc |
42 *----------------------------------------------------------------------------- | 42 *----------------------------------------------------------------------------- |
43 */ | 43 */ |
44 | 44 |
45 static gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter) | 45 gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter) |
46 { | 46 { |
47 GtkTreeModel *store; | 47 GtkTreeModel *store; |
48 gint valid; | 48 gint valid; |
49 gint row = 0; | 49 gint row = 0; |
50 | 50 |
141 n++; | 141 n++; |
142 } | 142 } |
143 | 143 |
144 if (row) *row = -1; | 144 if (row) *row = -1; |
145 return NULL; | 145 return NULL; |
146 } | |
147 | |
148 static void vdlist_color_set(ViewDir *vd, FileData *fd, gint color_set) | |
149 { | |
150 GtkTreeModel *store; | |
151 GtkTreeIter iter; | |
152 | |
153 if (vdlist_find_row(vd, fd, &iter) < 0) return; | |
154 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); | |
155 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1); | |
156 } | |
157 | |
158 /* | |
159 *----------------------------------------------------------------------------- | |
160 * drop menu (from dnd) | |
161 *----------------------------------------------------------------------------- | |
162 */ | |
163 | |
164 static void vdlist_drop_menu_copy_cb(GtkWidget *widget, gpointer data) | |
165 { | |
166 ViewDir *vd = data; | |
167 const gchar *path; | |
168 GList *list; | |
169 | |
170 if (!vd->drop_fd) return; | |
171 | |
172 path = vd->drop_fd->path; | |
173 list = vd->drop_list; | |
174 vd->drop_list = NULL; | |
175 | |
176 file_util_copy_simple(list, path); | |
177 } | |
178 | |
179 static void vdlist_drop_menu_move_cb(GtkWidget *widget, gpointer data) | |
180 { | |
181 ViewDir *vd = data; | |
182 const gchar *path; | |
183 GList *list; | |
184 | |
185 if (!vd->drop_fd) return; | |
186 | |
187 path = vd->drop_fd->path; | |
188 list = vd->drop_list; | |
189 | |
190 vd->drop_list = NULL; | |
191 | |
192 file_util_move_simple(list, path); | |
193 } | |
194 | |
195 static GtkWidget *vdlist_drop_menu(ViewDir *vd, gint active) | |
196 { | |
197 GtkWidget *menu; | |
198 | |
199 menu = popup_menu_short_lived(); | |
200 g_signal_connect(G_OBJECT(menu), "destroy", | |
201 G_CALLBACK(vdlist_popup_destroy_cb), vd); | |
202 | |
203 menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active, | |
204 G_CALLBACK(vdlist_drop_menu_copy_cb), vd); | |
205 menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vdlist_drop_menu_move_cb), vd); | |
206 | |
207 menu_item_add_divider(menu); | |
208 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vd); | |
209 | |
210 return menu; | |
211 } | 146 } |
212 | 147 |
213 /* | 148 /* |
214 *----------------------------------------------------------------------------- | 149 *----------------------------------------------------------------------------- |
215 * pop-up menu | 150 * pop-up menu |
431 | 366 |
432 static void vdlist_popup_destroy_cb(GtkWidget *widget, gpointer data) | 367 static void vdlist_popup_destroy_cb(GtkWidget *widget, gpointer data) |
433 { | 368 { |
434 ViewDir *vd = data; | 369 ViewDir *vd = data; |
435 | 370 |
436 vdlist_color_set(vd, vd->click_fd, FALSE); | 371 vd_color_set(vd, vd->click_fd, FALSE); |
437 vd->click_fd = NULL; | 372 vd->click_fd = NULL; |
438 vd->popup = NULL; | 373 vd->popup = NULL; |
439 | 374 |
440 vdlist_color_set(vd, vd->drop_fd, FALSE); | 375 vd_color_set(vd, vd->drop_fd, FALSE); |
441 filelist_free(vd->drop_list); | 376 filelist_free(vd->drop_list); |
442 vd->drop_list = NULL; | 377 vd->drop_list = NULL; |
443 vd->drop_fd = NULL; | 378 vd->drop_fd = NULL; |
444 } | 379 } |
445 | 380 |
499 | 434 |
500 static void vdlist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | 435 static void vdlist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) |
501 { | 436 { |
502 ViewDir *vd = data; | 437 ViewDir *vd = data; |
503 | 438 |
504 vdlist_color_set(vd, vd->click_fd, TRUE); | 439 vd_color_set(vd, vd->click_fd, TRUE); |
505 vdlist_dest_set(vd, FALSE); | 440 vdlist_dest_set(vd, FALSE); |
506 } | 441 } |
507 | 442 |
508 static void vdlist_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | 443 static void vdlist_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) |
509 { | 444 { |
510 ViewDir *vd = data; | 445 ViewDir *vd = data; |
511 | 446 |
512 vdlist_color_set(vd, vd->click_fd, FALSE); | 447 vd_color_set(vd, vd->click_fd, FALSE); |
513 | 448 |
514 if (context->action == GDK_ACTION_MOVE) | 449 if (context->action == GDK_ACTION_MOVE) |
515 { | 450 { |
516 vdlist_refresh(vd); | 451 vdlist_refresh(vd); |
517 } | 452 } |
551 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); | 486 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); |
552 if (!list) return; | 487 if (!list) return; |
553 | 488 |
554 active = access_file(fd->path, W_OK | X_OK); | 489 active = access_file(fd->path, W_OK | X_OK); |
555 | 490 |
556 vdlist_color_set(vd, fd, TRUE); | 491 vd_color_set(vd, fd, TRUE); |
557 vd->popup = vdlist_drop_menu(vd, active); | 492 vd->popup = vd_drop_menu(vd, active); |
558 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, 0, time); | 493 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, 0, time); |
559 | 494 |
560 vd->drop_fd = fd; | 495 vd->drop_fd = fd; |
561 vd->drop_list = list; | 496 vd->drop_list = list; |
562 } | 497 } |
627 gtk_tree_path_free(tpath); | 562 gtk_tree_path_free(tpath); |
628 } | 563 } |
629 | 564 |
630 if (fd != vd->drop_fd) | 565 if (fd != vd->drop_fd) |
631 { | 566 { |
632 vdlist_color_set(vd, vd->drop_fd, FALSE); | 567 vd_color_set(vd, vd->drop_fd, FALSE); |
633 vdlist_color_set(vd, fd, TRUE); | 568 vd_color_set(vd, fd, TRUE); |
634 } | 569 } |
635 | 570 |
636 vd->drop_fd = fd; | 571 vd->drop_fd = fd; |
637 } | 572 } |
638 | 573 |
707 | 642 |
708 static void vdlist_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | 643 static void vdlist_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) |
709 { | 644 { |
710 ViewDir *vd = data; | 645 ViewDir *vd = data; |
711 | 646 |
712 if (vd->drop_fd != vd->click_fd) vdlist_color_set(vd, vd->drop_fd, FALSE); | 647 if (vd->drop_fd != vd->click_fd) vd_color_set(vd, vd->drop_fd, FALSE); |
713 | 648 |
714 vd->drop_fd = NULL; | 649 vd->drop_fd = NULL; |
715 } | 650 } |
716 | 651 |
717 static void vdlist_dnd_init(ViewDir *vd) | 652 static void vdlist_dnd_init(ViewDir *vd) |
943 else | 878 else |
944 { | 879 { |
945 vd->click_fd = NULL; | 880 vd->click_fd = NULL; |
946 } | 881 } |
947 | 882 |
948 vdlist_color_set(vd, vd->click_fd, TRUE); | 883 vd_color_set(vd, vd->click_fd, TRUE); |
949 | 884 |
950 vd->popup = vdlist_pop_menu(vd, vd->click_fd); | 885 vd->popup = vdlist_pop_menu(vd, vd->click_fd); |
951 | 886 |
952 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vdlist_menu_position_cb, vd, 0, GDK_CURRENT_TIME); | 887 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vdlist_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
953 | 888 |
972 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | 907 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); |
973 gtk_tree_path_free(tpath); | 908 gtk_tree_path_free(tpath); |
974 } | 909 } |
975 | 910 |
976 vd->click_fd = fd; | 911 vd->click_fd = fd; |
977 vdlist_color_set(vd, vd->click_fd, TRUE); | 912 vd_color_set(vd, vd->click_fd, TRUE); |
978 | 913 |
979 if (bevent->button == 3) | 914 if (bevent->button == 3) |
980 { | 915 { |
981 vd->popup = vdlist_pop_menu(vd, vd->click_fd); | 916 vd->popup = vdlist_pop_menu(vd, vd->click_fd); |
982 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, | 917 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
991 ViewDir *vd = data; | 926 ViewDir *vd = data; |
992 GtkTreePath *tpath; | 927 GtkTreePath *tpath; |
993 GtkTreeIter iter; | 928 GtkTreeIter iter; |
994 FileData *fd = NULL; | 929 FileData *fd = NULL; |
995 | 930 |
996 vdlist_color_set(vd, vd->click_fd, FALSE); | 931 vd_color_set(vd, vd->click_fd, FALSE); |
997 | 932 |
998 if (bevent->button != 1) return TRUE; | 933 if (bevent->button != 1) return TRUE; |
999 | 934 |
1000 if ((bevent->x != 0 || bevent->y != 0) && | 935 if ((bevent->x != 0 || bevent->y != 0) && |
1001 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | 936 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, |