summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2013-08-02 22:00:53 +0200
committermathieui <mathieui@mathieui.net>2013-08-02 22:00:53 +0200
commit6fbb2f85938884286de4f4c0610b2389fcde4460 (patch)
treef1daf4f99b5aab830f55882619558bf9f33a3c3e /src
parentbb59771d9962dcd69c29b008031fd4ae9002915d (diff)
downloadpoezio-6fbb2f85938884286de4f4c0610b2389fcde4460.tar.gz
poezio-6fbb2f85938884286de4f4c0610b2389fcde4460.tar.bz2
poezio-6fbb2f85938884286de4f4c0610b2389fcde4460.tar.xz
poezio-6fbb2f85938884286de4f4c0610b2389fcde4460.zip
Fix #2317 (/join completion is broken)
Also add an override parameter to new_completion so that the completion does not care if the list matches the previous input or not.
Diffstat (limited to 'src')
-rw-r--r--src/core.py86
-rw-r--r--src/windows.py18
2 files changed, 64 insertions, 40 deletions
diff --git a/src/core.py b/src/core.py
index 9589f8e4..3bad8c97 100644
--- a/src/core.py
+++ b/src/core.py
@@ -1872,42 +1872,64 @@ class Core(object):
def completion_join(self, the_input):
"""
- Try to complete the server of the MUC's jid (for now only from the currently
- open ones)
- TODO: have a history of recently joined MUCs, and use that too
+ Completion for /join
+
+ Try to complete the MUC JID:
+ if only a resource is provided, complete with the default nick
+ if only a server is provided, complete with the rooms from the
+ disco#items of that server
+ if only a nodepart is provided, complete with the servers of the
+ current joined rooms
"""
- txt = the_input.get_text()
- if len(txt.split()) != 2:
+ n = the_input.get_argument_position(quoted=True)
+ args = common.shell_split(the_input.text)
+ if n != 1:
# we are not on the 1st argument of the command line
return False
- jid = safeJID(txt.split()[1])
- if jid.server:
- if jid.resource or jid.full.endswith('/'):
- # we are writing the resource: complete the node
- if not the_input.last_completion:
- try:
- response = self.xmpp.plugin['xep_0030'].get_items(jid=jid.server, block=True, timeout=1)
- except:
- response = None
- if response:
- items = response['disco_items'].get_items()
- else:
- return True
- items = ['%s/%s' % (tup[0], jid.resource) for tup in items]
- for _ in range(len(jid.server) + 2 + len(jid.resource)):
- the_input.key_backspace()
- else:
- items = []
- items.extend(list(self.pending_invites.keys()))
- the_input.auto_completion(items, '')
+ if len(args) == 1:
+ args.append('')
+ jid = safeJID(args[1])
+ if args[1].endswith('@') and not jid.user and not jid.server:
+ jid.user = args[1][:-1]
+
+ relevant_rooms = []
+ relevant_rooms.extend(sorted(self.pending_invites.keys()))
+ bookmarks = {str(elem.jid): False for elem in bookmark.bookmarks}
+ for tab in self.tabs:
+ if isinstance(tab, tabs.MucTab):
+ name = tab.get_name()
+ if name in bookmarks and not tab.joined:
+ bookmarks[name] = True
+ relevant_rooms.extend(sorted(room[0] for room in bookmarks.items() if room[1]))
+
+ if the_input.last_completion:
+ return the_input.new_completion([], 1, quotify=True)
+
+ if jid.server and not jid.user:
+ # no room was given: complete the node
+ try:
+ response = self.xmpp.plugin['xep_0030'].get_items(jid=jid.server, block=True, timeout=1)
+ except:
+ response = None
+ if response:
+ items = response['disco_items'].get_items()
else:
- # we are writing the server: complete the server
- serv_list = []
- for tab in self.tabs:
- if isinstance(tab, tabs.MucTab):
- serv_list.append('%s@%s'% (jid.user, safeJID(tab.get_name()).host))
- serv_list.extend(list(self.pending_invites.keys()))
- the_input.auto_completion(serv_list, '')
+ return True
+ items = sorted('%s/%s' % (tup[0], jid.resource) for tup in items)
+ return the_input.new_completion(items, 1, quotify=True, override=True)
+ elif jid.user:
+ # we are writing the server: complete the server
+ serv_list = []
+ for tab in self.tabs:
+ if isinstance(tab, tabs.MucTab) and tab.joined:
+ serv_list.append('%s@%s'% (jid.user, safeJID(tab.get_name()).host))
+ serv_list.extend(relevant_rooms)
+ return the_input.new_completion(serv_list, 1, quotify=True)
+ elif args[1].startswith('/'):
+ # we completing only a resource
+ return the_input.new_completion(['/%s' % self.own_nick], 1, quotify=True)
+ else:
+ return the_input.new_completion(relevant_rooms, 1, quotify=True)
return True
def command_bookmark_local(self, arg=''):
diff --git a/src/windows.py b/src/windows.py
index b35ad4ba..96c7ee1c 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -1383,7 +1383,7 @@ class Input(Win):
self.normal_completion(word_list, add_after)
return True
- def new_completion(self, word_list, argument_position=-1, add_after='', quotify=True):
+ def new_completion(self, word_list, argument_position=-1, add_after='', quotify=True, override=False):
"""
Complete the argument at position ``argument_postion`` in the input.
If ``quotify`` is ``True``, then the completion will operate on block of words
@@ -1403,11 +1403,11 @@ class Input(Win):
if argument_position == 0:
self._new_completion_first(word_list)
else:
- self._new_completion_args(word_list, argument_position, add_after, quotify)
+ self._new_completion_args(word_list, argument_position, add_after, quotify, override)
self.rewrite_text()
return True
- def _new_completion_args(self, word_list, argument_position=-1, add_after='', quoted=True):
+ def _new_completion_args(self, word_list, argument_position=-1, add_after='', quoted=True, override=False):
"""
Case for completing arguments with position ≠ 0
"""
@@ -1432,11 +1432,13 @@ class Input(Win):
if self.last_completion is not None:
self.hit_list.append(self.hit_list.pop(0))
else:
- hit_list = []
- for word in word_list:
- if word.lower().startswith(current_l):
- hit_list.append(word)
-
+ if override:
+ hit_list = word_list
+ else:
+ hit_list = []
+ for word in word_list:
+ if word.lower().startswith(current_l):
+ hit_list.append(word)
if not hit_list:
return
self.hit_list = hit_list