Make the search usable again
- Disable the history when searching - → allow moving the cursor around to select a contact when searching - fix refresh issues
This commit is contained in:
parent
d3e1f8085e
commit
4a7e08f1c2
3 changed files with 32 additions and 10 deletions
|
@ -180,6 +180,7 @@ class Roster(object):
|
||||||
for group in self.groups.values():
|
for group in self.groups.values():
|
||||||
if not show_offline and group.get_nb_connected_contacts() == 0:
|
if not show_offline and group.get_nb_connected_contacts() == 0:
|
||||||
continue
|
continue
|
||||||
|
before = length
|
||||||
if not group.name in self.folded_groups:
|
if not group.name in self.folded_groups:
|
||||||
for contact in group.get_contacts(self.contact_filter):
|
for contact in group.get_contacts(self.contact_filter):
|
||||||
# We do not count the offline contacts (depending on config)
|
# We do not count the offline contacts (depending on config)
|
||||||
|
@ -190,7 +191,8 @@ class Roster(object):
|
||||||
if not contact.folded:
|
if not contact.folded:
|
||||||
# One for each resource, if the contact is unfolded
|
# One for each resource, if the contact is unfolded
|
||||||
length += len(contact)
|
length += len(contact)
|
||||||
length += 1 # One for the group's line itself
|
if not self.contact_filter or before != length:
|
||||||
|
length += 1 # One for the group's line itself if needed
|
||||||
return length
|
return length
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|
22
src/tabs.py
22
src/tabs.py
|
@ -2091,7 +2091,7 @@ class RosterInfoTab(Tab):
|
||||||
|
|
||||||
def completion(self):
|
def completion(self):
|
||||||
# Check if we are entering a command (with the '/' key)
|
# Check if we are entering a command (with the '/' key)
|
||||||
if isinstance(self.input, windows.CommandInput) and\
|
if isinstance(self.input, windows.Input) and\
|
||||||
not self.input.help_message:
|
not self.input.help_message:
|
||||||
self.complete_commands(self.input)
|
self.complete_commands(self.input)
|
||||||
|
|
||||||
|
@ -2480,7 +2480,7 @@ class RosterInfoTab(Tab):
|
||||||
if key == '^M':
|
if key == '^M':
|
||||||
selected_row = self.roster_win.get_selected_row()
|
selected_row = self.roster_win.get_selected_row()
|
||||||
res = self.input.do_command(key, raw=raw)
|
res = self.input.do_command(key, raw=raw)
|
||||||
if res and not isinstance(self.input, windows.CommandInput):
|
if res and not isinstance(self.input, windows.Input):
|
||||||
return True
|
return True
|
||||||
elif res:
|
elif res:
|
||||||
return False
|
return False
|
||||||
|
@ -2537,13 +2537,13 @@ class RosterInfoTab(Tab):
|
||||||
|
|
||||||
@refresh_wrapper.conditional
|
@refresh_wrapper.conditional
|
||||||
def move_cursor_down(self):
|
def move_cursor_down(self):
|
||||||
if isinstance(self.input, windows.CommandInput):
|
if isinstance(self.input, windows.Input) and not self.input.history_disabled:
|
||||||
return
|
return
|
||||||
return self.roster_win.move_cursor_down()
|
return self.roster_win.move_cursor_down()
|
||||||
|
|
||||||
@refresh_wrapper.conditional
|
@refresh_wrapper.conditional
|
||||||
def move_cursor_up(self):
|
def move_cursor_up(self):
|
||||||
if isinstance(self.input, windows.CommandInput):
|
if isinstance(self.input, windows.Input) and not self.input.history_disabled:
|
||||||
return
|
return
|
||||||
return self.roster_win.move_cursor_up()
|
return self.roster_win.move_cursor_up()
|
||||||
|
|
||||||
|
@ -2580,6 +2580,8 @@ class RosterInfoTab(Tab):
|
||||||
|
|
||||||
@refresh_wrapper.conditional
|
@refresh_wrapper.conditional
|
||||||
def on_space(self):
|
def on_space(self):
|
||||||
|
if isinstance(self.input, windows.Input):
|
||||||
|
return
|
||||||
selected_row = self.roster_win.get_selected_row()
|
selected_row = self.roster_win.get_selected_row()
|
||||||
if isinstance(selected_row, RosterGroup) or\
|
if isinstance(selected_row, RosterGroup) or\
|
||||||
isinstance(selected_row, Contact):
|
isinstance(selected_row, Contact):
|
||||||
|
@ -2649,6 +2651,7 @@ class RosterInfoTab(Tab):
|
||||||
self.input.key_end()
|
self.input.key_end()
|
||||||
self.input.refresh()
|
self.input.refresh()
|
||||||
|
|
||||||
|
@refresh_wrapper.always
|
||||||
def start_search(self):
|
def start_search(self):
|
||||||
"""
|
"""
|
||||||
Start the search. The input should appear with a short instruction
|
Start the search. The input should appear with a short instruction
|
||||||
|
@ -2657,22 +2660,25 @@ class RosterInfoTab(Tab):
|
||||||
curses.curs_set(1)
|
curses.curs_set(1)
|
||||||
self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter)
|
self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter)
|
||||||
self.input.resize(1, self.width, self.height-1, 0)
|
self.input.resize(1, self.width, self.height-1, 0)
|
||||||
|
self.input.disable_history()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@refresh_wrapper.always
|
||||||
def start_search_slow(self):
|
def start_search_slow(self):
|
||||||
curses.curs_set(1)
|
curses.curs_set(1)
|
||||||
self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter_slow)
|
self.input = windows.CommandInput("[Search]", self.on_search_terminate, self.on_search_terminate, self.set_roster_filter_slow)
|
||||||
self.input.resize(1, self.width, self.height-1, 0)
|
self.input.resize(1, self.width, self.height-1, 0)
|
||||||
|
self.input.disable_history()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_roster_filter_slow(self, txt):
|
def set_roster_filter_slow(self, txt):
|
||||||
roster.jids_filter = (jid_and_name_match_slow, txt)
|
roster.jids_filter = (jid_and_name_match_slow, txt)
|
||||||
self.roster_win.refresh(roster)
|
self.refresh()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_roster_filter(self, txt):
|
def set_roster_filter(self, txt):
|
||||||
roster.contact_filter = (jid_and_name_match, txt)
|
roster.contact_filter = (jid_and_name_match, txt)
|
||||||
self.roster_win.refresh(roster)
|
self.refresh()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_search_terminate(self, txt):
|
def on_search_terminate(self, txt):
|
||||||
|
@ -3095,7 +3101,7 @@ class MucListTab(Tab):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def completion(self):
|
def completion(self):
|
||||||
if isinstance(self.input, windows.CommandInput):
|
if isinstance(self.input, windows.Input):
|
||||||
self.complete_commands(self.input)
|
self.complete_commands(self.input)
|
||||||
|
|
||||||
def on_input(self, key, raw):
|
def on_input(self, key, raw):
|
||||||
|
@ -3229,7 +3235,7 @@ class XMLTab(Tab):
|
||||||
return self.reset_help_message()
|
return self.reset_help_message()
|
||||||
|
|
||||||
def completion(self):
|
def completion(self):
|
||||||
if isinstance(self.input, windows.CommandInput):
|
if isinstance(self.input, windows.Input):
|
||||||
self.complete_commands(self.input)
|
self.complete_commands(self.input)
|
||||||
|
|
||||||
def on_input(self, key, raw):
|
def on_input(self, key, raw):
|
||||||
|
|
|
@ -1433,6 +1433,19 @@ class CommandInput(Input):
|
||||||
self.on_input(self.get_text())
|
self.on_input(self.get_text())
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def disable_history(self):
|
||||||
|
"""
|
||||||
|
Disable the history (up/down) keys
|
||||||
|
"""
|
||||||
|
if 'KEY_UP' in self.key_func:
|
||||||
|
del self.key_func['KEY_UP']
|
||||||
|
if 'KEY_DOWN' in self.key_func:
|
||||||
|
del self.key_func['KEY_DOWN']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def history_disabled(self):
|
||||||
|
return ('KEY_UP' not in self.key_func and 'KEY_DOWN' not in self.key_func)
|
||||||
|
|
||||||
def success(self):
|
def success(self):
|
||||||
"""
|
"""
|
||||||
call the success callback, passing the text as argument
|
call the success callback, passing the text as argument
|
||||||
|
@ -1617,7 +1630,7 @@ class RosterWin(Win):
|
||||||
self.draw_roster_information(roster)
|
self.draw_roster_information(roster)
|
||||||
y = 1
|
y = 1
|
||||||
show_offline = config.get('roster_show_offline', 'false') == 'true'
|
show_offline = config.get('roster_show_offline', 'false') == 'true'
|
||||||
sort = config.get('roster_sort', 'jid_show') or 'jid_show'
|
sort = config.get('roster_sort', 'jid:show') or 'jid:show'
|
||||||
group_sort = config.get('roster_group_sort', 'name') or 'name'
|
group_sort = config.get('roster_group_sort', 'name') or 'name'
|
||||||
for group in roster.get_groups(group_sort):
|
for group in roster.get_groups(group_sort):
|
||||||
contacts_filtered = group.get_contacts(roster.contact_filter)
|
contacts_filtered = group.get_contacts(roster.contact_filter)
|
||||||
|
@ -1658,6 +1671,7 @@ class RosterWin(Win):
|
||||||
self.draw_plus(self.height-1)
|
self.draw_plus(self.height-1)
|
||||||
self._refresh()
|
self._refresh()
|
||||||
|
|
||||||
|
|
||||||
def draw_plus(self, y):
|
def draw_plus(self, y):
|
||||||
"""
|
"""
|
||||||
Draw the indicator that shows that
|
Draw the indicator that shows that
|
||||||
|
|
Loading…
Reference in a new issue