# HG changeset patch # User Goffi # Date 1467056713 -7200 # Node ID 9421e721d5e221f7b8861126398cebf404fefdce # Parent 200cd707a46df6b9754c26ea309b61fa9960ec9c primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists diff -r 200cd707a46d -r 9421e721d5e2 frontends/src/primitivus/chat.py --- a/frontends/src/primitivus/chat.py Mon Jun 27 21:45:11 2016 +0200 +++ b/frontends/src/primitivus/chat.py Mon Jun 27 21:45:13 2016 +0200 @@ -156,6 +156,10 @@ def parent(self): return self.mess_data.parent + @property + def nick(self): + return self.occupant_data.nick + def selectable(self): return True @@ -253,6 +257,29 @@ return super(Chat, self).keypress(size, key) + def completion(self, text, completion_data): + """Completion method which complete nicknames in group chat + + for params, see [sat_widgets.AdvancedEdit] + """ + if self.type != C.CHAT_GROUP: + return text + + space = text.rfind(" ") + start = text[space + 1:] + words = [w.nick for w in self.occupants_walker if isinstance(w, OccupantWidget) and w.nick.startswith(start)] + if not words: + return text + try: + word_idx = words.index(completion_data['last_word']) + 1 + except (KeyError, ValueError): + word_idx = 0 + else: + if word_idx == len(words): + word_idx = 0 + word = completion_data['last_word'] = words[word_idx] + return u"{}{}{}".format(text[:space + 1], word, ': ' if space < 0 else '') + def getMenu(self): """Return Menu bar""" menu = sat_widgets.Menu(self.host.loop) diff -r 200cd707a46d -r 9421e721d5e2 frontends/src/primitivus/primitivus --- a/frontends/src/primitivus/primitivus Mon Jun 27 21:45:11 2016 +0200 +++ b/frontends/src/primitivus/primitivus Mon Jun 27 21:45:13 2016 +0200 @@ -64,36 +64,16 @@ def _text_completion(self, text, completion_data, mode): if mode == C.MODE_INSERTION: - return self._nick_completion(text, completion_data) + if self.host.selected_widget is not None: + try: + completion = self.host.selected_widget.completion + except AttributeError: + return text + else: + return completion(text, completion_data) else: return text - def _nick_completion(self, text, completion_data): - """Completion method which complete pseudo in group chat - for params, see AdvancedEdit""" - nicks = [] - for profile, clist in self.host.contact_lists.iteritems(): - for contact in clist.selected: - chat = self.host.widgets.getWidget(quick_chat.QuickChat, contact, profile) - if chat.type != C.CHAT_GROUP: - continue - space = text.rfind(" ") - start = text[space + 1:] - nicks.extend(list(chat.occupants)) - if nicks: - nicks.sort() - try: - start_idx = nicks.index(completion_data['last_nick']) + 1 - if start_idx == len(nicks): - start_idx = 0 - except (KeyError, ValueError): - start_idx = 0 - for idx in range(start_idx, len(nicks)) + range(0, start_idx): - if nicks[idx].lower().startswith(start.lower()): - completion_data['last_nick'] = nicks[idx] - return text[:space + 1] + nicks[idx] + (': ' if space < 0 else '') - return text - def onTextEntered(self, editBar): """Called when text is entered in the main edit bar""" if self.mode == C.MODE_INSERTION: