remove some cruft and replace the hacky backwards search with a more correct one. There are still some issues though

This commit is contained in:
Chris Jones 2009-11-04 20:41:01 +00:00
parent 8d19561f85
commit 55c79f56d5
1 changed files with 26 additions and 30 deletions

View File

@ -68,10 +68,14 @@ class Searchbar(gtk.HBox):
# Next Button # Next Button
self.next = gtk.Button(_('Next')) self.next = gtk.Button(_('Next'))
self.next.show()
self.next.set_sensitive(False)
self.next.connect('clicked', self.next_search) self.next.connect('clicked', self.next_search)
# Previous Button # Previous Button
self.prev = gtk.Button(_('Prev')) self.prev = gtk.Button(_('Prev'))
self.prev.show()
self.prev.set_sensitive(False)
self.prev.connect('clicked', self.prev_search) self.prev.connect('clicked', self.prev_search)
self.pack_start(label, False) self.pack_start(label, False)
@ -106,7 +110,6 @@ class Searchbar(gtk.HBox):
def do_search(self, widget): def do_search(self, widget):
"""Trap and re-emit the clicked signal""" """Trap and re-emit the clicked signal"""
self.searchhits = []
searchtext = self.entry.get_text() searchtext = self.entry.get_text()
if searchtext == '': if searchtext == '':
return return
@ -116,18 +119,17 @@ class Searchbar(gtk.HBox):
self.searchstring = searchtext self.searchstring = searchtext
self.reslabel.set_text(_("Searching scrollback")) self.reslabel.set_text(_("Searching scrollback"))
self.next.set_sensitive(True)
self.prev.set_sensitive(True)
self.next_search(None) self.next_search(None)
def next_search(self, widget): def next_search(self, widget):
"""Search forwards and jump to the next result, if any""" """Search forwards and jump to the next result, if any"""
# FIXME: I think we should emit a signal and have Terminal() do this.
startrow,endrow = self.get_vte_buffer_range() startrow,endrow = self.get_vte_buffer_range()
while True: while True:
if self.searchrow == endrow: if self.searchrow == endrow:
self.searchrow = startrow self.searchrow = startrow
self.reslabel.set_text(_("Finished search")) self.reslabel.set_text(_('No more results'))
self.next.hide()
self.prev.hide()
return return
buffer = self.vte.get_text_range(self.searchrow, 0, buffer = self.vte.get_text_range(self.searchrow, 0,
self.searchrow, -1, self.searchrow, -1,
@ -135,32 +137,38 @@ class Searchbar(gtk.HBox):
index = buffer.find(self.searchstring) index = buffer.find(self.searchstring)
if index != -1: if index != -1:
self.searchhits.append(self.searchrow)
self.search_hit(self.searchrow) self.search_hit(self.searchrow)
self.searchrow += 1 self.searchrow += 1
return return
self.searchrow += 1 self.searchrow += 1
# FIXME: There is an issue in switching search direction, probably because
# we increment/decrement self.searchrow after each search iteration
def prev_search(self, widget): def prev_search(self, widget):
"""Jump back to the previous search""" """Jump back to the previous search"""
row = self.searchhits.pop() startrow,endrow = self.get_vte_buffer_range()
position = self.get_parent().scrollbar_position() while True:
while row >= position: if self.searchrow == startrow:
row = self.searchhits.pop() self.searchrow = endrow
self.search_hit(row) self.reslabel.set_text(_('No more results'))
self.searchrow -= 1 return
buffer = self.vte.get_text_range(self.searchrow, 0,
self.searchrow, -1,
self.search_character)
index = buffer.find(self.searchstring)
if index != -1:
self.search_hit(self.searchrow)
self.searchrow -= 1
return
self.searchrow -= 1
def search_hit(self, row): def search_hit(self, row):
"""Update the UI for a search hit""" """Update the UI for a search hit"""
dbg('Searchbar::search_hit row %d, history of %d' % (row,
len(self.searchhits)))
self.reslabel.set_text("%s %d" % (_('Found at row'), row)) self.reslabel.set_text("%s %d" % (_('Found at row'), row))
self.get_parent().scrollbar_jump(row) self.get_parent().scrollbar_jump(row)
self.next.show() self.next.show()
if len(self.searchhits) > 1: self.prev.show()
self.prev.show()
else:
self.prev.hide()
def search_character(self, widget, col, row, junk): def search_character(self, widget, col, row, junk):
"""We have to have a callback for each character""" """We have to have a callback for each character"""
@ -183,16 +191,4 @@ class Searchbar(gtk.HBox):
"""Return the currently set search term""" """Return the currently set search term"""
return(self.entry.get_text()) return(self.entry.get_text())
def set_search_label(self, string = ''):
"""Set the search label"""
self.reslabel.set_text(string)
def hide_next(self):
"""Hide the Next button"""
self.next.hide()
def show_next(self):
"""Show the Next button"""
self.next.show()
gobject.type_register(Searchbar) gobject.type_register(Searchbar)