Skip to content

Commit

Permalink
fix #1342
Browse files Browse the repository at this point in the history
  • Loading branch information
alainm23 committed Jun 20, 2024
1 parent d1776ab commit ba71813
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
37 changes: 34 additions & 3 deletions core/QuickAdd.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -75,14 +86,16 @@ 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,
left_margin = 14,
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");
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 ();

Expand Down
12 changes: 10 additions & 2 deletions core/Widgets/Entries.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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 () == "") {
Expand Down
3 changes: 3 additions & 0 deletions data/io.github.alainm23.planify.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<file alias="shoe-box-symbolic.svg">resources/icons/shoe-box-symbolic.svg</file>
<file alias="eye-open-negative-filled-symbolic.svg">resources/icons/eye-open-negative-filled-symbolic.svg</file>
<file alias="size-vertically-symbolic.svg">resources/icons/size-vertically-symbolic.svg</file>
<file alias="info-outline-symbolic.svg">resources/icons/info-outline-symbolic.svg</file>
</gresource>

<gresource prefix="/io/github/alainm23/planify/Devel/icons/scalable/actions">
Expand Down Expand Up @@ -154,6 +155,7 @@
<file alias="shoe-box-symbolic.svg">resources/icons/shoe-box-symbolic.svg</file>
<file alias="eye-open-negative-filled-symbolic.svg">resources/icons/eye-open-negative-filled-symbolic.svg</file>
<file alias="size-vertically-symbolic.svg">resources/icons/size-vertically-symbolic.svg</file>
<file alias="info-outline-symbolic.svg">resources/icons/info-outline-symbolic.svg</file>
</gresource>

<gresource prefix="/io/github/alainm23/planify/quick-add/icons/scalable/actions">
Expand Down Expand Up @@ -218,5 +220,6 @@
<file alias="shoe-box-symbolic.svg">resources/icons/shoe-box-symbolic.svg</file>
<file alias="eye-open-negative-filled-symbolic.svg">resources/icons/eye-open-negative-filled-symbolic.svg</file>
<file alias="size-vertically-symbolic.svg">resources/icons/size-vertically-symbolic.svg</file>
<file alias="info-outline-symbolic.svg">resources/icons/info-outline-symbolic.svg</file>
</gresource>
</gresources>
2 changes: 2 additions & 0 deletions data/resources/icons/info-outline-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ba71813

Please sign in to comment.