Commit 70a16af3 authored by Kai Willadsen's avatar Kai Willadsen

ui.findbar: Update styling on failed find (#290)

parent 5ab3b245
......@@ -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);
}
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment