[gnome-commander] GnomeCmdFileList: prompt to confirm drag & drop operations



commit e80bbc99f8fe9c3f68950c7c8431cd322460058e
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Wed Aug 10 21:42:28 2011 +0200

    GnomeCmdFileList: prompt to confirm drag & drop operations

 NEWS                            |    1 +
 doc/C/gnome-commander.xml       |   10 +++
 src/gnome-cmd-data.cc           |    3 +
 src/gnome-cmd-data.h            |    1 +
 src/gnome-cmd-file-list.cc      |  134 +++++++++++++++++++++++++++------------
 src/gnome-cmd-file-list.h       |    1 +
 src/gnome-cmd-options-dialog.cc |   14 ++++
 7 files changed, 123 insertions(+), 41 deletions(-)
---
diff --git a/NEWS b/NEWS
index b35db52..8e87116 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ New features:
  * User defined LS_COLORS colours
  * Enhanced file name matching in quick search
  * Open terminal with administrator privileges
+ * Prompt to confirm drag & drop operations
  * Context popup menu for internal viewer
  * --config-dir command line option for customized location of config files
  * New colour theme: green tiger
diff --git a/doc/C/gnome-commander.xml b/doc/C/gnome-commander.xml
index cb0162c..0208d56 100644
--- a/doc/C/gnome-commander.xml
+++ b/doc/C/gnome-commander.xml
@@ -7326,6 +7326,13 @@
                                     <entry><para></para></entry>
                                 </row>
                                 <row valign="top">
+                                    <entry><para></para></entry>
+                                    <entry><para>confirm_mouse_dnd</para></entry>
+                                    <entry><para>boolean</para></entry>
+                                    <entry><para>If enabled, confirm drag &amp; drop operations</para></entry>
+                                    <entry><para></para></entry>
+                                </row>
+                                <row valign="top">
                                     <entry><para>[colors]</para></entry>
                                     <entry><para>curs_bg</para></entry>
                                     <entry><para></para></entry>
@@ -7641,6 +7648,9 @@
                             <para>Open terminal with administrator privileges</para>
                         </listitem>
                         <listitem>
+                            <para>Prompt to confirm drag &amp; drop operations</para>
+                        </listitem>
+                        <listitem>
                             <para>Context popup menu for internal viewer</para>
                         </listitem>
                         <listitem>
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 2b039f8..97a5a8b 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -880,6 +880,7 @@ GnomeCmdData::GnomeCmdData(): search_defaults(selections)
     confirm_delete = TRUE;
     confirm_copy_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_QUERY;
     confirm_move_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_QUERY;
+    confirm_mouse_dnd = TRUE;
     left_mouse_button_mode = LEFT_BUTTON_OPENS_WITH_DOUBLE_CLICK;
     left_mouse_button_unselects = TRUE;
     middle_mouse_button_mode = MIDDLE_BUTTON_GOES_UP_DIR;
@@ -1090,6 +1091,7 @@ void GnomeCmdData::load()
     confirm_delete = gnome_cmd_data_get_bool ("/confirm/delete", TRUE);
     confirm_copy_overwrite = (GnomeCmdConfirmOverwriteMode) gnome_cmd_data_get_int ("/confirm/copy_overwrite", GNOME_CMD_CONFIRM_OVERWRITE_QUERY);
     confirm_move_overwrite = (GnomeCmdConfirmOverwriteMode) gnome_cmd_data_get_int ("/confirm/move_overwrite", GNOME_CMD_CONFIRM_OVERWRITE_QUERY);
+    confirm_mouse_dnd = gnome_cmd_data_get_bool ("/confirm/confirm_mouse_dnd", TRUE);
 
     filter_settings.file_types[GNOME_VFS_FILE_TYPE_UNKNOWN] = gnome_cmd_data_get_bool ("/options/show_unknown", FALSE);
     filter_settings.file_types[GNOME_VFS_FILE_TYPE_REGULAR] = gnome_cmd_data_get_bool ("/options/show_regular", FALSE);
