Ref #598: Option to set default drag-drop behaviour to local folder as 'move' not...
[geeqie.git] / src / view_dir.c
index a9f473f..7c2d192 100644 (file)
@@ -1,12 +1,21 @@
 /*
- * Geeqie
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: Laurent Monin
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include "main.h"
@@ -22,6 +31,7 @@
 #include "ui_fileops.h"
 #include "ui_tree_edit.h"
 #include "ui_menu.h"
+#include "ui_misc.h"
 #include "utilops.h"
 #include "uri_utils.h"
 #include "view_dir_list.h"
@@ -31,7 +41,7 @@
 static PixmapFolders *folder_icons_new(GtkWidget *widget)
 {
        PixmapFolders *pf = g_new0(PixmapFolders, 1);
-       
+
 #if 1
        GtkIconSize size = GTK_ICON_SIZE_MENU;
 
@@ -40,6 +50,8 @@ static PixmapFolders *folder_icons_new(GtkWidget *widget)
        pf->open   = gtk_widget_render_icon(widget, GTK_STOCK_OPEN, size, NULL);
        pf->deny   = gtk_widget_render_icon(widget, GTK_STOCK_STOP, size, NULL);
        pf->parent = gtk_widget_render_icon(widget, GTK_STOCK_GO_UP, size, NULL);
+       /* FIXME: this is not a suitable icon */
+       pf->link = gtk_widget_render_icon(widget, GTK_STOCK_REDO, size, NULL);
 #else
        /* GQView legacy icons */
        pf->close  = pixbuf_inline(PIXBUF_INLINE_FOLDER_CLOSED);
@@ -58,6 +70,7 @@ static void folder_icons_free(PixmapFolders *pf)
        g_object_unref(pf->open);
        g_object_unref(pf->deny);
        g_object_unref(pf->parent);
+       g_object_unref(pf->link);
 
        g_free(pf);
 }
@@ -268,7 +281,7 @@ static gboolean vd_rename_cb(TreeEditData *td, const gchar *old, const gchar *ne
        g_free(base);
 
        file_util_rename_dir(fd, new_path, vd->view, vd_rename_finished_cb, vd);
-       
+
        g_free(new_path);
 
        return FALSE;
@@ -366,9 +379,9 @@ static void vd_drop_menu_filter_cb(GtkWidget *widget, gpointer data)
        const gchar *path;
        GList *list;
        const gchar *key;
-       
+
        if (!vd->drop_fd) return;
-       
+
        key = g_object_get_data(G_OBJECT(widget), "filter_key");
 
        path = vd->drop_fd->path;
@@ -404,13 +417,13 @@ GtkWidget *vd_drop_menu(ViewDir *vd, gint active)
                const EditorDescription *editor = work->data;
                gchar *key;
                work = work->next;
-               
+
                if (!editor_is_filter(editor->key)) continue;
                key = g_strdup(editor->key);
                item = menu_item_add_sensitive(menu, editor->name, active, G_CALLBACK(vd_drop_menu_filter_cb), vd);
                g_object_set_data_full(G_OBJECT(item), "filter_key", key, vd_drop_menu_edit_item_free);
                }
-       
+
        g_list_free(editors_list);
 
        menu_item_add_divider(menu);
@@ -464,7 +477,7 @@ static void vd_pop_menu_slide_rec_cb(GtkWidget *widget, gpointer data)
        if (!vd->layout) return;
        if (!vd->click_fd) return;
 
-       list = filelist_recursive(vd->click_fd);
+       list = filelist_recursive_full(vd->click_fd, vd->layout->sort_method, vd->layout->sort_ascend);
 
        layout_image_slideshow_stop(vd->layout);
        layout_image_slideshow_start_from_list(vd->layout, list);
@@ -487,7 +500,7 @@ static void vd_pop_menu_dupe(ViewDir *vd, gint recursive)
                list = filelist_filter(list, FALSE);
                }
 
-       dw = dupe_window_new(DUPE_MATCH_NAME);
+       dw = dupe_window_new();
        dupe_window_add_files(dw, list, recursive);
 
        filelist_free(list);
@@ -519,7 +532,16 @@ static void vd_pop_menu_copy_path_cb(GtkWidget *widget, gpointer data)
 
        if (!vd->click_fd) return;
 
