From c3bc39aafc618f548e8a8132311f2485ce636549 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Sun, 8 Mar 2020 15:57:10 +0000 Subject: [PATCH] Fix #756: Set default option for file drag-drop, skipping "Move/Copy/Symlink" popup https://github.com/BestImageViewer/geeqie/issues/756 Additional option on Preferences/Behavior --- doc/docbook/GuideOptionsBehavior.xml | 12 +++++++ src/options.c | 1 + src/options.h | 1 + src/preferences.c | 49 ++++++++++++++++++++++++++++ src/rcfile.c | 2 ++ src/typedefs.h | 7 ++++ src/view_dir.c | 12 +++++++ 7 files changed, 84 insertions(+) diff --git a/doc/docbook/GuideOptionsBehavior.xml b/doc/docbook/GuideOptionsBehavior.xml index 6db8c46d..c6b1ca8e 100644 --- a/doc/docbook/GuideOptionsBehavior.xml +++ b/doc/docbook/GuideOptionsBehavior.xml @@ -180,6 +180,18 @@ This is the width and height of the icon generated from image and displayed when doing drag and drop actions. High resolution screens may require to increase this number. + + + Drag'n drop default action + + + When using drag and drop to copy or move files, the default action is to use a pop-up menu to permit you to select which action is to be taken. This option allows you to set the default action to either Copy or Move. + + + When using the pop-up menu, the menu will also include an option for a symbolic link and any other plugins that are defined as being a filter. If you set the default action to Copy or Move these additional options will not be available to you. + + + Copy path clipboard selection diff --git a/src/options.c b/src/options.c index 69dfe82f..3be69052 100644 --- a/src/options.c +++ b/src/options.c @@ -51,6 +51,7 @@ ConfOptions *init_options(ConfOptions *options) options->color_profile.render_intent = 0; options->dnd_icon_size = 48; + options->dnd_default_action = DND_ACTION_ASK; options->duplicates_similarity_threshold = 99; options->rot_invariant_sim = TRUE; options->sort_totals = FALSE; diff --git a/src/options.h b/src/options.h index 02ff8fac..5644929c 100644 --- a/src/options.h +++ b/src/options.h @@ -56,6 +56,7 @@ struct _ConfOptions gint open_recent_list_maxsize; gint dnd_icon_size; + DnDAction dnd_default_action; gint clipboard_selection; gboolean save_window_positions; diff --git a/src/preferences.c b/src/preferences.c index c0c38105..af755f97 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -378,6 +378,7 @@ static void config_window_apply(void) options->open_recent_list_maxsize = c_options->open_recent_list_maxsize; options->dnd_icon_size = c_options->dnd_icon_size; options->clipboard_selection = c_options->clipboard_selection; + options->dnd_default_action = c_options->dnd_default_action; options->metadata.save_in_image_file = c_options->metadata.save_in_image_file; options->metadata.save_legacy_IPTC = c_options->metadata.save_legacy_IPTC; @@ -551,6 +552,24 @@ static void quality_menu_cb(GtkWidget *combo, gpointer data) } } +static void dnd_default_action_selection_menu_cb(GtkWidget *combo, gpointer data) +{ + gint *option = data; + + switch (gtk_combo_box_get_active(GTK_COMBO_BOX(combo))) + { + case 0: + default: + *option = DND_ACTION_ASK; + break; + case 1: + *option = DND_ACTION_COPY; + break; + case 2: + *option = DND_ACTION_MOVE; + break; + } +} static void clipboard_selection_menu_cb(GtkWidget *combo, gpointer data) { gint *option = data; @@ -597,6 +616,33 @@ static void add_quality_menu(GtkWidget *table, gint column, gint row, const gcha gtk_widget_show(combo); } +static void add_dnd_default_action_selection_menu(GtkWidget *table, gint column, gint row, const gchar *text, DnDAction option, DnDAction *option_c) +{ + GtkWidget *combo; + gint current = 0; + + *option_c = option; + + pref_table_label(table, column, row, text, 0.0); + + combo = gtk_combo_box_text_new(); + + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Ask")); + if (option == DND_ACTION_ASK) current = 0; + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Copy")); + if (option == DND_ACTION_COPY) current = 1; + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Move")); + if (option == DND_ACTION_MOVE) current = 2; + + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), current); + + g_signal_connect(G_OBJECT(combo), "changed", + G_CALLBACK(dnd_default_action_selection_menu_cb), option_c); + + gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1, GTK_SHRINK, 0, 0, 0); + gtk_widget_show(combo); +} + static void add_clipboard_selection_menu(GtkWidget *table, gint column, gint row, const gchar *text, gint option, gint *option_c) { @@ -3273,6 +3319,9 @@ static void config_tab_behavior(GtkWidget *notebook) pref_spin_new_int(group, _("Drag'n drop icon size"), NULL, 16, 256, 16, options->dnd_icon_size, &c_options->dnd_icon_size); + table = pref_table_new(group, 2, 1, FALSE, FALSE); + add_dnd_default_action_selection_menu(table, 0, 0, _("Drag`n drop default action:"), options->dnd_default_action, &c_options->dnd_default_action); + table = pref_table_new(group, 2, 1, FALSE, FALSE); add_clipboard_selection_menu(table, 0, 0, _("Copy path clipboard selection:"), options->clipboard_selection, &c_options->clipboard_selection); diff --git a/src/rcfile.c b/src/rcfile.c index aba8702c..899e9c2a 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -334,6 +334,7 @@ static void write_global_attributes(GString *outstr, gint indent) WRITE_NL(); WRITE_CHAR(*options, image_l_click_video_editor); WRITE_NL(); WRITE_INT(*options, open_recent_list_maxsize); WRITE_NL(); WRITE_INT(*options, dnd_icon_size); + WRITE_NL(); WRITE_UINT(*options, dnd_default_action); WRITE_NL(); WRITE_BOOL(*options, place_dialogs_under_mouse); WRITE_NL(); WRITE_INT(*options, clipboard_selection); @@ -748,6 +749,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar ** if (READ_INT(*options, open_recent_list_maxsize)) continue; if (READ_INT(*options, dnd_icon_size)) continue; + if (READ_UINT(*options, dnd_default_action)) continue; if (READ_BOOL(*options, place_dialogs_under_mouse)) continue; if (READ_INT(*options, clipboard_selection)) continue; diff --git a/src/typedefs.h b/src/typedefs.h index ce58f509..fab68a8e 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -79,6 +79,13 @@ typedef enum { SORT_CLASS } SortType; +/* drag and drop default action */ +typedef enum { + DND_ACTION_ASK, + DND_ACTION_COPY, + DND_ACTION_MOVE +} DnDAction; + typedef enum { ALTER_NONE, /* do nothing */ ALTER_ROTATE_90, diff --git a/src/view_dir.c b/src/view_dir.c index 0fcdf27d..d7ac1207 100644 --- a/src/view_dir.c +++ b/src/view_dir.c @@ -888,6 +888,18 @@ static void vd_dnd_drop_receive(GtkWidget *widget, #else action = (gdk_drag_context_get_actions(context)); #endif + if (action != GDK_ACTION_COPY && action != GDK_ACTION_MOVE) + { + if (options->dnd_default_action == DND_ACTION_COPY) + { + action = GDK_ACTION_COPY; + } + else if (options->dnd_default_action == DND_ACTION_MOVE) + { + action = GDK_ACTION_MOVE; + } + } + if (action == GDK_ACTION_COPY) { file_util_copy_simple(list, fd->path, vd->widget); -- 2.20.1