2 * Copyright (C) 2008 - 2016 The Geeqie Team
4 * Author: Laurent Monin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "layout-image.h"
29 #include "layout-util.h"
31 #include "ui-fileops.h"
32 #include "ui-tree-edit.h"
36 #include "uri-utils.h"
37 #include "view-dir-list.h"
38 #include "view-dir-tree.h"
40 /* Folders icons to be used in tree or list directory view */
41 static PixmapFolders *folder_icons_new(GtkWidget *widget)
43 PixmapFolders *pf = g_new0(PixmapFolders, 1);
46 GtkIconSize size = GTK_ICON_SIZE_MENU;
48 /* Attempt to use stock gtk icons */
49 pf->close = gtk_widget_render_icon(widget, GTK_STOCK_DIRECTORY, size, NULL);
50 pf->open = gtk_widget_render_icon(widget, GTK_STOCK_OPEN, size, NULL);
51 pf->deny = gtk_widget_render_icon(widget, GTK_STOCK_STOP, size, NULL);
52 pf->parent = gtk_widget_render_icon(widget, GTK_STOCK_GO_UP, size, NULL);
53 pf->link = gtk_widget_render_icon(widget, GTK_STOCK_REDO, size, NULL); /** @FIXME this is not a suitable icon */
55 /* GQView legacy icons */
56 pf->close = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
57 pf->open = pixbuf_inline(PIXBUF_INLINE_FOLDER_OPEN);
58 pf->deny = pixbuf_inline(PIXBUF_INLINE_FOLDER_LOCKED);
59 pf->parent = pixbuf_inline(PIXBUF_INLINE_FOLDER_UP);
64 static void folder_icons_free(PixmapFolders *pf)
68 g_object_unref(pf->close);
69 g_object_unref(pf->open);
70 g_object_unref(pf->deny);
71 g_object_unref(pf->parent);
72 g_object_unref(pf->link);
79 static void vd_notify_cb(FileData *fd, NotifyType type, gpointer data);
81 static void vd_destroy_cb(GtkWidget *widget, gpointer data)
83 ViewDir *vd = static_cast<ViewDir *>(data);
85 file_data_unregister_notify_func(vd_notify_cb, vd);
89 g_signal_handlers_disconnect_matched(G_OBJECT(vd->popup), G_SIGNAL_MATCH_DATA,
91 gtk_widget_destroy(vd->popup);
96 case DIRVIEW_LIST: vdlist_destroy_cb(widget, data); break;
97 case DIRVIEW_TREE: vdtree_destroy_cb(widget, data); break;
100 if (vd->pf) folder_icons_free(vd->pf);
101 if (vd->drop_list) filelist_free(vd->drop_list);
103 if (vd->dir_fd) file_data_unref(vd->dir_fd);
104 if (vd->info) g_free(vd->info);
109 ViewDir *vd_new(LayoutWindow *lw)
111 ViewDir *vd = g_new0(ViewDir, 1);
113 vd->widget = gtk_scrolled_window_new(NULL, NULL);
114 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vd->widget), GTK_SHADOW_IN);
115 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vd->widget),
116 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
119 vd->pf = folder_icons_new(vd->widget);
121 switch (lw->options.dir_view_type)
123 case DIRVIEW_LIST: vd = vdlist_new(vd, lw->dir_fd); break;
124 case DIRVIEW_TREE: vd = vdtree_new(vd, lw->dir_fd); break;
127 gtk_container_add(GTK_CONTAINER(vd->widget), vd->view);
131 g_signal_connect(G_OBJECT(vd->view), "row_activated",
132 G_CALLBACK(vd_activate_cb), vd);
133 g_signal_connect(G_OBJECT(vd->widget), "destroy",
134 G_CALLBACK(vd_destroy_cb), vd);
135 g_signal_connect(G_OBJECT(vd->view), "key_press_event",
136 G_CALLBACK(vd_press_key_cb), vd);
137 g_signal_connect(G_OBJECT(vd->view), "button_press_event",
138 G_CALLBACK(vd_press_cb), vd);
139 g_signal_connect(G_OBJECT(vd->view), "button_release_event",
140 G_CALLBACK(vd_release_cb), vd);
142 file_data_register_notify_func(vd_notify_cb, vd, NOTIFY_PRIORITY_HIGH);
144 /* vd_set_fd expects that vd_notify_cb is already registered */
145 if (lw->dir_fd) vd_set_fd(vd, lw->dir_fd);
147 gtk_widget_show(vd->view);
152 void vd_set_select_func(ViewDir *vd,
153 void (*func)(ViewDir *vd, FileData *fd, gpointer data), gpointer data)
155 vd->select_func = func;
156 vd->select_data = data;
159 //void vd_set_layout(ViewDir *vd, LayoutWindow *layout)
161 //vd->layout = layout;
164 gboolean vd_set_fd(ViewDir *vd, FileData *dir_fd)
166 gboolean ret = FALSE;
168 file_data_unregister_notify_func(vd_notify_cb, vd);
172 case DIRVIEW_LIST: ret = vdlist_set_fd(vd, dir_fd); break;
173 case DIRVIEW_TREE: ret = vdtree_set_fd(vd, dir_fd); break;
176 file_data_register_notify_func(vd_notify_cb, vd, NOTIFY_PRIORITY_HIGH);
181 void vd_refresh(ViewDir *vd)
185 case DIRVIEW_LIST: vdlist_refresh(vd); break;
186 case DIRVIEW_TREE: vdtree_refresh(vd); break;
190 //const gchar *vd_row_get_path(ViewDir *vd, gint row)
192 //const gchar *ret = NULL;
196 //case DIRVIEW_LIST: ret = vdlist_row_get_path(vd, row); break;
197 //case DIRVIEW_TREE: ret = vdtree_row_get_path(vd, row); break;
203 /* the calling stack is this:
204 vd_select_row -> select_func -> layout_set_fd -> vd_set_fd
206 void vd_select_row(ViewDir *vd, FileData *fd)
208 if (fd && vd->select_func)
210 vd->select_func(vd, fd, vd->select_data);
214 gboolean vd_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter)
216 gboolean ret = FALSE;
220 case DIRVIEW_LIST: ret = vdlist_find_row(vd, fd, iter); break;
221 case DIRVIEW_TREE: ret = vdtree_find_row(vd, fd, iter, NULL); break;
227 FileData *vd_get_fd_from_tree_path(ViewDir *vd, GtkTreeView *tview, GtkTreePath *tpath)
233 store = gtk_tree_view_get_model(tview);
234 gtk_tree_model_get_iter(store, &iter, tpath);
238 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1);
243 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
244 fd = (nd) ? nd->fd : NULL;
252 static void vd_rename_finished_cb(gboolean success, const gchar *new_path, gpointer data)
254 ViewDir *vd = static_cast<ViewDir *>(data);
257 FileData *fd = file_data_new_dir(new_path);
260 if (vd_find_row(vd, fd, &iter))
262 tree_view_row_make_visible(GTK_TREE_VIEW(vd->view), &iter, TRUE);
269 static gboolean vd_rename_cb(TreeEditData *td, const gchar *UNUSED(old_name), const gchar *new_name, gpointer data)
271 ViewDir *vd = static_cast<ViewDir *>(data);
276 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(vd->view), td->path);
277 if (!fd) return FALSE;
279 base = remove_level_from_path(fd->path);
280 new_path = g_build_filename(base, new_name, NULL);
283 file_util_rename_dir(fd, new_path, vd->view, vd_rename_finished_cb, vd);
290 static void vd_rename_by_data(ViewDir *vd, FileData *fd)
296 if (!fd || !vd_find_row(vd, fd, &iter)) return;
297 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
298 tpath = gtk_tree_model_get_path(store, &iter);
300 tree_edit_by_path(GTK_TREE_VIEW(vd->view), tpath, 0, fd->name,
302 gtk_tree_path_free(tpath);
306 void vd_color_set(ViewDir *vd, FileData *fd, gint color_set)
311 if (!vd_find_row(vd, fd, &iter)) return;
312 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
317 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1);
320 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1);
325 void vd_popup_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
327 ViewDir *vd = static_cast<ViewDir *>(data);
329 vd_color_set(vd, vd->click_fd, FALSE);
333 vd_color_set(vd, vd->drop_fd, FALSE);
334 filelist_free(vd->drop_list);
335 vd->drop_list = NULL;
340 *-----------------------------------------------------------------------------
341 * drop menu (from dnd)
342 *-----------------------------------------------------------------------------
345 static void vd_drop_menu_copy_cb(GtkWidget *UNUSED(widget), gpointer data)
347 ViewDir *vd = static_cast<ViewDir *>(data);
351 if (!vd->drop_fd) return;
353 path = vd->drop_fd->path;
354 list = vd->drop_list;
355 vd->drop_list = NULL;
357 file_util_copy_simple(list, path, vd->widget);
360 static void vd_drop_menu_move_cb(GtkWidget *UNUSED(widget), gpointer data)
362 ViewDir *vd = static_cast<ViewDir *>(data);
366 if (!vd->drop_fd) return;
368 path = vd->drop_fd->path;
369 list = vd->drop_list;
371 vd->drop_list = NULL;
373 file_util_move_simple(list, path, vd->widget);
376 static void vd_drop_menu_filter_cb(GtkWidget *widget, gpointer data)
378 ViewDir *vd = static_cast<ViewDir *>(data);
383 if (!vd->drop_fd) return;
385 key = static_cast<const gchar *>(g_object_get_data(G_OBJECT(widget), "filter_key"));
387 path = vd->drop_fd->path;
388 list = vd->drop_list;
390 vd->drop_list = NULL;
392 file_util_start_filter_from_filelist(key, list, path, vd->widget);
395 static void vd_drop_menu_edit_item_free(gpointer data)
400 GtkWidget *vd_drop_menu(ViewDir *vd, gint active)
403 GList *editors_list = editor_list_get();
404 GList *work = editors_list;
406 menu = popup_menu_short_lived();
407 g_signal_connect(G_OBJECT(menu), "destroy",
408 G_CALLBACK(vd_popup_destroy_cb), vd);
410 menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active,
411 G_CALLBACK(vd_drop_menu_copy_cb), vd);
412 menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vd_drop_menu_move_cb), vd);
417 const EditorDescription *editor = static_cast<const EditorDescription *>(work->data);
421 if (!editor_is_filter(editor->key)) continue;
422 key = g_strdup(editor->key);
423 item = menu_item_add_sensitive(menu, editor->name, active, G_CALLBACK(vd_drop_menu_filter_cb), vd);
424 g_object_set_data_full(G_OBJECT(item), "filter_key", key, vd_drop_menu_edit_item_free);
427 g_list_free(editors_list);
429 menu_item_add_divider(menu);
430 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vd);
436 *-----------------------------------------------------------------------------
438 *-----------------------------------------------------------------------------
441 static void vd_pop_menu_up_cb(GtkWidget *UNUSED(widget), gpointer data)
443 ViewDir *vd = static_cast<ViewDir *>(data);
446 if (!vd->dir_fd || strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) == 0) return;
447 path = remove_level_from_path(vd->dir_fd->path);
451 FileData *fd = file_data_new_dir(path);
452 vd->select_func(vd, fd, vd->select_data);
459 static void vd_pop_menu_slide_cb(GtkWidget *UNUSED(widget), gpointer data)
461 ViewDir *vd = static_cast<ViewDir *>(data);
463 if (!vd->layout) return;
464 if (!vd->click_fd) return;
466 layout_set_fd(vd->layout, vd->click_fd);
467 layout_select_none(vd->layout);
468 layout_image_slideshow_stop(vd->layout);
469 layout_image_slideshow_start(vd->layout);
472 static void vd_pop_menu_slide_rec_cb(GtkWidget *UNUSED(widget), gpointer data)
474 ViewDir *vd = static_cast<ViewDir *>(data);
477 if (!vd->layout) return;
478 if (!vd->click_fd) return;
480 list = filelist_recursive_full(vd->click_fd, vd->layout->sort_method, vd->layout->sort_ascend);
482 layout_image_slideshow_stop(vd->layout);
483 layout_image_slideshow_start_from_list(vd->layout, list);
486 static void vd_pop_menu_dupe(ViewDir *vd, gint recursive)
491 if (!vd->click_fd) return;
495 list = g_list_append(list, file_data_ref(vd->click_fd));
499 filelist_read(vd->click_fd, &list, NULL);
500 list = filelist_filter(list, FALSE);
503 dw = dupe_window_new();
504 dupe_window_add_files(dw, list, recursive);
509 static void vd_pop_menu_dupe_cb(GtkWidget *UNUSED(widget), gpointer data)
511 ViewDir *vd = static_cast<ViewDir *>(data);
512 vd_pop_menu_dupe(vd, FALSE);
515 static void vd_pop_menu_dupe_rec_cb(GtkWidget *UNUSED(widget), gpointer data)
517 ViewDir *vd = static_cast<ViewDir *>(data);
518 vd_pop_menu_dupe(vd, TRUE);
521 static void vd_pop_menu_delete_cb(GtkWidget *UNUSED(widget), gpointer data)
523 ViewDir *vd = static_cast<ViewDir *>(data);
525 if (!vd->click_fd) return;
526 file_util_delete_dir(vd->click_fd, vd->widget);
529 static void vd_pop_menu_copy_path_cb(GtkWidget *UNUSED(widget), gpointer data)
531 ViewDir *vd = static_cast<ViewDir *>(data);
533 if (!vd->click_fd) return;
535 file_util_copy_path_to_clipboard(vd->click_fd, TRUE);
538 static void vd_pop_menu_copy_path_unquoted_cb(GtkWidget *UNUSED(widget), gpointer data)
540 ViewDir *vd = static_cast<ViewDir *>(data);
542 if (!vd->click_fd) return;
544 file_util_copy_path_to_clipboard(vd->click_fd, FALSE);
547 static void vd_pop_submenu_dir_view_as_cb(GtkWidget *widget, gpointer data)
549 ViewDir *vd = static_cast<ViewDir *>(data);
551 DirViewType new_type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "menu_item_radio_data"));
552 layout_views_set(vd->layout, new_type, vd->layout->options.file_view_type);
555 static void vd_pop_menu_refresh_cb(GtkWidget *UNUSED(widget), gpointer data)
557 ViewDir *vd = static_cast<ViewDir *>(data);
559 if (vd->layout) layout_refresh(vd->layout);
562 static void vd_toggle_show_hidden_files_cb(GtkWidget *UNUSED(widget), gpointer data)
564 ViewDir *vd = static_cast<ViewDir *>(data);
566 options->file_filter.show_hidden_files = !options->file_filter.show_hidden_files;
567 if (vd->layout) layout_refresh(vd->layout);
570 static void vd_pop_menu_new_folder_cb(gboolean success, const gchar *new_path, gpointer data)
572 ViewDir *vd = static_cast<ViewDir *>(data);
578 if (!success) return;
585 fd = vdlist_row_by_path(vd, new_path, NULL);
590 FileData *new_fd = file_data_new_dir(new_path);
591 fd = vdtree_populate_path(vd, new_fd, TRUE, TRUE);
592 file_data_unref(new_fd);
597 if (!fd || !vd_find_row(vd, fd, &iter)) return;
598 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
599 tpath = gtk_tree_model_get_path(store, &iter);
600 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE);
602 gtk_tree_path_free(tpath);
605 static void vd_pop_menu_new_cb(GtkWidget *UNUSED(widget), gpointer data)
607 ViewDir *vd = static_cast<ViewDir *>(data);
608 FileData *dir_fd = NULL;
614 if (!vd->dir_fd) return;
620 if (!vd->click_fd) return;
621 dir_fd = vd->click_fd;
626 file_util_create_dir(dir_fd, vd->layout->window, vd_pop_menu_new_folder_cb, vd);
629 static void vd_pop_menu_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
631 ViewDir *vd = static_cast<ViewDir *>(data);
633 vd_rename_by_data(vd, vd->click_fd);
636 static void vd_pop_menu_sort_ascend_cb(GtkWidget *widget, gpointer data)
638 ViewDir *vd = static_cast<ViewDir *>(data);
643 if (!vd->layout) return;
645 ascend = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
646 layout_views_set_sort(vd->layout, vd->layout->options.dir_view_list_sort.method, ascend);
648 if (vd->layout) layout_refresh(vd->layout);
651 static void vd_pop_menu_sort_cb(GtkWidget *widget, gpointer data)
656 vd = static_cast<ViewDir *>(submenu_item_get_data(widget));
659 if (!vd->layout) return;
661 type = (SortType)GPOINTER_TO_INT(data);
663 if (type == SORT_NAME || type == SORT_TIME)
665 layout_views_set_sort(vd->layout, type, vd->layout->options.dir_view_list_sort.ascend);
667 if (vd->layout) layout_refresh(vd->layout);
671 GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
675 gboolean rename_delete_active = FALSE;
676 gboolean new_folder_active = FALSE;
680 active = (fd != NULL);
685 /* check using . (always row 0) */
686 new_folder_active = (vd->dir_fd && access_file(vd->dir_fd->path , W_OK | X_OK));
688 /* ignore .. and . */
689 rename_delete_active = (new_folder_active && fd &&
690 strcmp(fd->name, ".") != 0 &&
691 strcmp(fd->name, "..") != 0 &&
692 access_file(fd->path, W_OK | X_OK));
700 new_folder_active = (fd && access_file(fd->path, W_OK | X_OK));
701 parent = remove_level_from_path(fd->path);
702 rename_delete_active = access_file(parent, W_OK | X_OK);
709 menu = popup_menu_short_lived();
710 g_signal_connect(G_OBJECT(menu), "destroy",
711 G_CALLBACK(vd_popup_destroy_cb), vd);
713 menu_item_add_stock_sensitive(menu, _("_Up to parent"), GTK_STOCK_GO_UP,
714 (vd->dir_fd && strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) != 0),
715 G_CALLBACK(vd_pop_menu_up_cb), vd);
717 menu_item_add_divider(menu);
718 menu_item_add_sensitive(menu, _("_Slideshow"), active,
719 G_CALLBACK(vd_pop_menu_slide_cb), vd);
720 menu_item_add_sensitive(menu, _("Slideshow recursive"), active,
721 G_CALLBACK(vd_pop_menu_slide_rec_cb), vd);
723 menu_item_add_divider(menu);
724 menu_item_add_stock_sensitive(menu, _("Find _duplicates..."), GTK_STOCK_FIND, active,
725 G_CALLBACK(vd_pop_menu_dupe_cb), vd);
726 menu_item_add_stock_sensitive(menu, _("Find duplicates recursive..."), GTK_STOCK_FIND, active,
727 G_CALLBACK(vd_pop_menu_dupe_rec_cb), vd);
729 menu_item_add_divider(menu);
731 menu_item_add_sensitive(menu, _("_New folder..."), new_folder_active,
732 G_CALLBACK(vd_pop_menu_new_cb), vd);
734 menu_item_add_sensitive(menu, _("_Rename..."), rename_delete_active,
735 G_CALLBACK(vd_pop_menu_rename_cb), vd);
737 menu_item_add(menu, _("_Copy path"),
738 G_CALLBACK(vd_pop_menu_copy_path_cb), vd);
740 menu_item_add(menu, _("_Copy path unquoted"),
741 G_CALLBACK(vd_pop_menu_copy_path_unquoted_cb), vd);
743 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, rename_delete_active,
744 G_CALLBACK(vd_pop_menu_delete_cb), vd);
745 menu_item_add_divider(menu);
748 menu_item_add_radio(menu, _("View as _List"), GINT_TO_POINTER(DIRVIEW_LIST), vd->type == DIRVIEW_LIST,
749 G_CALLBACK(vd_pop_submenu_dir_view_as_cb), vd);
751 menu_item_add_radio(menu, _("View as _Tree"), GINT_TO_POINTER(DIRVIEW_TREE), vd->type == DIRVIEW_TREE,
752 G_CALLBACK(vd_pop_submenu_dir_view_as_cb), vd);
754 if (vd->type == DIRVIEW_LIST)
756 submenu = submenu_add_dir_sort(NULL, G_CALLBACK(vd_pop_menu_sort_cb), vd, FALSE, FALSE, TRUE, vd->layout->options.dir_view_list_sort.method);
757 menu_item_add_check(submenu, _("Ascending"), vd->layout->options.dir_view_list_sort.ascend, G_CALLBACK(vd_pop_menu_sort_ascend_cb), (vd));
758 item = menu_item_add(menu, _("_Sort"), NULL, NULL);
759 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
762 menu_item_add_divider(menu);
764 menu_item_add_check(menu, _("Show _hidden files"), options->file_filter.show_hidden_files,
765 G_CALLBACK(vd_toggle_show_hidden_files_cb), vd);
767 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH,
768 G_CALLBACK(vd_pop_menu_refresh_cb), vd);
773 void vd_new_folder(ViewDir *vd, FileData *dir_fd)
775 file_util_create_dir(dir_fd, vd->layout->window, vd_pop_menu_new_folder_cb, vd);
779 *-----------------------------------------------------------------------------
781 *-----------------------------------------------------------------------------
784 static GtkTargetEntry vd_dnd_drop_types[] = {
785 { "text/uri-list", 0, TARGET_URI_LIST }
787 static gint vd_dnd_drop_types_count = 1;
789 static void vd_dest_set(ViewDir *vd, gint enable)
793 gtk_drag_dest_set(vd->view,
794 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
795 vd_dnd_drop_types, vd_dnd_drop_types_count,
796 GDK_ACTION_MOVE | GDK_ACTION_COPY);
800 gtk_drag_dest_unset(vd->view);
804 static void vd_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context),
805 GtkSelectionData *selection_data, guint info,
806 guint UNUSED(time), gpointer data)
808 ViewDir *vd = static_cast<ViewDir *>(data);
811 if (!vd->click_fd) return;
815 case TARGET_URI_LIST:
816 case TARGET_TEXT_PLAIN:
817 list = g_list_prepend(NULL, vd->click_fd);
818 uri_selection_data_set_uris_from_filelist(selection_data, list);
824 static void vd_dnd_begin(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context), gpointer data)
826 ViewDir *vd = static_cast<ViewDir *>(data);
828 vd_color_set(vd, vd->click_fd, TRUE);
829 vd_dest_set(vd, FALSE);
832 static void vd_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *context, gpointer data)
834 ViewDir *vd = static_cast<ViewDir *>(data);
836 vd_color_set(vd, vd->click_fd, FALSE);
838 if (vd->type == DIRVIEW_LIST && gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
842 vd_dest_set(vd, TRUE);
845 static void vd_dnd_drop_receive(GtkWidget *widget,
846 GdkDragContext *UNUSED(context), gint x, gint y,
847 GtkSelectionData *selection_data, guint info,
848 guint UNUSED(time), gpointer data)
850 ViewDir *vd = static_cast<ViewDir *>(data);
853 GdkDragAction action = GDK_ACTION_ASK;
857 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y,
858 &tpath, NULL, NULL, NULL))
860 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(widget), tpath);
861 gtk_tree_path_free(tpath);
866 if (info == TARGET_URI_LIST)
870 gboolean done = FALSE;
872 list = uri_filelist_from_gtk_selection_data(selection_data);
875 active = access_file(fd->path, W_OK | X_OK);
877 vd_color_set(vd, fd, TRUE);
881 /** @FIXME With GTK2 gdk_drag_context_get_actions() shows the state of the
882 * shift and control keys during the drag operation. With GTK3 this is not
883 * so. This is a workaround.
885 GdkModifierType mask;
887 gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, &mask);
888 if (mask & GDK_CONTROL_MASK)
890 action = GDK_ACTION_COPY;
892 else if (mask & GDK_SHIFT_MASK)
894 action = GDK_ACTION_MOVE;
897 if (action != GDK_ACTION_COPY && action != GDK_ACTION_MOVE)
899 if (options->dnd_default_action == DND_ACTION_COPY)
901 action = GDK_ACTION_COPY;
903 else if (options->dnd_default_action == DND_ACTION_MOVE)
905 action = GDK_ACTION_MOVE;
909 if (action == GDK_ACTION_COPY)
911 file_util_copy_simple(list, fd->path, vd->widget);
915 else if (action == GDK_ACTION_MOVE)
917 file_util_move_simple(list, fd->path, vd->widget);
925 vd->popup = vd_drop_menu(vd, active);
926 gtk_menu_popup_at_pointer(GTK_MENU(vd->popup), NULL);
930 vd->drop_list = list;
934 static void vd_dnd_drop_update(ViewDir *vd, gint x, gint y)
939 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vd->view), x, y,
940 &tpath, NULL, NULL, NULL))
942 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(vd->view), tpath);
943 gtk_tree_path_free(tpath);
946 if (fd != vd->drop_fd)
948 vd_color_set(vd, vd->drop_fd, FALSE);
949 vd_color_set(vd, fd, TRUE);
950 if (fd && vd->dnd_drop_update_func) vd->dnd_drop_update_func(vd);
956 void vd_dnd_drop_scroll_cancel(ViewDir *vd)
958 if (vd->drop_scroll_id)
960 g_source_remove(vd->drop_scroll_id);
961 vd->drop_scroll_id = 0;
965 static gboolean vd_auto_scroll_idle_cb(gpointer data)
967 ViewDir *vd = static_cast<ViewDir *>(data);
977 window = gtk_widget_get_window(vd->view);
978 seat = gdk_display_get_default_seat(gdk_window_get_display(window));
979 device = gdk_seat_get_pointer(seat);
980 gdk_window_get_device_position(window, device, &x, &y, NULL);
982 w = gdk_window_get_width(window);
983 h = gdk_window_get_height(window);
984 if (x >= 0 && x < w && y >= 0 && y < h)
986 vd_dnd_drop_update(vd, x, y);
990 vd->drop_scroll_id = 0;
994 static gboolean vd_auto_scroll_notify_cb(GtkWidget *UNUSED(widget), gint UNUSED(x), gint UNUSED(y), gpointer data)
996 ViewDir *vd = static_cast<ViewDir *>(data);
998 if (!vd->drop_fd || vd->drop_list) return FALSE;
1000 if (!vd->drop_scroll_id) vd->drop_scroll_id = g_idle_add(vd_auto_scroll_idle_cb, vd);
1005 static gboolean vd_dnd_drop_motion(GtkWidget *UNUSED(widget), GdkDragContext *context,
1006 gint x, gint y, guint time, gpointer data)
1008 ViewDir *vd = static_cast<ViewDir *>(data);
1010 vd->click_fd = NULL;
1012 if (gtk_drag_get_source_widget(context) == vd->view)
1014 /* from same window */
1015 gdk_drag_status(context, 0, time);
1020 gdk_drag_status(context, gdk_drag_context_get_suggested_action(context), time);
1023 vd_dnd_drop_update(vd, x, y);
1027 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vd->view));
1028 widget_auto_scroll_start(vd->view, adj, -1, -1, vd_auto_scroll_notify_cb, vd);
1034 static void vd_dnd_drop_leave(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context), guint UNUSED(time), gpointer data)
1036 ViewDir *vd = static_cast<ViewDir *>(data);
1038 if (vd->drop_fd != vd->click_fd) vd_color_set(vd, vd->drop_fd, FALSE);
1042 if (vd->dnd_drop_leave_func) vd->dnd_drop_leave_func(vd);
1045 void vd_dnd_init(ViewDir *vd)
1047 gtk_drag_source_set(vd->view, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
1048 dnd_file_drag_types, dnd_file_drag_types_count,
1049 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
1050 g_signal_connect(G_OBJECT(vd->view), "drag_data_get",
1051 G_CALLBACK(vd_dnd_get), vd);
1052 g_signal_connect(G_OBJECT(vd->view), "drag_begin",
1053 G_CALLBACK(vd_dnd_begin), vd);
1054 g_signal_connect(G_OBJECT(vd->view), "drag_end",
1055 G_CALLBACK(vd_dnd_end), vd);
1057 vd_dest_set(vd, TRUE);
1058 g_signal_connect(G_OBJECT(vd->view), "drag_data_received",
1059 G_CALLBACK(vd_dnd_drop_receive), vd);
1060 g_signal_connect(G_OBJECT(vd->view), "drag_motion",
1061 G_CALLBACK(vd_dnd_drop_motion), vd);
1062 g_signal_connect(G_OBJECT(vd->view), "drag_leave",
1063 G_CALLBACK(vd_dnd_drop_leave), vd);
1067 *----------------------------------------------------------------------------
1069 *----------------------------------------------------------------------------
1072 //void vd_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *UNUSED(push_in), gpointer data)
1074 //ViewDir *vd = static_cast<//ViewDir *>(data);
1075 //GtkTreeModel *store;
1077 //GtkTreePath *tpath;
1080 //if (!vd_find_row(vd, vd->click_fd, &iter)) return;
1081 //store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view));
1082 //tpath = gtk_tree_model_get_path(store, &iter);
1083 //tree_view_get_cell_clamped(GTK_TREE_VIEW(vd->view), tpath, 0, TRUE, x, y, &cw, &ch);
1084 //gtk_tree_path_free(tpath);
1086 //popup_menu_position_clamp(menu, x, y, 0);
1089 void vd_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *UNUSED(column), gpointer data)
1091 ViewDir *vd = static_cast<ViewDir *>(data);
1092 FileData *fd = vd_get_fd_from_tree_path(vd, tview, tpath);
1094 vd_select_row(vd, fd);
1097 static GdkColor *vd_color_shifted(GtkWidget *widget)
1099 static GdkColor color;
1100 static GtkWidget *done = NULL;
1106 style = gtk_widget_get_style(widget);
1107 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
1108 shift_color(&color, -1, 0);
1115 void vd_color_cb(GtkTreeViewColumn *UNUSED(tree_column), GtkCellRenderer *cell,
1116 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
1118 ViewDir *vd = static_cast<ViewDir *>(data);
1121 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1);
1122 g_object_set(G_OBJECT(cell),
1123 "cell-background-gdk", vd_color_shifted(vd->view),
1124 "cell-background-set", set, NULL);
1127 gboolean vd_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1129 ViewDir *vd = static_cast<ViewDir *>(data);
1131 FileData *fd = NULL;
1133 if (defined_mouse_buttons(widget, bevent, vd->layout))
1138 if (vd->type == DIRVIEW_LIST && !options->view_dir_list_single_click_enter)
1141 if (!vd->click_fd) return FALSE;
1142 vd_color_set(vd, vd->click_fd, FALSE);
1144 if (bevent->button != MOUSE_BUTTON_LEFT) return TRUE;
1146 if ((bevent->x != 0 || bevent->y != 0) &&
1147 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
1148 &tpath, NULL, NULL, NULL))
1150 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(widget), tpath);
1151 gtk_tree_path_free(tpath);
1154 if (fd && vd->click_fd == fd)
1156 vd_select_row(vd, vd->click_fd);
1162 gboolean vd_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
1164 ViewDir *vd = static_cast<ViewDir *>(data);
1165 gboolean ret = FALSE;
1169 case DIRVIEW_LIST: ret = vdlist_press_key_cb(widget, event, data); break;
1170 case DIRVIEW_TREE: ret = vdtree_press_key_cb(widget, event, data); break;
1176 gboolean vd_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
1178 ViewDir *vd = static_cast<ViewDir *>(data);
1179 gboolean ret = FALSE;
1183 NodeData *nd = NULL;
1184 GtkTreeModel *store;
1186 if (bevent->button == MOUSE_BUTTON_RIGHT)
1188 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, &tpath, NULL, NULL, NULL))
1190 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
1191 gtk_tree_model_get_iter(store, &iter, tpath);
1196 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1);
1200 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
1201 vd->click_fd = (nd) ? nd->fd : NULL;
1206 vd_color_set(vd, vd->click_fd, TRUE);
1210 vd->popup = vd_pop_menu(vd, vd->click_fd);
1211 gtk_menu_popup_at_pointer(GTK_MENU(vd->popup), NULL);
1218 case DIRVIEW_LIST: ret = vdlist_press_cb(widget, bevent, data); break;
1219 case DIRVIEW_TREE: ret = vdtree_press_cb(widget, bevent, data); break;
1225 static void vd_notify_cb(FileData *fd, NotifyType type, gpointer data)
1227 ViewDir *vd = static_cast<ViewDir *>(data);
1231 if (!S_ISDIR(fd->mode)) return; /* this gives correct results even on recently deleted files/directories */
1233 DEBUG_1("Notify vd: %s %04x", fd->path, type);
1235 base = remove_level_from_path(fd->path);
1237 if (vd->type == DIRVIEW_LIST)
1239 refresh = (fd == vd->dir_fd);
1243 refresh = (strcmp(base, vd->dir_fd->path) == 0);
1246 if ((type & NOTIFY_CHANGE) && fd->change)
1248 if (!refresh && fd->change->dest)
1250 gchar *dest_base = remove_level_from_path(fd->change->dest);
1251 refresh = (strcmp(dest_base, vd->dir_fd->path) == 0);
1255 if (!refresh && fd->change->source)
1257 gchar *source_base = remove_level_from_path(fd->change->source);
1258 refresh = (strcmp(source_base, vd->dir_fd->path) == 0);
1259 g_free(source_base);
1263 if (refresh) vd_refresh(vd);
1266 if (vd->type == DIRVIEW_TREE)
1269 FileData *base_fd = file_data_new_dir(base);
1271 if (vd_find_row(vd, base_fd, &iter))
1273 vdtree_populate_path_by_iter(vd, &iter, TRUE, vd->dir_fd);
1276 file_data_unref(base_fd);
1281 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */