[gtk+] testnotebookdnd: Defer deletion to an idle



commit 34c29d8d3cfd85132a7e8c333ffb4353771cfe64
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 30 09:20:04 2015 -0500

    testnotebookdnd: Defer deletion to an idle
    
    The code here was always a bit buggy: We removed the tab from
    the notebook in a ::drag-data-received handler. But with
    GTK_DEST_DEFAULT_DROP, that signal is emitted before we inform
    the source side that the drag is finished. With its improved drag
    handling, GtkNotebook now interprets this as a 'spontaneous'
    removal of the tab being dragged, and cancels the drag, leading
    to an unwanted cancel animation.
    
    The easiest fix is to just defer the tab removal to an idle.

 tests/testnotebookdnd.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c
index 47bcc58..1bdd57e 100644
--- a/tests/testnotebookdnd.c
+++ b/tests/testnotebookdnd.c
@@ -119,6 +119,20 @@ on_notebook_drag_begin (GtkWidget      *widget,
     }
 }
 
+static gboolean
+remove_in_idle (gpointer data)
+{
+  GtkWidget *child = data;
+  GtkWidget *parent = gtk_widget_get_parent (child);
+  GtkWidget *tab_label;
+
+  tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (parent), child);
+  g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
+  gtk_container_remove (GTK_CONTAINER (parent), child);
+
+  return G_SOURCE_REMOVE;
+}
+
 static void
 on_button_drag_data_received (GtkWidget        *widget,
                               GdkDragContext   *context,
@@ -129,16 +143,11 @@ on_button_drag_data_received (GtkWidget        *widget,
                               guint             time,
                               gpointer          user_data)
 {
-  GtkWidget *source, *tab_label;
   GtkWidget **child;
 
-  source = gtk_drag_get_source_widget (context);
   child = (void*) gtk_selection_data_get_data (data);
 
-  tab_label = gtk_notebook_get_tab_label (GTK_NOTEBOOK (source), *child);
-  g_print ("Removing tab: %s\n", gtk_label_get_text (GTK_LABEL (tab_label)));
-
-  gtk_container_remove (GTK_CONTAINER (source), *child);
+  g_idle_add (remove_in_idle, *child);
 }
 
 static GtkWidget*
@@ -226,7 +235,7 @@ create_trash_button (void)
 {
   GtkWidget *button;
 
-  button = gtk_button_new_with_label ("_Delete");
+  button = gtk_button_new_with_mnemonic ("_Delete");
 
   gtk_drag_dest_set (button,
                      GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,


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