[meld] ui.findbar: Update styling on failed find (#290)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] ui.findbar: Update styling on failed find (#290)
- Date: Fri, 1 Mar 2019 22:01:26 +0000 (UTC)
commit 70a16af3a9f7e71aa601beb57d73242d7e00b401
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 | 25 ++++++++++++++++++++-----
2 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/data/meld.css b/data/meld.css
index 86d40ec3..ddc0c948 100644
--- a/data/meld.css
+++ b/data/meld.css
@@ -30,9 +30,3 @@ link-map {
border-style: solid;
border-color: @borders;
}
-
-.not-found {
- color: white;
- background-image: none;
- background-color: rgb(237, 54, 54);
-}
diff --git a/meld/ui/findbar.py b/meld/ui/findbar.py
index ed9ad63c..2f0dd1a2 100644
--- a/meld/ui/findbar.py
+++ b/meld/ui/findbar.py
@@ -42,6 +42,9 @@ class FindBar(Gtk.Grid):
super().__init__()
self.init_template()
+ self.search_context = None
+ self.notify_id = None
+
self.set_text_view(None)
self.arrow_left.show()
self.arrow_right.show()
@@ -67,13 +70,30 @@ 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, text=None):
@@ -81,7 +101,6 @@ class FindBar(Gtk.Grid):
self.replace_label.hide()
self.replace_entry.hide()
self.hbuttonbox2.hide()
- self.find_entry.get_style_context().remove_class("not-found")
if text:
self.find_entry.set_text(text)
self.set_row_spacing(0)
@@ -104,7 +123,6 @@ class FindBar(Gtk.Grid):
def start_replace(self, textview, text=None):
self.set_text_view(textview)
- self.find_entry.get_style_context().remove_class("not-found")
if text:
self.find_entry.set_text(text)
self.set_row_spacing(6)
@@ -146,7 +164,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()
@@ -175,9 +192,7 @@ 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]