# HG changeset patch # User souliane # Date 1384007499 -3600 # Node ID da0487f0a2e740821b51e7cf2e9816c72e681bf7 # Parent 28d3315a8003f20a4f8c532bfb8866b8ec5817e0 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 diff -r 28d3315a8003 -r da0487f0a2e7 browser_side/contact.py --- 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) diff -r 28d3315a8003 -r da0487f0a2e7 browser_side/dialog.py --- a/browser_side/dialog.py Sat Nov 09 09:38:17 2013 +0100 +++ b/browser_side/dialog.py Sat Nov 09 15:31:39 2013 +0100 @@ -298,6 +298,8 @@ def onGroupInput(self, sender): text = sender.getText() + if text == "": + return for group in self.groups: if text == group: Window.alert("The group '%s' already exists." % text) diff -r 28d3315a8003 -r da0487f0a2e7 browser_side/panels.py --- a/browser_side/panels.py Sat Nov 09 09:38:17 2013 +0100 +++ b/browser_side/panels.py Sat Nov 09 15:31:39 2013 +0100 @@ -114,6 +114,10 @@ #self.getCompletionItems().completions.append(key) def removeKey(self, key): + return + # TODO: investigate why AutoCompleteTextBox doesn't work here, + # maybe it can work on a TextBox but no TextArea. Remove addKey + # and removeKey methods if they don't serve anymore. try: self.getCompletionItems().completions.remove(key) except KeyError: @@ -890,9 +894,9 @@ # contacts self._contacts = HorizontalPanel() self._contacts.addStyleName('globalLeftArea') - contacts_switch = Button(u'«', self._contactsSwitch) - contacts_switch.addStyleName('contactsSwitch') - self._contacts.add(contacts_switch) + self.contacts_switch = Button(u'«', self._contactsSwitch) + self.contacts_switch.addStyleName('contactsSwitch') + self._contacts.add(self.contacts_switch) self._contacts.add(self.host.contact_panel) # tabs @@ -916,8 +920,10 @@ self.setWidth("100%") Window.addWindowResizeListener(self) - def _contactsSwitch(self, btn): + def _contactsSwitch(self, btn=None): """ (Un)hide contacts panel """ + if btn is None: + btn = self.contacts_switch cpanel = self.host.contact_panel cpanel.setVisible(not cpanel.getVisible()) btn.setText(u"«" if cpanel.getVisible() else u"»")