From b5d137cf302b1c237ca79ffa2e311e4713b0ca6a Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 16 Mar 2023 12:57:50 +0000 Subject: [PATCH 1/5] Update appearance of search entry according to results label --- src/Widgets/SearchBar.vala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 89d27b8398..66dcb200ac 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -578,6 +578,21 @@ namespace Scratch.Widgets { } } + // Update appearance of search entry + var ctx = search_entry.get_style_context (); + ctx.remove_class (Gtk.STYLE_CLASS_ERROR); + ctx.remove_class (Gtk.STYLE_CLASS_WARNING); + search_entry.primary_icon_name = "edit-find-symbolic"; + if (search_entry.text != "") { + if (count_of_search == 0) { + ctx.add_class (Gtk.STYLE_CLASS_ERROR); + search_entry.primary_icon_name = "dialog-error-symbolic"; + } else if (location_of_search == 0) { + ctx.add_class (Gtk.STYLE_CLASS_WARNING); + search_entry.primary_icon_name = "dialog-warning-symbolic"; + } + } + return Source.REMOVE; }); From fb5f0d03905c070d3bb048fc0b955badaa91a148 Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 16 Mar 2023 17:11:41 +0000 Subject: [PATCH 2/5] Remove duplicate code --- src/Widgets/SearchBar.vala | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 66dcb200ac..31877b2c28 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -275,23 +275,8 @@ namespace Scratch.Widgets { return false; } - Gtk.TextIter? iter, start_iter, end_iter; - text_buffer.get_iter_at_offset (out iter, text_buffer.cursor_position); - end_iter = iter; - - bool found = search_context.forward (iter, out start_iter, out end_iter, null); - if (found) { - search_entry.get_style_context ().remove_class (Gtk.STYLE_CLASS_ERROR); - search_entry.primary_icon_name = "edit-find-symbolic"; - return true; - } else { - if (search_entry.text != "") { - search_entry.get_style_context ().add_class (Gtk.STYLE_CLASS_ERROR); - search_entry.primary_icon_name = "dialog-error-symbolic"; - } - - return false; - } + update_search_widgets (); + return false; } public bool search () { @@ -303,7 +288,6 @@ namespace Scratch.Widgets { if (!has_matches ()) { debug ("Can't search anything in a non-existent buffer and/or without anything to search."); - search_entry.primary_icon_name = "edit-find-symbolic"; return false; } From a396f14f6d1ae32bda10f2e20bc06bbc1aa6d79b Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Thu, 16 Mar 2023 17:43:32 +0000 Subject: [PATCH 3/5] Set primary icon sensitivity and tooltip according to results --- src/Widgets/SearchBar.vala | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 31877b2c28..0627be85c8 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -62,9 +62,11 @@ namespace Scratch.Widgets { construct { get_style_context ().add_class ("search-bar"); - search_entry = new Gtk.SearchEntry (); - search_entry.hexpand = true; - search_entry.placeholder_text = _("Find"); + search_entry = new Gtk.SearchEntry () { + hexpand = true, + placeholder_text = _("Find"), + primary_icon_activatable = true + }; search_occurence_count_label = new Gtk.Label (_("no results")) { margin_start = 4 @@ -531,7 +533,6 @@ namespace Scratch.Widgets { tool_arrow_down.sensitive = true; tool_arrow_up.sensitive =true; } else { - // Gtk.TextIter? start_iter, end_iter; Gtk.TextIter? tmp_start_iter, tmp_end_iter; bool is_in_start, is_in_end; @@ -567,13 +568,25 @@ namespace Scratch.Widgets { ctx.remove_class (Gtk.STYLE_CLASS_ERROR); ctx.remove_class (Gtk.STYLE_CLASS_WARNING); search_entry.primary_icon_name = "edit-find-symbolic"; + search_entry.primary_icon_sensitive = true; + search_entry.set_icon_tooltip_text ( + Gtk.EntryIconPosition.PRIMARY, _("Click to find next match") + ); if (search_entry.text != "") { if (count_of_search == 0) { ctx.add_class (Gtk.STYLE_CLASS_ERROR); search_entry.primary_icon_name = "dialog-error-symbolic"; + search_entry.primary_icon_sensitive = false; + search_entry.set_icon_tooltip_text ( + Gtk.EntryIconPosition.PRIMARY, _("No matches") + ); } else if (location_of_search == 0) { ctx.add_class (Gtk.STYLE_CLASS_WARNING); search_entry.primary_icon_name = "dialog-warning-symbolic"; + search_entry.primary_icon_sensitive = false; + search_entry.set_icon_tooltip_text ( + Gtk.EntryIconPosition.PRIMARY, _("Search is past last match and is not cyclic") + ); } } From 7e9f31d4503679fd6882eac3cdbe38d3494e7bae Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Sun, 26 Mar 2023 11:24:52 +0100 Subject: [PATCH 4/5] Drop warning state --- src/Widgets/SearchBar.vala | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index 1db2a8587e..ab4fc87f95 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -605,29 +605,21 @@ namespace Scratch.Widgets { // Update appearance of search entry var ctx = search_entry.get_style_context (); - ctx.remove_class (Gtk.STYLE_CLASS_ERROR); - ctx.remove_class (Gtk.STYLE_CLASS_WARNING); - search_entry.primary_icon_name = "edit-find-symbolic"; - search_entry.primary_icon_sensitive = true; - search_entry.set_icon_tooltip_text ( - Gtk.EntryIconPosition.PRIMARY, _("Click to find next match") - ); - if (search_entry.text != "") { - if (count_of_search == 0) { - ctx.add_class (Gtk.STYLE_CLASS_ERROR); - search_entry.primary_icon_name = "dialog-error-symbolic"; - search_entry.primary_icon_sensitive = false; - search_entry.set_icon_tooltip_text ( - Gtk.EntryIconPosition.PRIMARY, _("No matches") - ); - } else if (location_of_search == 0) { - ctx.add_class (Gtk.STYLE_CLASS_WARNING); - search_entry.primary_icon_name = "dialog-warning-symbolic"; - search_entry.primary_icon_sensitive = false; - search_entry.set_icon_tooltip_text ( - Gtk.EntryIconPosition.PRIMARY, _("Search is past last match and is not cyclic") - ); - } + + if (search_entry.text != "" && count_of_search == 0) { + ctx.add_class (Gtk.STYLE_CLASS_ERROR); + search_entry.primary_icon_name = "dialog-error-symbolic"; + search_entry.primary_icon_sensitive = false; + search_entry.set_icon_tooltip_text ( + Gtk.EntryIconPosition.PRIMARY, _("No matches") + ); + } else if (ctx.has_class (Gtk.STYLE_CLASS_ERROR)) { + ctx.remove_class (Gtk.STYLE_CLASS_ERROR); + search_entry.primary_icon_name = "edit-find-symbolic"; + search_entry.primary_icon_sensitive = true; + search_entry.set_icon_tooltip_text ( + Gtk.EntryIconPosition.PRIMARY, _("Click to find next match") + ); } return Source.REMOVE; From 141b88ae6c17e0199dffd854b16534ef7b0b92cd Mon Sep 17 00:00:00 2001 From: Jeremy Wootten Date: Tue, 28 Mar 2023 11:05:02 +0100 Subject: [PATCH 5/5] Remove primary icon tooltip and action --- src/Widgets/SearchBar.vala | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index d60b9f3dc5..cd61f2bfcc 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -69,8 +69,7 @@ namespace Scratch.Widgets { construct { search_entry = new Gtk.SearchEntry () { hexpand = true, - placeholder_text = _("Find"), - primary_icon_activatable = true + placeholder_text = _("Find") }; search_occurence_count_label = new Gtk.Label (_("No Results")); @@ -614,17 +613,9 @@ namespace Scratch.Widgets { if (search_entry.text != "" && count_of_search == 0) { ctx.add_class (Gtk.STYLE_CLASS_ERROR); search_entry.primary_icon_name = "dialog-error-symbolic"; - search_entry.primary_icon_sensitive = false; - search_entry.set_icon_tooltip_text ( - Gtk.EntryIconPosition.PRIMARY, _("No matches") - ); } else if (ctx.has_class (Gtk.STYLE_CLASS_ERROR)) { ctx.remove_class (Gtk.STYLE_CLASS_ERROR); search_entry.primary_icon_name = "edit-find-symbolic"; - search_entry.primary_icon_sensitive = true; - search_entry.set_icon_tooltip_text ( - Gtk.EntryIconPosition.PRIMARY, _("Click to find next match") - ); } return Source.REMOVE;