diff --git a/src/Widgets/EntryPopover/Generic.vala b/src/Widgets/EntryPopover/Generic.vala index e3e795321..9232417b3 100644 --- a/src/Widgets/EntryPopover/Generic.vala +++ b/src/Widgets/EntryPopover/Generic.vala @@ -3,7 +3,7 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { +public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.Box { public signal string? value_format (T value); public signal void value_changed (T value); @@ -12,9 +12,10 @@ public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { public string placeholder { get; construct; } public T value { get; set; } - private Gtk.MenuButton popover_button; private T value_on_popover_show; + private Gtk.EventControllerMotion motion_controller; + protected Generic (string placeholder, string? icon_name = null) { Object ( icon_name: icon_name, @@ -27,31 +28,36 @@ public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { } construct { - events |= Gdk.EventMask.ENTER_NOTIFY_MASK - | Gdk.EventMask.LEAVE_NOTIFY_MASK; + popover = new Gtk.Popover (null); + + var label = new Gtk.Label (placeholder); - popover = new Gtk.Popover (popover_button); + var popover_button_box = new Gtk.Box (HORIZONTAL, 0); + if (icon_name != null) { + popover_button_box.add (new Gtk.Image.from_icon_name (icon_name, BUTTON)); + } + popover_button_box.add (label); - popover_button = new Gtk.MenuButton () { - label = placeholder, - popover = popover, - image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.BUTTON), - always_show_image = icon_name != null + var popover_button = new Gtk.MenuButton () { + child = popover_button_box, + popover = popover }; popover_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); - var delete_button = new Gtk.Button.from_icon_name ("process-stop-symbolic", Gtk.IconSize.BUTTON) { + label.mnemonic_widget = popover_button; + + var delete_button = new Gtk.Button.from_icon_name ("process-stop-symbolic", BUTTON) { tooltip_text = _("Remove") }; delete_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); var delete_button_revealer = new Gtk.Revealer () { - transition_type = Gtk.RevealerTransitionType.SLIDE_RIGHT, + child = delete_button, + transition_type = SLIDE_LEFT, reveal_child = false }; - delete_button_revealer.add (delete_button); - var button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + var button_box = new Gtk.Box (HORIZONTAL, 0); button_box.add (popover_button); button_box.add (delete_button_revealer); @@ -74,24 +80,28 @@ public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { notify["value"].connect (() => { var value_formatted = value_format (value); if (value_formatted == null) { - popover_button.label = placeholder; + label.label = placeholder; if (delete_button_revealer.reveal_child) { delete_button_revealer.reveal_child = false; } } else { - popover_button.label = value_formatted; + label.label = value_formatted; } }); - enter_notify_event.connect (() => { + motion_controller = new Gtk.EventControllerMotion (this) { + propagation_phase = CAPTURE + }; + + motion_controller.enter.connect (() => { if (value_format (value) != null) { delete_button_revealer.reveal_child = true; } }); - leave_notify_event.connect (() => { + motion_controller.leave.connect (() => { if (delete_button_revealer.reveal_child) { delete_button_revealer.reveal_child = false; }