@@ -1523,6 +1525,7 @@ void GnomeCmdData::save()
     gnome_cmd_data_set_bool   ("/confirm/delete", confirm_delete);
     gnome_cmd_data_set_int    ("/confirm/copy_overwrite", confirm_copy_overwrite);
     gnome_cmd_data_set_int    ("/confirm/move_overwrite", confirm_move_overwrite);
+    gnome_cmd_data_set_bool   ("/confirm/confirm_mouse_dnd", confirm_mouse_dnd);
 
     gnome_cmd_data_set_bool   ("/options/show_unknown", filter_settings.file_types[GNOME_VFS_FILE_TYPE_UNKNOWN]);
     gnome_cmd_data_set_bool   ("/options/show_regular", filter_settings.file_types[GNOME_VFS_FILE_TYPE_REGULAR]);
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 41660b7..0c58327 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -199,6 +199,7 @@ struct GnomeCmdData
     gboolean                     confirm_delete;
     GnomeCmdConfirmOverwriteMode confirm_copy_overwrite;
     GnomeCmdConfirmOverwriteMode confirm_move_overwrite;
+    gboolean                     confirm_mouse_dnd;
     LeftMouseButtonMode          left_mouse_button_mode;
     gboolean                     left_mouse_button_unselects;
     MiddleMouseButtonMode        middle_mouse_button_mode;
diff --git a/src/gnome-cmd-file-list.cc b/src/gnome-cmd-file-list.cc
index 10c2568..793559e 100644
--- a/src/gnome-cmd-file-list.cc
+++ b/src/gnome-cmd-file-list.cc
@@ -171,8 +171,12 @@ class GnomeCmdFileList::Private
     GtkWidget *con_open_dialog_label;
     GtkWidget *con_open_dialog_pbar;
 
+    GtkItemFactory *ifac;
+
     Private(GnomeCmdFileList *fl);
     ~Private();
+
+    static void on_dnd_popup_menu (GnomeCmdFileList *fl, GnomeVFSXferOptions xferOptions, GtkWidget *widget);
 };
 
 
@@ -205,11 +209,39 @@ GnomeCmdFileList::Private::Private(GnomeCmdFileList *fl)
 
     for (gint i=0; i<NUM_COLUMNS; i++)
         gtk_clist_set_column_resizeable (*fl, i, TRUE);
+
+    static GtkItemFactoryEntry items[] = {
+                                            {_("/_Copy here"), "<control>", (GtkItemFactoryCallback) on_dnd_popup_menu, GNOME_VFS_XFER_RECURSIVE, "<StockItem>", GTK_STOCK_COPY},
+                                            {_("/_Move here"), "<shift>", (GtkItemFactoryCallback) on_dnd_popup_menu, GNOME_VFS_XFER_REMOVESOURCE, "<StockItem>", GTK_STOCK_COPY},
+                                            {_("/_Link here"), "<control><shift>", (GtkItemFactoryCallback) on_dnd_popup_menu,GNOME_VFS_XFER_LINK_ITEMS,"<StockItem>", GTK_STOCK_CONVERT},
+                                            {"/", NULL, NULL, 0, "<Separator>"},
+                                            {_("/C_ancel"), "Esc", (GtkItemFactoryCallback) on_dnd_popup_menu, 0, "<StockItem>", GTK_STOCK_CANCEL}
+                                         };
+
+    ifac = gtk_item_factory_new (GTK_TYPE_MENU, "<main>", NULL);
+    gtk_item_factory_create_items (ifac, G_N_ELEMENTS (items), items, fl);
 }
 
 
 GnomeCmdFileList::Private::~Private()
 {
+    g_object_unref (ifac);
+}
+
+
+void GnomeCmdFileList::Private::on_dnd_popup_menu (GnomeCmdFileList *fl, GnomeVFSXferOptions xferOptions, GtkWidget *widget)
+{
+    g_return_if_fail (GNOME_CMD_IS_FILE_LIST (fl));
+
+    gpointer *data = (gpointer *) gtk_item_factory_popup_data_from_widget (widget);
+    GList *uri_list = (GList *) data[0];
+    GnomeCmdDir *to = (GnomeCmdDir *) data[1];
+
+    if (xferOptions)
+    {
+        data[0] = NULL;
+        fl->drop_files(xferOptions,uri_list,to);
+    }
 }
 
 
