changeset 189:757518d05833

Primitivus: added nick completion
author Goffi <goffi@goffi.org>
date Wed, 18 Aug 2010 20:50:45 +0800
parents 22cbd3837233
children 31632472e857
files frontends/primitivus/primitivus
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/primitivus/primitivus	Wed Aug 18 17:27:33 2010 +0800
+++ b/frontends/primitivus/primitivus	Wed Aug 18 20:50:45 2010 +0800
@@ -227,11 +227,38 @@
         #self.center_part = urwid.Columns([('weight',2,self.contactList),('weight',8,Chat('',self))])
         self.center_part = urwid.Columns([('weight',2,self.contactList), ('weight',8,urwid.Filler(urwid.Text('')))])
         self.editBar = custom_widgets.AdvancedEdit('> ')
+        self.editBar.setCompletionMethod(self._nick_completion)
         urwid.connect_signal(self.editBar,'click',self.onTextEntered)
         self.menu_roller = self.__buildMenuRoller()
         self.main_widget = custom_widgets.FocusFrame(self.center_part, header=self.menu_roller, footer=self.editBar, focus_part='footer')
         return self.main_widget
 
+    def _nick_completion(self, text, completion_data):
+        """Completion method which complete pseudo in group chat
+        for params, see AdvancedEdit"""
+        contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once
+        if contact:
+            chat = self.chat_wins[contact]
+            if chat.type != "group":
+                return text
+            space = text.rfind(" ")
+            start = text[space+1:]
+            nicks = list(chat.occupants)
+            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 plug_profile(self, profile_key='@DEFAULT@'):
         self.loop.widget = self.__buildMainWidget() 
         QuickApp.plug_profile(self, profile_key)