about summary refs log tree commit diff
path: root/saneterm
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-06-08 02:35:12 +0200
committerSören Tempel <soeren+git@soeren-tempel.net>2021-06-08 02:35:12 +0200
commit3167a4ad27076e0b1b49e981ad3ff487e3fac8a9 (patch)
tree58d90d395b49277aad1b9b18a91fe22ab40496be /saneterm
parent9b6b7aba74c43132ab0c25ab0e755515a32d1252 (diff)
Add buttons to search bar for cycling through matches
Currently there are still some focus issue, i.e. if the button are
pressed these are focused and the Ctrl+G/Ctrl+Shift+G keybindings no
longer work. That will be fixed in a future commit.
Diffstat (limited to 'saneterm')
-rw-r--r--saneterm/search.py34
1 files changed, 32 insertions, 2 deletions
diff --git a/saneterm/search.py b/saneterm/search.py
index 82e07db..9b840ab 100644
--- a/saneterm/search.py
+++ b/saneterm/search.py
@@ -17,14 +17,39 @@ class SearchBar(Gtk.SearchBar):
                 background=self.BG_COLOR,
                 foreground=self.FG_COLOR)
 
+        hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
+        style_ctx = hbox.get_style_context()
+        style_ctx.add_class("linked")
+        style_ctx.add_class("raised")
+        self.add(hbox)
+
         search_entry = Gtk.SearchEntry.new()
+        search_entry.set_width_chars(32)
         search_entry.connect("search-changed", self.__search_changed)
         search_entry.connect("next-match", self.__next_match)
         search_entry.connect("previous-match", self.__prev_match)
+        hbox.pack_start(search_entry, True, True, 0)
+
+        self.__nextbtn, self.__prevbtn = self.__create_nav_buttons(search_entry, hbox)
 
         self.set_show_close_button(True)
         self.connect_entry(search_entry)
-        self.add(search_entry)
+
+    def __create_nav_buttons(self, search_entry, box):
+        def button_callback(button, dir):
+            signal = "previous-match" if dir == "up" else "next-match"
+            search_entry.emit(signal)
+
+        buttons = []
+        for dir in ["up", "down"]:
+            button = Gtk.Button.new_from_icon_name(F"go-{dir}-symbolic", Gtk.IconSize.MENU)
+            button.set_sensitive(False)
+            button.connect("clicked", button_callback, dir)
+
+            box.add(button)
+            buttons.append(button)
+
+        return tuple(buttons)
 
     def __find_match(self, entry, start, forward=True):
         buf = self.__buffer
@@ -45,8 +70,13 @@ class SearchBar(Gtk.SearchBar):
             buf.apply_tag(self.__tag, mstart, mend)
             self.__view.scroll_to_iter(mstart, 0.1, False, 0.0, 0.0)
 
+        return self.__match
+
     def __search_changed(self, entry):
-        self.__find_match(entry, self.__buffer.get_start_iter())
+        found = self.__find_match(entry, self.__buffer.get_start_iter())
+
+        self.__nextbtn.set_sensitive(not found is None)
+        self.__prevbtn.set_sensitive(not found is None)
 
     def __next_match(self, entry):
         # Wrap around if no match was found previously.