-       file_util_copy_path_to_clipboard(vd->click_fd);
+       file_util_copy_path_to_clipboard(vd->click_fd, TRUE);
+}
+
+static void vd_pop_menu_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
+{
+       ViewDir *vd = data;
+
+       if (!vd->click_fd) return;
+
+       file_util_copy_path_to_clipboard(vd->click_fd, FALSE);
 }
 
 static void vd_pop_submenu_dir_view_as_cb(GtkWidget *widget, gpointer data)
@@ -604,7 +626,6 @@ static void vd_pop_menu_rename_cb(GtkWidget *widget, gpointer data)
 GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
 {
        GtkWidget *menu;
-       GtkWidget *item;
        gboolean active;
        gboolean rename_delete_active = FALSE;
        gboolean new_folder_active = FALSE;
@@ -665,20 +686,23 @@ GtkWidget *vd_pop_menu(ViewDir *vd, FileData *fd)
 
        menu_item_add_sensitive(menu, _("_Rename..."), rename_delete_active,
                                G_CALLBACK(vd_pop_menu_rename_cb), vd);
-       menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, rename_delete_active,
-                                     G_CALLBACK(vd_pop_menu_delete_cb), vd);
 
        menu_item_add(menu, _("_Copy path"),
                      G_CALLBACK(vd_pop_menu_copy_path_cb), vd);
 
+       menu_item_add(menu, _("_Copy path unquoted"),
+                     G_CALLBACK(vd_pop_menu_copy_path_unquoted_cb), vd);
+
+       menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, rename_delete_active,
+                                     G_CALLBACK(vd_pop_menu_delete_cb), vd);
        menu_item_add_divider(menu);
 
 
-       item = menu_item_add_radio(menu, _("View as _List"), GINT_TO_POINTER(DIRVIEW_LIST), vd->type == DIRVIEW_LIST,
-                                           G_CALLBACK(vd_pop_submenu_dir_view_as_cb), vd);
+       menu_item_add_radio(menu, _("View as _List"), GINT_TO_POINTER(DIRVIEW_LIST), vd->type == DIRVIEW_LIST,
+                        G_CALLBACK(vd_pop_submenu_dir_view_as_cb), vd);
 
-       item = menu_item_add_radio(menu, _("View as _Tree"), GINT_TO_POINTER(DIRVIEW_TREE), vd->type == DIRVIEW_TREE,
-                                           G_CALLBACK(vd_pop_submenu_dir_view_as_cb), vd);
+       menu_item_add_radio(menu, _("View as _Tree"), GINT_TO_POINTER(DIRVIEW_TREE), vd->type == DIRVIEW_TREE,
+                        G_CALLBACK(vd_pop_submenu_dir_view_as_cb), vd);
 
        menu_item_add_divider(menu);
 
@@ -728,8 +752,6 @@ static void vd_dnd_get(GtkWidget *widget, GdkDragContext *context,
 {
        ViewDir *vd = data;
        GList *list;
-       gchar *uritext = NULL;
-       gint length = 0;
 
        if (!vd->click_fd) return;
 
@@ -738,16 +760,10 @@ static void vd_dnd_get(GtkWidget *widget, GdkDragContext *context,
                case TARGET_URI_LIST:
                case TARGET_TEXT_PLAIN:
                        list = g_list_prepend(NULL, vd->click_fd);
-                       uritext = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN));
+                       uri_selection_data_set_uris_from_filelist(selection_data, list);
                        g_list_free(list);
                        break;
                }
-       if (uritext)
-               {
-               gtk_selection_data_set(selection_data, selection_data->target,
-                                      8, (guchar *)uritext, length);
-               g_free(uritext);
-               }
 }
 
 static void vd_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
@@ -764,7 +780,7 @@ static void vd_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data
 
        vd_color_set(vd, vd->click_fd, FALSE);
 
-       if (vd->type == DIRVIEW_LIST && context->action == GDK_ACTION_MOVE)
+       if (vd->type == DIRVIEW_LIST && gdk_drag_context_get_selected_action(context) == GDK_ACTION_MOVE)
                {
                vd_refresh(vd);
                }
