parent
2df471eaf3
commit
80f2bb884d
|
@ -22,6 +22,7 @@ class Searchbar(gtk.HBox):
|
||||||
reslabel = None
|
reslabel = None
|
||||||
next = None
|
next = None
|
||||||
prev = None
|
prev = None
|
||||||
|
wrap = None
|
||||||
|
|
||||||
vte = None
|
vte = None
|
||||||
config = None
|
config = None
|
||||||
|
@ -79,16 +80,31 @@ class Searchbar(gtk.HBox):
|
||||||
self.prev.set_sensitive(False)
|
self.prev.set_sensitive(False)
|
||||||
self.prev.connect('clicked', self.prev_search)
|
self.prev.connect('clicked', self.prev_search)
|
||||||
|
|
||||||
|
# Wrap checkbox
|
||||||
|
self.wrap = gtk.CheckButton(_('Wrap'))
|
||||||
|
self.wrap.show()
|
||||||
|
self.wrap.set_sensitive(True)
|
||||||
|
self.wrap.connect('toggled', self.wrap_toggled)
|
||||||
|
|
||||||
self.pack_start(label, False)
|
self.pack_start(label, False)
|
||||||
self.pack_start(self.entry)
|
self.pack_start(self.entry)
|
||||||
self.pack_start(self.reslabel, False)
|
self.pack_start(self.reslabel, False)
|
||||||
self.pack_start(self.prev, False, False)
|
self.pack_start(self.prev, False, False)
|
||||||
self.pack_start(self.next, False, False)
|
self.pack_start(self.next, False, False)
|
||||||
|
self.pack_start(self.wrap, False, False)
|
||||||
self.pack_end(close, False, False)
|
self.pack_end(close, False, False)
|
||||||
|
|
||||||
self.hide()
|
self.hide()
|
||||||
self.set_no_show_all(True)
|
self.set_no_show_all(True)
|
||||||
|
|
||||||
|
def wrap_toggled(self, toggled):
|
||||||
|
if self.searchrow is None:
|
||||||
|
self.prev.set_sensitive(False)
|
||||||
|
self.next.set_sensitive(False)
|
||||||
|
elif toggled:
|
||||||
|
self.prev.set_sensitive(True)
|
||||||
|
self.next.set_sensitive(True)
|
||||||
|
|
||||||
def get_vte(self):
|
def get_vte(self):
|
||||||
"""Find our parent widget"""
|
"""Find our parent widget"""
|
||||||
parent = self.get_parent()
|
parent = self.get_parent()
|
||||||
|
@ -101,6 +117,9 @@ class Searchbar(gtk.HBox):
|
||||||
key = gtk.gdk.keyval_name(event.keyval)
|
key = gtk.gdk.keyval_name(event.keyval)
|
||||||
if key == 'Escape':
|
if key == 'Escape':
|
||||||
self.end_search()
|
self.end_search()
|
||||||
|
else:
|
||||||
|
self.prev.set_sensitive(False)
|
||||||
|
self.next.set_sensitive(False)
|
||||||
|
|
||||||
def start_search(self):
|
def start_search(self):
|
||||||
"""Show ourselves"""
|
"""Show ourselves"""
|
||||||
|
@ -117,7 +136,7 @@ class Searchbar(gtk.HBox):
|
||||||
return
|
return
|
||||||
|
|
||||||
if searchtext != self.searchstring:
|
if searchtext != self.searchstring:
|
||||||
self.searchrow = self.get_vte_buffer_range()[0]
|
self.searchrow = self.get_vte_buffer_range()[0] - 1
|
||||||
self.searchstring = searchtext
|
self.searchstring = searchtext
|
||||||
self.searchre = re.compile(searchtext)
|
self.searchre = re.compile(searchtext)
|
||||||
|
|
||||||
|
@ -129,42 +148,50 @@ class Searchbar(gtk.HBox):
|
||||||
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"""
|
||||||
startrow,endrow = self.get_vte_buffer_range()
|
startrow,endrow = self.get_vte_buffer_range()
|
||||||
|
found = startrow <= self.searchrow and self.searchrow < endrow
|
||||||
|
row = self.searchrow
|
||||||
while True:
|
while True:
|
||||||
if self.searchrow >= endrow:
|
row += 1
|
||||||
self.searchrow = startrow
|
if row >= endrow:
|
||||||
self.reslabel.set_text(_('No more results'))
|
if found and self.wrap.get_active():
|
||||||
return
|
row = startrow - 1
|
||||||
buffer = self.vte.get_text_range(self.searchrow, 0,
|
else:
|
||||||
self.searchrow+1, 0,
|
self.prev.set_sensitive(found)
|
||||||
self.search_character)
|
self.next.set_sensitive(False)
|
||||||
|
self.reslabel.set_text(_('No more results'))
|
||||||
|
return
|
||||||
|
buffer = self.vte.get_text_range(row, 0, row + 1, 0, self.search_character)
|
||||||
|
|
||||||
matches = self.searchre.search(buffer)
|
matches = self.searchre.search(buffer)
|
||||||
if matches:
|
if matches:
|
||||||
|
self.searchrow = row
|
||||||
|
self.prev.set_sensitive(True)
|
||||||
self.search_hit(self.searchrow)
|
self.search_hit(self.searchrow)
|
||||||
self.searchrow += 1
|
|
||||||
return
|
return
|
||||||
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"""
|
||||||
startrow,endrow = self.get_vte_buffer_range()
|
startrow,endrow = self.get_vte_buffer_range()
|
||||||
|
found = startrow <= self.searchrow and self.searchrow < endrow
|
||||||
|
row = self.searchrow
|
||||||
while True:
|
while True:
|
||||||
if self.searchrow <= startrow:
|
row -= 1
|
||||||
self.searchrow = endrow
|
if row <= startrow:
|
||||||
self.reslabel.set_text(_('No more results'))
|
if found and self.wrap.get_active():
|
||||||
return
|
row = endrow
|
||||||
buffer = self.vte.get_text_range(self.searchrow, 0,
|
else:
|
||||||
self.searchrow+1, 0,
|
self.next.set_sensitive(found)
|
||||||
self.search_character)
|
self.prev.set_sensitive(False)
|
||||||
|
self.reslabel.set_text(_('No more results'))
|
||||||
|
return
|
||||||
|
buffer = self.vte.get_text_range(row, 0, row + 1, 0, self.search_character)
|
||||||
|
|
||||||
matches = self.searchre.search(buffer)
|
matches = self.searchre.search(buffer)
|
||||||
if matches:
|
if matches:
|
||||||
|
self.searchrow = row
|
||||||
|
self.next.set_sensitive(True)
|
||||||
self.search_hit(self.searchrow)
|
self.search_hit(self.searchrow)
|
||||||
self.searchrow -= 1
|
|
||||||
return
|
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"""
|
||||||
|
|
Loading…
Reference in New Issue