printers, new-printer-dialog: Handle "Escape" shortcut in ui file

As suggested by Matthijs Velsink, it is much cleaner handling UI
related things in the .ui file.

This is a cleaner version of commit 3f612ab81

Related to !2656, fixing #3086
This commit is contained in:
Felipe Borges 2024-06-13 10:29:47 +02:00
parent fb9b6a0c5c
commit 18398e2986
2 changed files with 7 additions and 21 deletions

View file

@ -1338,24 +1338,6 @@ search_entry_activated_cb (PpNewPrinterDialog *self)
FALSE);
}
static gboolean
on_key_press_event (GtkEventControllerKey *controller,
guint keyval,
guint keycode,
GdkModifierType state,
PpNewPrinterDialog *self)
{
/* Capture Escape key press before it propagates down to the Search Entry,
* so the dialog can close on Escape. */
if (keyval == GDK_KEY_Escape) {
gtk_window_close (GTK_WINDOW (self));
return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
}
static void
search_entry_changed_cb (PpNewPrinterDialog *self)
{
@ -1901,7 +1883,6 @@ pp_new_printer_dialog_class_init (PpNewPrinterDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, add_cb);
gtk_widget_class_bind_template_callback (widget_class, cancel_cb);
gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
object_class->dispose = pp_new_printer_dialog_dispose;
window_class->close_request = pp_new_printer_dialog_close_request;

View file

@ -33,9 +33,14 @@
<class name="view"/>
</style>
<child>
<object class="GtkEventControllerKey">
<object class="GtkShortcutController">
<property name="propagation-phase">capture</property>
<signal name="key-pressed" handler="on_key_press_event"/>
<child>
<object class="GtkShortcut">
<property name="trigger">Escape</property>
<property name="action">action(window.close)</property>
</object>
</child>
</object>
</child>
<property name="content">