From f685a32d9a93eed3536fbeae799510918b99444e Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 5 Oct 2020 12:46:14 +0100 Subject: [PATCH] Bug 797967 - Manage Document Link errors If there are no document links, the default dialog is for a file uri and if the escape key is pressed in this default state the following error is added to the trace file... ERROR gtk_widget_event: assertion 'WIDGET_REALIZED_FOR_EVENT (widget, event)' failed This coming from the GtkFileChooserButton and to fix this add a signal callback for the dialog 'key_press_event' to intercept the escape key and emit a GTK_RESPONSE_CANCEL to close the dialog. --- gnucash/gnome/dialog-doclink.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gnucash/gnome/dialog-doclink.c b/gnucash/gnome/dialog-doclink.c index 3fbc2e1663..50cfd62e73 100644 --- a/gnucash/gnome/dialog-doclink.c +++ b/gnucash/gnome/dialog-doclink.c @@ -229,6 +229,19 @@ setup_file_dialog (GtkBuilder *builder, GtkFileChooserButton *fcb, g_free (display_uri); } +static gboolean +gnc_doclink_get_uri_event_cb (GtkWidget *widget, GdkEventKey *event, + gpointer user_data) +{ + if (event->keyval == GDK_KEY_Escape) + { + gtk_dialog_response (GTK_DIALOG(widget), + GTK_RESPONSE_CANCEL); + return TRUE; + } + return FALSE; +} + gchar * gnc_doclink_get_uri_dialog (GtkWindow *parent, const gchar *title, const gchar *uri) @@ -258,6 +271,10 @@ gnc_doclink_get_uri_dialog (GtkWindow *parent, const gchar *title, gtk_widget_set_name (GTK_WIDGET(dialog), "gnc-id-doclink"); gnc_widget_style_context_add_class (GTK_WIDGET(dialog), "gnc-class-doclink"); + // Use this event to capture the escape key being pressed + g_signal_connect (dialog, "key_press_event", + G_CALLBACK(gnc_doclink_get_uri_event_cb), dialog); + head_label = GTK_WIDGET(gtk_builder_get_object (builder, "path_head_label")); ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "ok_button"));