comparison frontends/src/primitivus/chat.py @ 1971:9421e721d5e2

primitivus (chat): fixed nick completion. Completion is now managed per widget, if completion method exists
author Goffi <goffi@goffi.org>
date Mon, 27 Jun 2016 21:45:13 +0200
parents 200cd707a46d
children a9908e751c42
comparison
equal deleted inserted replaced
1970:200cd707a46d 1971:9421e721d5e2
153 return self.occupant_data.nick.lower() < other.occupant_data.nick.lower() 153 return self.occupant_data.nick.lower() < other.occupant_data.nick.lower()
154 154
155 @property 155 @property
156 def parent(self): 156 def parent(self):
157 return self.mess_data.parent 157 return self.mess_data.parent
158
159 @property
160 def nick(self):
161 return self.occupant_data.nick
158 162
159 def selectable(self): 163 def selectable(self):
160 return True 164 return True
161 165
162 def keypress(self, size, key): 166 def keypress(self, size, key):
251 self.chat_widget.header = None 255 self.chat_widget.header = None
252 self._invalidate() 256 self._invalidate()
253 257
254 return super(Chat, self).keypress(size, key) 258 return super(Chat, self).keypress(size, key)
255 259
260 def completion(self, text, completion_data):
261 """Completion method which complete nicknames in group chat
262
263 for params, see [sat_widgets.AdvancedEdit]
264 """
265 if self.type != C.CHAT_GROUP:
266 return text
267
268 space = text.rfind(" ")
269 start = text[space + 1:]
270 words = [w.nick for w in self.occupants_walker if isinstance(w, OccupantWidget) and w.nick.startswith(start)]
271 if not words:
272 return text
273 try:
274 word_idx = words.index(completion_data['last_word']) + 1
275 except (KeyError, ValueError):
276 word_idx = 0
277 else:
278 if word_idx == len(words):
279 word_idx = 0
280 word = completion_data['last_word'] = words[word_idx]
281 return u"{}{}{}".format(text[:space + 1], word, ': ' if space < 0 else '')
282
256 def getMenu(self): 283 def getMenu(self):
257 """Return Menu bar""" 284 """Return Menu bar"""
258 menu = sat_widgets.Menu(self.host.loop) 285 menu = sat_widgets.Menu(self.host.loop)
259 if self.type == C.CHAT_GROUP: 286 if self.type == C.CHAT_GROUP:
260 self.host.addMenus(menu, C.MENU_ROOM, {'room_jid': self.target.bare}) 287 self.host.addMenus(menu, C.MENU_ROOM, {'room_jid': self.target.bare})