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> 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.
This commit is contained in:
Robert Fewell 2020-10-05 12:46:14 +01:00
parent 1c0530dafd
commit f685a32d9a

View File

@ -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"));