Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EntryPopover/Generic: Gtk4 Prep #386

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions src/Widgets/EntryPopover/Generic.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/

public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.EventBox {
public abstract class Tasks.Widgets.EntryPopover.Generic<T> : Gtk.Box {
public signal string? value_format (T value);
public signal void value_changed (T value);

Expand All @@ -12,9 +12,10 @@ public abstract class Tasks.Widgets.EntryPopover.Generic<T> : 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;
danirabbit marked this conversation as resolved.
Show resolved Hide resolved

protected Generic (string placeholder, string? icon_name = null) {
Object (
icon_name: icon_name,
Expand All @@ -27,31 +28,36 @@ public abstract class Tasks.Widgets.EntryPopover.Generic<T> : 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);

Expand All @@ -74,24 +80,28 @@ public abstract class Tasks.Widgets.EntryPopover.Generic<T> : 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;
}
Expand Down