From: John Darrington Date: Sun, 26 Sep 2010 10:13:35 +0000 (+0200) Subject: Disconnect clip signal handlers when a syntax window is destroyed X-Git-Tag: v0.7.6~139 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d0ea35a8628c8947d2e4639e7b9c8746e2f02704;p=pspp-builds.git Disconnect clip signal handlers when a syntax window is destroyed --- diff --git a/src/ui/gui/psppire-syntax-window.c b/src/ui/gui/psppire-syntax-window.c index 86d1db76..ccf94e7b 100644 --- a/src/ui/gui/psppire-syntax-window.c +++ b/src/ui/gui/psppire-syntax-window.c @@ -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; } - - diff --git a/src/ui/gui/psppire-syntax-window.h b/src/ui/gui/psppire-syntax-window.h index 9da7c869..08f5a7c5 100644 --- a/src/ui/gui/psppire-syntax-window.h +++ b/src/ui/gui/psppire-syntax-window.h @@ -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