fix some issues with recent-words completion, make the ConversationTabs...

fix some issues with recent-words completion, make the ConversationTabs closable with /unquery and ignore the keyboard shortcuts not handled.  fixed #1941
parent f729e79a
...@@ -1207,6 +1207,9 @@ class Core(object): ...@@ -1207,6 +1207,9 @@ class Core(object):
if isinstance(tab, PrivateTab): if isinstance(tab, PrivateTab):
self.tabs.remove(tab) self.tabs.remove(tab)
self.refresh_window() self.refresh_window()
if isinstance(tab, ConversationTab):
self.tabs.remove(tab)
self.refresh_window()
def command_query(self, arg): def command_query(self, arg):
""" """
......
...@@ -25,6 +25,9 @@ Window are displayed, etc ...@@ -25,6 +25,9 @@ Window are displayed, etc
MIN_WIDTH = 50 MIN_WIDTH = 50
MIN_HEIGHT = 16 MIN_HEIGHT = 16
import logging
log = logging.getLogger(__name__)
import window import window
import theme import theme
import curses import curses
...@@ -126,6 +129,12 @@ class Tab(object): ...@@ -126,6 +129,12 @@ class Tab(object):
""" """
raise NotImplementedError raise NotImplementedError
def on_close(self):
"""
Called when the tab is to be closed
"""
raise NotImplementedError
class InfoTab(Tab): class InfoTab(Tab):
""" """
The information tab, used to display global informations The information tab, used to display global informations
...@@ -181,6 +190,9 @@ class InfoTab(Tab): ...@@ -181,6 +190,9 @@ class InfoTab(Tab):
def just_before_refresh(self): def just_before_refresh(self):
return return
def on_close(self):
return
class MucTab(Tab): class MucTab(Tab):
""" """
The tab containing a multi-user-chat room. The tab containing a multi-user-chat room.
...@@ -251,31 +263,26 @@ class MucTab(Tab): ...@@ -251,31 +263,26 @@ class MucTab(Tab):
Complete the input with words recently said Complete the input with words recently said
""" """
# build the list of the recent words # build the list of the recent words
char_we_dont_want = [',', '(', ')', '.'] char_we_dont_want = [',', '(', ')', '.', '"', '\'', ' '] # The last one is nbsp
words = list() words = list()
for msg in self._room.messages[:-40:-1]: for msg in self._room.messages[:-40:-1]:
if not msg: if not msg:
continue continue
log.debug('line: %s\n'%msg)
for char in char_we_dont_want: for char in char_we_dont_want:
msg.txt.replace(char, ' ') msg.txt = msg.txt.replace(char, ' ')
for word in msg.txt.split(): for word in msg.txt.split():
if len(word) > 5: if len(word) >= 5 and word not in words:
words.append(word) words.append(word)
self.input.auto_completion(words, False) self.input.auto_completion(words, False)
def get_color_state(self): def get_color_state(self):
"""
"""
return self._room.color_state return self._room.color_state
def set_color_state(self, color): def set_color_state(self, color):
"""
"""
self._room.set_color_state(color) self._room.set_color_state(color)
def get_name(self): def get_name(self):
"""
"""
return self._room.name return self._room.name
def get_room(self): def get_room(self):
...@@ -305,6 +312,9 @@ class MucTab(Tab): ...@@ -305,6 +312,9 @@ class MucTab(Tab):
def just_before_refresh(self): def just_before_refresh(self):
self.input.move_cursor_to_pos() self.input.move_cursor_to_pos()
def on_close(self):
return
class PrivateTab(Tab): class PrivateTab(Tab):
""" """
The tab containg a private conversation (someone from a MUC) The tab containg a private conversation (someone from a MUC)
...@@ -374,6 +384,9 @@ class PrivateTab(Tab): ...@@ -374,6 +384,9 @@ class PrivateTab(Tab):
def just_before_refresh(self): def just_before_refresh(self):
return return
def on_close(self):
return
class RosterInfoTab(Tab): class RosterInfoTab(Tab):
""" """
A tab, splitted in two, containing the roster and infos A tab, splitted in two, containing the roster and infos
...@@ -523,6 +536,9 @@ class RosterInfoTab(Tab): ...@@ -523,6 +536,9 @@ class RosterInfoTab(Tab):
def just_before_refresh(self): def just_before_refresh(self):
return return
def on_close(self):
return
class ConversationTab(Tab): class ConversationTab(Tab):
""" """
The tab containg a normal conversation (someone from our roster) The tab containg a normal conversation (someone from our roster)
...@@ -597,6 +613,9 @@ class ConversationTab(Tab): ...@@ -597,6 +613,9 @@ class ConversationTab(Tab):
def just_before_refresh(self): def just_before_refresh(self):
return return
def on_close(self):
return
def jid_and_name_match(contact, txt): def jid_and_name_match(contact, txt):
""" """
A function used to know if a contact in the roster should A function used to know if a contact in the roster should
......
...@@ -64,7 +64,7 @@ class User(object): ...@@ -64,7 +64,7 @@ class User(object):
return True return True
def __repr__(self): def __repr__(self):
return ">%s<" % (self.nick.decode('utf-8')) return ">%s<" % (self.nick)
def __eq__(self, b): def __eq__(self, b):
return self.role == b.role and self.nick.lower() == b.nick.lower() return self.role == b.role and self.nick.lower() == b.nick.lower()
......
...@@ -976,8 +976,8 @@ class Input(Win): ...@@ -976,8 +976,8 @@ class Input(Win):
def do_command(self, key, reset=True): def do_command(self, key, reset=True):
if key in self.key_func: if key in self.key_func:
return self.key_func[key]() return self.key_func[key]()
# if not key or len(key) > 1: if not key or len(key) > 1:
# return # ignore non-handled keyboard shortcuts return # ignore non-handled keyboard shortcuts
self.reset_completion() self.reset_completion()
self.text = self.text[:self.pos+self.line_pos]+key+self.text[self.pos+self.line_pos:] self.text = self.text[:self.pos+self.line_pos]+key+self.text[self.pos+self.line_pos:]
(y, x) = self._win.getyx() (y, x) = self._win.getyx()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment