diff --git a/src/Widgets/SearchBar.vala b/src/Widgets/SearchBar.vala index c4ea2e2d07..3072c167c6 100644 --- a/src/Widgets/SearchBar.vala +++ b/src/Widgets/SearchBar.vala @@ -67,9 +67,10 @@ namespace Scratch.Widgets { } construct { - search_entry = new Gtk.SearchEntry (); - search_entry.hexpand = true; - search_entry.placeholder_text = _("Find"); + search_entry = new Gtk.SearchEntry () { + hexpand = true, + placeholder_text = _("Find") + }; search_occurence_count_label = new Gtk.Label (_("No Results")); search_occurence_count_label.get_style_context ().add_class (Granite.STYLE_CLASS_SMALL_LABEL); @@ -328,23 +329,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 () { @@ -356,7 +342,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; } @@ -595,7 +580,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; @@ -626,6 +610,17 @@ namespace Scratch.Widgets { } } + // Update appearance of search entry + var ctx = search_entry.get_style_context (); + + if (search_entry.text != "" && count_of_search == 0) { + ctx.add_class (Gtk.STYLE_CLASS_ERROR); + search_entry.primary_icon_name = "dialog-error-symbolic"; + } else if (ctx.has_class (Gtk.STYLE_CLASS_ERROR)) { + ctx.remove_class (Gtk.STYLE_CLASS_ERROR); + search_entry.primary_icon_name = "edit-find-symbolic"; + } + return Source.REMOVE; });