diff browser_side/contact.py @ 255:da0487f0a2e7

browser_side: small changes to prepare the contact group manager: - group and contact lists are sorted - avoid adding empty group in the "Add group" panel - allow to show/hide the contact panel from another class
author souliane <souliane@mailoo.org>
date Sat, 09 Nov 2013 15:31:39 +0100
parents b77940d8a9bf
children 30c01671e338
line wrap: on
line diff
--- a/browser_side/contact.py	Sat Nov 09 09:38:17 2013 +0100
+++ b/browser_side/contact.py	Sat Nov 09 15:31:39 2013 +0100
@@ -89,7 +89,12 @@
         _item = GroupLabel(self._parent.host, group)
         _item.addMouseListener(self._parent)
         DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
-        VerticalPanel.add(self, _item)
+        index = 0
+        for group_ in [group.group for group in self.getChildren()]:
+            if group_ > group:
+                break
+            index += 1
+        VerticalPanel.insert(self, _item, index)
 
     def remove(self, group):
         for wid in self:
@@ -105,15 +110,20 @@
     def __init__(self, host):
         VerticalPanel.__init__(self)
         self.host = host
-        self.contacts = set()
+        self.contacts = []
 
     def add(self, jid, name=None, item_cb=None):
         if jid in self.contacts:
             return
-        self.contacts.add(jid)
+        index = 0
+        for contact_ in self.contacts:
+            if contact_ > jid:
+                break
+            index += 1
+        self.contacts.insert(index, jid)
         _item = ContactLabel(self.host, jid, name)
         DOM.setStyleAttribute(_item.getElement(), "cursor", "pointer")
-        VerticalPanel.add(self, _item)
+        VerticalPanel.insert(self, _item, index)
         if item_cb is not None:
             item_cb(_item)