From dd2faec9defd47eaf5bedb8eb46a83e48c3323b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 6 Jun 2024 15:03:21 -0700 Subject: [PATCH 1/4] EntryPopover/Generic: Gtk4 Prep --- src/Widgets/EntryPopover/Generic.vala | 38 ++++++++++++++++++--------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Widgets/EntryPopover/Generic.vala b/src/Widgets/EntryPopover/Generic.vala index e3e795321..93f398134 100644 --- a/src/Widgets/EntryPopover/Generic.vala +++ b/src/Widgets/EntryPopover/Generic.vala @@ -15,6 +15,8 @@ public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { 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 +29,37 @@ 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 (popover_button); + var label = new Gtk.Label (placeholder); + + 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, + child = popover_button_box, popover = popover, - image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.BUTTON), always_show_image = icon_name != null }; 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 +82,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; } From f34fa31b09fab334c0beab50f39913faae06c9f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 6 Jun 2024 15:06:09 -0700 Subject: [PATCH 2/4] Don't cache menubutton --- src/Widgets/EntryPopover/Generic.vala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Widgets/EntryPopover/Generic.vala b/src/Widgets/EntryPopover/Generic.vala index 93f398134..0e27882b9 100644 --- a/src/Widgets/EntryPopover/Generic.vala +++ b/src/Widgets/EntryPopover/Generic.vala @@ -12,7 +12,6 @@ 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; @@ -29,7 +28,7 @@ public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { } construct { - popover = new Gtk.Popover (popover_button); + popover = new Gtk.Popover (null); var label = new Gtk.Label (placeholder); @@ -39,7 +38,7 @@ public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { } popover_button_box.add (label); - popover_button = new Gtk.MenuButton () { + var popover_button = new Gtk.MenuButton () { child = popover_button_box, popover = popover, always_show_image = icon_name != null From 2f7408935db5bcc5892e77dc0b529932d9d05e87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 10 Jun 2024 12:07:46 -0700 Subject: [PATCH 3/4] Remove always show image --- src/Widgets/EntryPopover/Generic.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Widgets/EntryPopover/Generic.vala b/src/Widgets/EntryPopover/Generic.vala index 0e27882b9..d5512eebb 100644 --- a/src/Widgets/EntryPopover/Generic.vala +++ b/src/Widgets/EntryPopover/Generic.vala @@ -40,8 +40,7 @@ public abstract class Tasks.Widgets.EntryPopover.Generic : Gtk.EventBox { var popover_button = new Gtk.MenuButton () { child = popover_button_box, - popover = popover, - always_show_image = icon_name != null + popover = popover }; popover_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT); From 2b31a300a14f13cf17956fdce92a43ce531732b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 10 Jun 2024 12:09:22 -0700 Subject: [PATCH 4/4] Don't use eventbox --- src/Widgets/EntryPopover/Generic.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/EntryPopover/Generic.vala b/src/Widgets/EntryPopover/Generic.vala index d5512eebb..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);