@@ -2731,13 +2763,52 @@ static void unref_uri_list (GList *list)
 }
 
 
+void free_dnd_popup_data (gpointer *data)
+{
+    if (data)
+    {
+        GList *uri_list = (GList *) data[0];
+        unref_uri_list (uri_list);
+    }
+
+    g_free (data);
+}
+
+
 static void drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint32 time, GnomeCmdFileList *fl)
 {
     GtkCList *clist = *fl;
-    GnomeCmdFile *f;
-    GnomeCmdDir *to, *cwd;
-    GList *uri_list = NULL;
-    gchar *to_fn = NULL;
+
+    // find the row that the file was dropped on
+    y -= clist->column_title_area.height - GTK_CONTAINER (clist)->border_width;
+    if (y < 0) return;
+
+    GnomeCmdFile *f = fl->get_file_at_row (gnome_cmd_clist_get_row (*fl, x, y));
+    GnomeCmdDir *to = fl->cwd;
+
+    // the drop was over a directory in the list, which means that the
+    // xfer should be done to that directory instead of the current one in the list
+    if (f && f->info->type==GNOME_VFS_FILE_TYPE_DIRECTORY)
+        to = f->is_dotdot ? gnome_cmd_dir_get_parent (to) : gnome_cmd_dir_get_child (to, f->info->name);
+
+    // transform the drag data to a list with URIs
+    GList *uri_list = strings_to_uris ((gchar *) selection_data->data);
+
+    if (gnome_cmd_data.confirm_mouse_dnd)
+    {
+        gpointer *arr = g_new (gpointer, 2);
+
+        arr[0] = uri_list;
+        arr[1] = to;
+
+        int x, y;
+
+        gdk_display_get_pointer (gdk_display_get_default (), NULL, &x, &y, NULL);
+        gtk_item_factory_popup_with_data (fl->priv->ifac, arr, (GDestroyNotify) free_dnd_popup_data, x, y, 0, time);
+
+        return;
+    }
+
     GnomeVFSXferOptions xferOptions;
 
     // find out what operation to perform
@@ -2760,43 +2831,7 @@ static void drag_data_received (GtkWidget *widget, GdkDragContext *context, gint
             return;
     }
 
-
-    // Find the row that the file was dropped on
-    y -= (clist->column_title_area.height - GTK_CONTAINER (clist)->border_width);
-    if (y < 0) return;
-
-    int row = gnome_cmd_clist_get_row (*fl, x, y);
-
-    // Transform the drag data to a list with uris
-    uri_list = strings_to_uris ((gchar *) selection_data->data);
-
-    if (g_list_length (uri_list) == 1)
-        to_fn = gnome_vfs_unescape_string (gnome_vfs_uri_extract_short_name ((GnomeVFSURI *) uri_list->data), 0);
-
-    f = fl->get_file_at_row(row);
-    cwd = fl->cwd;
-
-    if (f && f->info->type == GNOME_VFS_FILE_TYPE_DIRECTORY)
-    {
-        // the drop was over a directory in the list, which means that the
-        // xfer should be done to that directory instead of the current one in the list
-        to = f->is_dotdot ? gnome_cmd_dir_get_parent (cwd) : gnome_cmd_dir_get_child (cwd, f->info->name);
-    }
-    else
-        to = cwd;
-
-    g_return_if_fail (GNOME_CMD_IS_DIR (to));
-
-    // start the xfer
-    gnome_cmd_xfer_uris_start (uri_list,
-                               gnome_cmd_dir_ref (to),
-                               NULL,
-                               NULL,
-                               to_fn,
-                               xferOptions,
-                               GNOME_VFS_XFER_OVERWRITE_MODE_QUERY,
-                               GTK_SIGNAL_FUNC (unref_uri_list),
-                               uri_list);
+    fl->drop_files(xferOptions,uri_list,to);
 }
 
 
