From ba718132d9a49e74a12a87143981b69e2c420068 Mon Sep 17 00:00:00 2001 From: Alain Date: Thu, 20 Jun 2024 16:26:34 -0500 Subject: [PATCH] fix #1342 --- core/QuickAdd.vala | 37 +++++++++++++++++-- core/Widgets/Entries.vala | 12 +++++- data/io.github.alainm23.planify.gresource.xml | 3 ++ .../resources/icons/info-outline-symbolic.svg | 2 + 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 data/resources/icons/info-outline-symbolic.svg diff --git a/core/QuickAdd.vala b/core/QuickAdd.vala index 5b1a3287f..0cbf9caa5 100644 --- a/core/QuickAdd.vala +++ b/core/QuickAdd.vala @@ -15,6 +15,7 @@ public class Layouts.QuickAdd : Adw.Bin { private Gtk.Image added_image; private Gtk.Stack main_stack; private Gtk.ToggleButton create_more_button; + private Gtk.Revealer info_revealer; public signal void hide_destroy (); public signal void send_interface_id (string id); @@ -65,6 +66,16 @@ public class Layouts.QuickAdd : Adw.Bin { css_classes = { "flat", "font-bold" } }; + var info_icon = new Gtk.Image.from_icon_name ("info-outline-symbolic") { + css_classes = { "error" }, + tooltip_text = _("This field is required") + }; + + info_revealer = new Gtk.Revealer () { + child = info_icon, + transition_type = Gtk.RevealerTransitionType.SLIDE_LEFT + }; + var content_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6) { valign = Gtk.Align.CENTER, hexpand = true, @@ -75,6 +86,7 @@ public class Layouts.QuickAdd : Adw.Bin { }; content_box.append (content_entry); + content_box.append (info_revealer); description_textview = new Widgets.HyperTextView (_("Add a description…")) { height_request = 64, @@ -82,7 +94,8 @@ public class Layouts.QuickAdd : Adw.Bin { right_margin = 6, top_margin = 12, wrap_mode = Gtk.WrapMode.WORD_CHAR, - hexpand = true + hexpand = true, + event_focus = false }; description_textview.remove_css_class ("view"); @@ -271,6 +284,11 @@ public class Layouts.QuickAdd : Adw.Bin { add_item (); }); + content_entry.changed.connect (() => { + info_revealer.reveal_child = false; + content_entry.remove_css_class ("error"); + }); + var content_controller_key = new Gtk.EventControllerKey (); content_entry.add_controller (content_controller_key); content_controller_key.key_pressed.connect ((keyval, keycode, state) => { @@ -325,12 +343,25 @@ public class Layouts.QuickAdd : Adw.Bin { }); } - private void add_item () { - if (content_entry.buffer.text.length <= 0) { + private void add_item () { + info_revealer.reveal_child = false; + content_entry.remove_css_class ("error"); + + if (content_entry.get_text ().length <= 0 && description_textview.get_text ().length <= 0) { hide_destroy (); return; } + if (content_entry.get_text ().length <= 0) { + Timeout.add (info_revealer.transition_duration, () => { + info_revealer.reveal_child = true; + content_entry.add_css_class ("error"); + return GLib.Source.REMOVE; + }); + + return; + } + item.content = content_entry.get_text (); item.description = description_textview.get_text (); diff --git a/core/Widgets/Entries.vala b/core/Widgets/Entries.vala index dfdc7c205..41fe220cd 100644 --- a/core/Widgets/Entries.vala +++ b/core/Widgets/Entries.vala @@ -75,6 +75,8 @@ public class Widgets.HyperTextView : Granite.HyperTextView { } } + public bool event_focus { get; set; default = true; } + public HyperTextView (string placeholder_text) { Object ( placeholder_text: placeholder_text @@ -97,7 +99,10 @@ public class Widgets.HyperTextView : Granite.HyperTextView { } private void handle_focus_in () { - Services.EventBus.get_default ().disconnect_typing_accel (); + if (event_focus) { + Services.EventBus.get_default ().disconnect_typing_accel (); + } + enter (); if (buffer_get_text () == placeholder_text) { @@ -107,7 +112,10 @@ public class Widgets.HyperTextView : Granite.HyperTextView { } public void update_on_leave () { - Services.EventBus.get_default ().connect_typing_accel (); + if (event_focus) { + Services.EventBus.get_default ().connect_typing_accel (); + } + leave (); if (buffer_get_text () == "") { diff --git a/data/io.github.alainm23.planify.gresource.xml b/data/io.github.alainm23.planify.gresource.xml index 1bfde5415..da8f8b374 100644 --- a/data/io.github.alainm23.planify.gresource.xml +++ b/data/io.github.alainm23.planify.gresource.xml @@ -90,6 +90,7 @@ resources/icons/shoe-box-symbolic.svg resources/icons/eye-open-negative-filled-symbolic.svg resources/icons/size-vertically-symbolic.svg + resources/icons/info-outline-symbolic.svg @@ -154,6 +155,7 @@ resources/icons/shoe-box-symbolic.svg resources/icons/eye-open-negative-filled-symbolic.svg resources/icons/size-vertically-symbolic.svg + resources/icons/info-outline-symbolic.svg @@ -218,5 +220,6 @@ resources/icons/shoe-box-symbolic.svg resources/icons/eye-open-negative-filled-symbolic.svg resources/icons/size-vertically-symbolic.svg + resources/icons/info-outline-symbolic.svg diff --git a/data/resources/icons/info-outline-symbolic.svg b/data/resources/icons/info-outline-symbolic.svg new file mode 100644 index 000000000..254e7e838 --- /dev/null +++ b/data/resources/icons/info-outline-symbolic.svg @@ -0,0 +1,2 @@ + +