@@ -779,6 +795,8 @@ static void vd_dnd_drop_receive(GtkWidget *widget,
        ViewDir *vd = data;
        GtkTreePath *tpath;
        FileData *fd = NULL;
+       GdkDragAction action;
+       GdkModifierType mask;
 
        vd->click_fd = NULL;
 
@@ -797,7 +815,7 @@ static void vd_dnd_drop_receive(GtkWidget *widget,
                gint active;
                gboolean done = FALSE;
 
-               list = uri_filelist_from_text((gchar *)selection_data->data, TRUE);
+               list = uri_filelist_from_gtk_selection_data(selection_data);
                if (!list) return;
 
                active = access_file(fd->path, W_OK | X_OK);
@@ -806,13 +824,30 @@ static void vd_dnd_drop_receive(GtkWidget *widget,
 
                if (active)
                        {
-                       if (context->actions == GDK_ACTION_COPY)
+/* FIXME: With GTK2 gdk_drag_context_get_actions() shows the state of the
+ * shift and control keys during the drag operation. With GTK3 this is not
+ * so. This is a workaround.
+ */
+#if GTK_CHECK_VERSION(3,0,0)
+                       gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, &mask);
+                       if (mask & GDK_CONTROL_MASK)
+                               {
+                               action = GDK_ACTION_COPY;
+                               }
+                       else if (mask & GDK_SHIFT_MASK)
+                               {
+                               action = GDK_ACTION_MOVE;
+                               }
+#else
+                       action = (gdk_drag_context_get_actions(context));
+#endif
+                       if (action == GDK_ACTION_COPY)
                                {
                                file_util_copy_simple(list, fd->path, vd->widget);
                                done = TRUE;
                                list = NULL;
                                }
-                       else if (context->actions == GDK_ACTION_MOVE)
+                       else if (action == GDK_ACTION_MOVE)
                                {
                                file_util_move_simple(list, fd->path, vd->widget);
                                done = TRUE;
@@ -865,6 +900,10 @@ void vd_dnd_drop_scroll_cancel(ViewDir *vd)
 static gboolean vd_auto_scroll_idle_cb(gpointer data)
 {
        ViewDir *vd = data;
+#if GTK_CHECK_VERSION(3,0,0)
+       GdkDeviceManager *device_manager;
+       GdkDevice *device;
+#endif
 
        if (vd->drop_fd)
                {
@@ -872,9 +911,16 @@ static gboolean vd_auto_scroll_idle_cb(gpointer data)
                gint x, y;
                gint w, h;
 
-               window = vd->view->window;
+               window = gtk_widget_get_window(vd->view);
+#if GTK_CHECK_VERSION(3,0,0)
+               device_manager = gdk_display_get_device_manager(gdk_window_get_display(window));
+               device = gdk_device_manager_get_client_pointer(device_manager);
+               gdk_window_get_device_position(window, device, &x, &y, NULL);
+#else
                gdk_window_get_pointer(window, &x, &y, NULL);
-               gdk_drawable_get_size(window, &w, &h);
+#endif
+               w = gdk_window_get_width(window);
+               h = gdk_window_get_height(window);
                if (x >= 0 && x < w && y >= 0 && y < h)
                        {
                        vd_dnd_drop_update(vd, x, y);
@@ -911,7 +957,7 @@ static gboolean vd_dnd_drop_motion(GtkWidget *widget, GdkDragContext *context,
                }
        else
                {
-               gdk_drag_status(context, context->suggested_action, time);
+               gdk_drag_status(context, gdk_drag_context_get_suggested_action(context), time);
                }
 
        vd_dnd_drop_update(vd, x, y);
@@ -1024,6 +1070,14 @@ gboolean vd_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
        GtkTreePath *tpath;
        FileData *fd = NULL;
 
+       if (defined_mouse_buttons(widget, bevent, vd->layout))
+               {
+               return TRUE;
+               }
+
+       if (vd->type == DIRVIEW_LIST && !options->view_dir_list_single_click_enter)
+               return FALSE;
+
        if (!vd->click_fd) return FALSE;
        vd_color_set(vd, vd->click_fd, FALSE);
 
@@ -1064,6 +1118,15 @@ gboolean vd_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
        ViewDir *vd = data;
        gboolean ret = FALSE;
 
+       if (bevent->button == MOUSE_BUTTON_RIGHT)
+               {
+               vd->popup = vd_pop_menu(vd, vd->click_fd);
+               gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL,
+                              bevent->button, bevent->time);
+
+               return TRUE;
+               }
+
        switch (vd->type)
        {
        case DIRVIEW_LIST: ret = vdlist_press_cb(widget, bevent, data); break;
@@ -1110,7 +1173,7 @@ static void vd_notify_cb(FileData *fd, NotifyType type, gpointer data)
                                g_free(source_base);
                                }
                        }
-               
+
                if (refresh) vd_refresh(vd);
                }