@@ -2878,6 +2913,23 @@ void GnomeCmdFileList::init_dnd()
 }
 
 
+void GnomeCmdFileList::drop_files(GnomeVFSXferOptions xferOptions, GList *uri_list, GnomeCmdDir *dir)
+{
+    g_return_if_fail (GNOME_CMD_IS_DIR (dir));
+
+    // start the xfer
+    gnome_cmd_xfer_uris_start (uri_list,
+                               gnome_cmd_dir_ref (dir),
+                               NULL,
+                               NULL,
+                               g_list_length (uri_list) == 1 ? gnome_vfs_unescape_string (gnome_vfs_uri_extract_short_name ((GnomeVFSURI *) uri_list->data), 0) : NULL,
+                               xferOptions,
+                               GNOME_VFS_XFER_OVERWRITE_MODE_QUERY,
+                               GTK_SIGNAL_FUNC (unref_uri_list),
+                               uri_list);
+}
+
+
 XML::xstream &operator << (XML::xstream &xml, GnomeCmdFileList &fl)
 {
     return xml << XML::tag("Tab") << XML::attr("dir") << GNOME_CMD_FILE (fl.cwd)->get_real_path() << XML::attr("sort") << fl.get_sort_column() << XML::attr("asc") << fl.get_sort_order() << XML::attr("lock") << fl.locked << XML::endtag();
diff --git a/src/gnome-cmd-file-list.h b/src/gnome-cmd-file-list.h
index 2714109..74da64a 100644
--- a/src/gnome-cmd-file-list.h
+++ b/src/gnome-cmd-file-list.h
@@ -181,6 +181,7 @@ struct GnomeCmdFileList
     gboolean key_pressed(GdkEventKey *event);
 
     void init_dnd();
+    void drop_files(GnomeVFSXferOptions xferOptions, GList *uri_list, GnomeCmdDir *dir);
 
     friend XML::xstream &operator << (XML::xstream &xml, GnomeCmdFileList &fl);
 };
diff --git a/src/gnome-cmd-options-dialog.cc b/src/gnome-cmd-options-dialog.cc
index ec69de2..0990169 100644
--- a/src/gnome-cmd-options-dialog.cc
+++ b/src/gnome-cmd-options-dialog.cc
@@ -947,6 +947,17 @@ static GtkWidget *create_confirmation_tab (GtkWidget *parent)
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
 
 
+    /* Drag and Drop options
+     */
+    cat_box = create_vbox (parent, FALSE, 0);
+    cat = create_category (parent, cat_box, _("Drag and Drop"));
+    gtk_box_pack_start (GTK_BOX (vbox), cat, FALSE, TRUE, 0);
+
+    check = create_check (parent, _("Confirm mouse operation"), "confirm_mouse_dnd_check");
+    gtk_box_pack_start (GTK_BOX (cat_box), check, FALSE, TRUE, 0);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), gnome_cmd_data.confirm_mouse_dnd);
+
+
     return frame;
 }
 
@@ -960,6 +971,7 @@ inline void store_confirmation_options (GtkWidget *dialog)
     GtkWidget *confirm_move_silent = lookup_widget (dialog, "move_overwrite_silently");
     GtkWidget *confirm_move_query = lookup_widget (dialog, "move_overwrite_query");
     GtkWidget *confirm_move_skip_all = lookup_widget (dialog, "move_overwrite_skip_all");
+    GtkWidget *confirm_mouse_dnd_check = lookup_widget (dialog, "confirm_mouse_dnd_check");
 
     gnome_cmd_data.confirm_delete = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (confirm_delete_check));
 
@@ -976,6 +988,8 @@ inline void store_confirmation_options (GtkWidget *dialog)
         gnome_cmd_data.confirm_move_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_QUERY;
     else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (confirm_move_skip_all)))
         gnome_cmd_data.confirm_move_overwrite = GNOME_CMD_CONFIRM_OVERWRITE_SKIP_ALL;
+
+    gnome_cmd_data.confirm_mouse_dnd = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (confirm_mouse_dnd_check));
 }
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]