[meld/ui-next] ui.findbar: Update styling on failed find (#290)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/ui-next] ui.findbar: Update styling on failed find (#290)
- Date: Tue, 12 Mar 2019 20:27:23 +0000 (UTC)
commit e63b78d0faef595726be636472b9b48cab4bb9dd
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sat Mar 2 07:58:02 2019 +1000
ui.findbar: Update styling on failed find (#290)
data/meld.css | 6 ------
meld/ui/findbar.py | 24 ++++++++++++++++++++----
2 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/data/meld.css b/data/meld.css
index f36e1a28..f15504ab 100644
--- a/data/meld.css
+++ b/data/meld.css
@@ -52,12 +52,6 @@ find-bar {
border-color: @borders;
}
-.not-found {
- color: white;
- background-image: none;
- background-color: rgb(237, 54, 54);
-}
-
.sourcemap-container {
border-width: 0 0 0 1px;
border-style: solid;
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index fda5741a..24ccea15 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -43,6 +43,9 @@ class FindBar(Gtk.Grid):
super().__init__()
self.init_template()
+ self.search_context = None
+ self.notify_id = None
+
self.set_text_view(None)
parent.connect('set-focus-child', self.on_focus_child)
@@ -73,19 +76,35 @@ class FindBar(Gtk.Grid):
self.wrap_box.set_visible(False)
Gtk.Widget.hide(self)
+ def update_match_state(self, *args):
+ # Note that -1 here implies that the search is still running
+ no_matches = (
+ self.search_context.props.occurrences_count == 0 and
+ self.search_settings.props.search_text
+ )
+ style_context = self.find_entry.get_style_context()
+ if no_matches:
+ style_context.add_class(Gtk.STYLE_CLASS_ERROR)
+ else:
+ style_context.remove_class(Gtk.STYLE_CLASS_ERROR)
+
def set_text_view(self, textview):
self.textview = textview
if textview is not None:
self.search_context = GtkSource.SearchContext.new(
textview.get_buffer(), self.search_settings)
self.search_context.set_highlight(True)
+ self.notify_id = self.search_context.connect(
+ 'notify::occurrences-count', self.update_match_state)
else:
+ if self.notify_id:
+ self.search_context.disconnect(self.notify_id)
+ self.notify_id = None
self.search_context = None
def start_find(self, *, textview: Gtk.TextView, replace: bool, text: str):
self.replace_mode = replace
self.set_text_view(textview)
- self.find_entry.get_style_context().remove_class("not-found")
if text:
self.find_entry.set_text(text)
self.show()
@@ -137,7 +156,6 @@ class FindBar(Gtk.Grid):
@Template.Callback()
def on_find_entry_changed(self, entry):
- self.find_entry.get_style_context().remove_class("not-found")
self._find_text(0)
@Template.Callback()
@@ -167,11 +185,9 @@ class FindBar(Gtk.Grid):
buf.move_mark(buf.get_selection_bound(), end_iter)
self.textview.scroll_to_mark(
buf.get_insert(), 0.25, True, 0.5, 0.5)
- self.find_entry.get_style_context().remove_class("not-found")
return True
else:
buf.place_cursor(buf.get_iter_at_mark(buf.get_insert()))
- self.find_entry.get_style_context().add_class("not-found")
self.wrap_box.set_visible(False)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]