editablelabel: Stop editing on focus-out

This is the expected behavior for the main use case,
treeview-like 'edit one cell at a time'.
This commit is contained in:
Matthias Clasen 2020-07-18 10:10:38 -04:00
parent 77072b3eaa
commit 287d80bd36

View File

@ -30,6 +30,7 @@
#include "gtkshortcut.h"
#include "gtkshortcuttrigger.h"
#include "gtkwidgetprivate.h"
#include "gtkeventcontrollerfocus.h"
#include "gtkintl.h"
/**
@ -193,12 +194,20 @@ gtk_editable_label_prepare_drag (GtkDragSource *source,
gtk_label_get_label (GTK_LABEL (self->label)));
}
static void
gtk_editable_label_focus_out (GtkEventController *controller,
GtkEditableLabel *self)
{
gtk_editable_label_stop_editing (self, TRUE);
}
static void
gtk_editable_label_init (GtkEditableLabel *self)
{
GtkGesture *gesture;
GtkDropTarget *target;
GtkDragSource *source;
GtkEventController *controller;
gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
@ -228,6 +237,10 @@ gtk_editable_label_init (GtkEditableLabel *self)
g_signal_connect (source, "prepare", G_CALLBACK (gtk_editable_label_prepare_drag), self);
gtk_widget_add_controller (self->label, GTK_EVENT_CONTROLLER (source));
controller = gtk_event_controller_focus_new ();
g_signal_connect (controller, "leave", G_CALLBACK (gtk_editable_label_focus_out), self);
gtk_widget_add_controller (GTK_WIDGET (self), controller);
gtk_editable_init_delegate (GTK_EDITABLE (self));
}