diff browser_side/panels.py @ 232:0ed09cc0566f

browser_side: added UIs for rich text editor and addressing to multiple recipients The rich text format is set according to a user parameter which is for now not created, so you will get a warning on the backend and no toolbar will be displayed. For testing purpose: - you can set _debug to True in RichTextEditor: that will display one toolbar per format. - you can add this parameter to any plugin (the same will be added later in XEP-0071): # DEBUG: TO BE REMOVED LATER, THIS BELONGS TO RICH TEXT EDITOR FORMATS = {"markdown": {}, "bbcode": {}, "dokuwiki": {}, "html": {}} FORMAT_PARAM_KEY = "Composition and addressing" FORMAT_PARAM_NAME = "Format for rich text message composition" # In the parameter definition: <category name="%(format_category_name)s" label="%(format_category_label)s"> <param name="%(format_param_name)s" label="%(format_param_label)s" value="%(format_param_default)s" type="list" security="0"> %(format_options)s </param> </category> # Strings for the placeholders: 'format_category_name': FORMAT_PARAM_KEY, 'format_category_label': _(FORMAT_PARAM_KEY), 'format_param_name': FORMAT_PARAM_NAME, 'format_param_label': _(FORMAT_PARAM_NAME), 'format_param_default': FORMATS.keys()[0], 'format_options': ['<option value="%s"/>' % format for format in FORMATS.keys()]
author souliane <souliane@mailoo.org>
date Tue, 08 Oct 2013 14:12:38 +0200
parents fab7aa366576
children b304cdf13a3b
line wrap: on
line diff
--- a/browser_side/panels.py	Tue Oct 08 13:38:42 2013 +0200
+++ b/browser_side/panels.py	Tue Oct 08 14:12:38 2013 +0200
@@ -24,6 +24,7 @@
 from pyjamas.ui.AbsolutePanel import AbsolutePanel
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
+from pyjamas.ui.DialogBox import DialogBox
 from pyjamas.ui.HTMLPanel import HTMLPanel
 from pyjamas.ui.Frame import Frame
 from pyjamas.ui.TextArea import TextArea
@@ -45,20 +46,48 @@
 from time import time
 import dialog
 import base_widget
+from richtext import RichTextEditor
 from plugin_xep_0085 import ChatStateMachine
 from pyjamas import Window
 from __pyjamas__ import doc
 
 
-class UniBoxPanel(SimplePanel):
+class UniBoxPanel(HorizontalPanel):
     """Panel containing the UniBox"""
 
     def __init__(self, host):
-        SimplePanel.__init__(self)
+        HorizontalPanel.__init__(self)
+        self.host = host
         self.setStyleName('uniBoxPanel')
+
+        self.button = Button ('<img src="media/icons/tango/actions/32/format-text-italic.png" class="richTextIcon"/>')
+        self.button.setTitle('Open the rich text editor')
+        self.button.addStyleName('uniBoxButton')
+        self.add(self.button)
+
         self.unibox = UniBox(host)
-        self.unibox.setWidth('100%')
         self.add(self.unibox)
+        self.setCellWidth(self.unibox, '100%')
+
+        self.button.addClickListener(self.openRichTextEditor)
+        self.unibox.addDoubleClickListener(self.openRichTextEditor)
+
+    def openRichTextEditor(self):
+        """Open the rich text editor."""
+        self.button.setVisible(False)
+        self.unibox.setVisible(False)
+        self.setCellWidth(self.unibox, '0px')
+        self.host.panel._contactsMove(self)
+
+        def onCloseCallback():
+            self.host.panel._contactsMove(self.host.panel._hpanel)
+            self.setCellWidth(self.unibox, '100%')
+            self.button.setVisible(True)
+            self.unibox.setVisible(True)
+            self.host.resize()
+
+        RichTextEditor.getOrCreate(self.host, self, onCloseCallback)
+        self.host.resize()
 
 
 class UniBox(TextArea, MouseHandler): #AutoCompleteTextBox):
@@ -848,12 +877,12 @@
         status = host.status_panel
 
         # contacts
-        _contacts = HorizontalPanel()
-        _contacts.addStyleName('globalLeftArea')
+        self._contacts = HorizontalPanel()
+        self._contacts.addStyleName('globalLeftArea')
         contacts_switch = Button(u'«', self._contactsSwitch)
         contacts_switch.addStyleName('contactsSwitch')
-        _contacts.add(contacts_switch)
-        _contacts.add(self.host.contact_panel)
+        self._contacts.add(contacts_switch)
+        self._contacts.add(self.host.contact_panel)
 
         # tabs
         self.tab_panel = base_widget.MainTabPanel(host)
@@ -868,10 +897,10 @@
         header.setStyleName('header')
         self.add(header)
 
-        _hpanel = HorizontalPanel()
-        _hpanel.add(_contacts)
-        _hpanel.add(self.tab_panel)
-        self.add(_hpanel)
+        self._hpanel = HorizontalPanel()
+        self._hpanel.add(self._contacts)
+        self._hpanel.add(self.tab_panel)
+        self.add(self._hpanel)
 
         self.setWidth("100%")
         Window.addWindowResizeListener(self)
@@ -883,6 +912,17 @@
         btn.setText(u"«" if cpanel.getVisible() else u"»")
         self.host.resize()
 
+    def _contactsMove(self, parent):
+        """Move the contacts container (containing the contact list and
+        the "hide/show" button) to another parent, but always as the
+        first child position (insert at index 0).
+        """
+        if self._contacts.getParent():
+            if self._contacts.getParent() == parent:
+                return
+            self._contacts.removeFromParent()
+        parent.insert(self._contacts, 0)
+
     def onWindowResized(self, width, height):
         _elts = doc().getElementsByClassName('gwt-TabBar')
         if not _elts.length: