Disconnect clip signal handlers when a syntax window is destroyed
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 26 Sep 2010 10:13:35 +0000 (12:13 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 29 Sep 2010 19:58:20 +0000 (21:58 +0200)
src/ui/gui/psppire-syntax-window.c
src/ui/gui/psppire-syntax-window.h

index 86d1db7664f7dc8f19a516f3f7333f2d5dd14823..ccf94e7bf2f0298b7f38c9ca95b07905f744e07c 100644 (file)
@@ -99,10 +99,41 @@ psppire_syntax_window_finalize (GObject *object)
 }
 
 
+static void
+psppire_syntax_window_dispose (GObject *obj)
+{
+  PsppireSyntaxWindow *sw = (PsppireSyntaxWindow *)obj;
+
+  GtkClipboard *clip_selection;
+  GtkClipboard *clip_primary;
+
+  if (sw->dispose_has_run)
+    return;
+
+  clip_selection = gtk_widget_get_clipboard (GTK_WIDGET (sw), GDK_SELECTION_CLIPBOARD);
+  clip_primary =   gtk_widget_get_clipboard (GTK_WIDGET (sw), GDK_SELECTION_PRIMARY);
+
+  g_signal_handler_disconnect (clip_primary, sw->sel_handler);
+
+  g_signal_handler_disconnect (clip_selection, sw->ps_handler);
+
+  /* Make sure dispose does not run twice. */
+  sw->dispose_has_run = TRUE;
+
+  /* Chain up to the parent class */
+  G_OBJECT_CLASS (parent_class)->dispose (obj);
+}
+
+
+
 static void
 psppire_syntax_window_class_init (PsppireSyntaxWindowClass *class)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+
   parent_class = g_type_class_peek_parent (class);
+
+  gobject_class->dispose = psppire_syntax_window_dispose;
 }
 
 
@@ -284,8 +315,12 @@ on_edit_paste (PsppireSyntaxWindow *sw)
                                  sw);
 }
 
+
+/* Check to see if CLIP holds a target which we know how to paste,
+   and set the sensitivity of the Paste action accordingly.
+ */
 static void
-on_owner_change (GtkClipboard *clip, GdkEventOwnerChange *event, gpointer data)
+set_paste_sensitivity (GtkClipboard *clip, GdkEventOwnerChange *event, gpointer data)
 {
   gint i;
   gboolean compatible_target = FALSE;
@@ -576,6 +611,7 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window)
   GtkClipboard *clip_primary =   gtk_widget_get_clipboard (GTK_WIDGET (window), GDK_SELECTION_PRIMARY);
 
   window->cliptext = NULL;
+  window->dispose_has_run = FALSE;
 
   window->edit_delete = get_action_assert (xml, "edit_delete");
   window->edit_copy = get_action_assert (xml, "edit_copy");
@@ -594,11 +630,11 @@ psppire_syntax_window_init (PsppireSyntaxWindow *window)
   g_signal_connect (window->buffer, "modified-changed", 
                    G_CALLBACK (on_modified_changed), window);
 
-  g_signal_connect_swapped (clip_primary, "owner-change", 
-                           G_CALLBACK (selection_changed), window);
+  window->sel_handler = g_signal_connect_swapped (clip_primary, "owner-change", 
+                                                  G_CALLBACK (selection_changed), window);
 
-  g_signal_connect (clip_selection, "owner-change", 
-                   G_CALLBACK (on_owner_change), window);
+  window->ps_handler = g_signal_connect (clip_selection, "owner-change", 
+                                         G_CALLBACK (set_paste_sensitivity), window);
 
   connect_help (xml);
 
@@ -789,5 +825,3 @@ psppire_syntax_window_iface_init (PsppireWindowIface *iface)
   iface->load = syntax_load;
 }
 
-
-
index 9da7c86996c6335d6b38866982f91ae0c5a9cfc0..08f5a7c5b2190246c9691a43b191b25b8f81484a 100644 (file)
@@ -58,6 +58,11 @@ struct _PsppireSyntaxWindow
   GtkAction *edit_copy;
   GtkAction *edit_delete;
   GtkAction *edit_paste;
+
+  gulong ps_handler;
+  gulong sel_handler;
+
+  gboolean dispose_has_run;
 };
 
 struct _PsppireSyntaxWindowClass