Skip to content

Commit

Permalink
Browse: Improve autocomplete list #4081
Browse files Browse the repository at this point in the history
Makes the lists scrolleable (upto max 20 entries).
Number of entries increased to 20.
Can be scrolled through both up/down arrow keys and mouse scroller.
Puts the URL below the Title, so more url text is visible now.
  • Loading branch information
iamutkarshtiwari committed Mar 16, 2016
1 parent dae11d7 commit c4648c0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion places.py
Expand Up @@ -34,7 +34,7 @@ def __init__(self, uri=''):


class SqliteStore(object):
MAX_SEARCH_MATCHES = 7
MAX_SEARCH_MATCHES = 20
EXPIRE_DAYS = 30

def __init__(self):
Expand Down
45 changes: 27 additions & 18 deletions webtoolbar.py
Expand Up @@ -61,8 +61,8 @@ def __init__(self):


class WebEntry(iconentry.IconEntry):
_COL_ADDRESS = 0
_COL_TITLE = 1
_COL_ADDRESS = 1
_COL_TITLE = 0

def __init__(self):
GObject.GObject.__init__(self)
Expand All @@ -71,8 +71,14 @@ def __init__(self):
self._search_view = self._search_create_view()

self._search_window = _SearchWindow()
self._search_window.add(self._search_view)
self._search_window_scroll = Gtk.ScrolledWindow()
self._search_window_scroll.set_policy(Gtk.PolicyType.NEVER,
Gtk.PolicyType.AUTOMATIC)
self._search_window_scroll.set_min_content_height(200)
self._search_window_scroll.add(self._search_view)
self._search_window.add(self._search_window_scroll)
self._search_view.show()
self._search_window_scroll.show()

self.connect('focus-in-event', self.__focus_in_event_cb)
self.connect('populate-popup', self.__populate_popup_cb)
Expand Down Expand Up @@ -142,20 +148,9 @@ def _search_create_view(self):
cell.props.ellipsize_set = True
cell.props.height = style.STANDARD_ICON_SIZE
cell.props.xpad = _SEARCH_ENTRY_MARGIN
cell.props.font = 'Bold'
column.pack_start(cell, True)

column.add_attribute(cell, 'text', self._COL_TITLE)

cell = Gtk.CellRendererText()
cell.props.xpad = _SEARCH_ENTRY_MARGIN
cell.props.xalign = 0
cell.props.ellipsize = Pango.EllipsizeMode.END
cell.props.ellipsize_set = True
cell.props.alignment = Pango.Alignment.LEFT
column.pack_start(cell, True)

column.add_attribute(cell, 'text', self._COL_ADDRESS)
column.add_attribute(cell, 'markup', self._COL_TITLE)

return view

Expand All @@ -164,7 +159,8 @@ def _search_update(self):

search_text = self.props.text.decode('utf-8')
for place in places.get_store().search(search_text):
list_store.append([place.uri, place.title])
title = '<span weight="bold" >%s</span>' % (place.title)
list_store.append([title + '\n' + place.uri, place.uri])

self._search_view.set_model(list_store)

Expand Down Expand Up @@ -217,7 +213,8 @@ def __key_press_event_cb(self, entry, event):
up_iter = model.iter_previous(selected)
if up_iter:
selection.select_iter(up_iter)
self._set_text(model.get(up_iter, 0)[0])
self._set_text(model.get(up_iter, self._COL_ADDRESS)[0])
self.set_vadjustments(selection)
return True
elif keyname == 'Down':
if selected is None:
Expand All @@ -226,7 +223,8 @@ def __key_press_event_cb(self, entry, event):
down_iter = model.iter_next(selected)
if down_iter:
selection.select_iter(down_iter)
self._set_text(model.get(down_iter, 0)[0])
self._set_text(model.get(down_iter, self._COL_ADDRESS)[0])
self.set_vadjustments(selection)
return True
elif keyname == 'Return':
if selected is None:
Expand All @@ -240,6 +238,17 @@ def __key_press_event_cb(self, entry, event):
return True
return False

def set_vadjustments(self, selection):
# Sets the vertical adjustments of the scrolled window
# on 'Up'/'Down' keypress
path = (selection.get_selected_rows()[1])[0]
index = path.get_indices()[0]
adjustment = self._search_window_scroll.get_vadjustment()
value = adjustment.get_value()
step = style.STANDARD_ICON_SIZE
adjustment.set_value(step * index)
self._search_window_scroll.set_vadjustment(adjustment)

def __popup_unmap_cb(self, entry):
self.handler_unblock(self._focus_out_hid)

Expand Down

0 comments on commit c4648c0

Please sign in to comment.