diff browser_side/base_panels.py @ 362:019e1e706e74

browser_side: display the popup notifying the message's recipient when you edit the blog entry's bubble.
author souliane <souliane@mailoo.org>
date Wed, 19 Feb 2014 16:38:13 +0100
parents df743589bb8c
children 30d03d9f07e4
line wrap: on
line diff
--- a/browser_side/base_panels.py	Wed Feb 19 14:17:03 2014 +0100
+++ b/browser_side/base_panels.py	Wed Feb 19 16:38:13 2014 +0100
@@ -321,6 +321,7 @@
         self.__modifiedCb = modifiedCb
         self._afterEditCb = afterEditCb
         self.initialized = False
+        self.edit_listeners = []
         self.setContent(content)
 
     def setContent(self, content=None):
@@ -414,6 +415,11 @@
     def abortEdition(self, content):
         return True
 
+    def addEditListener(self, listener):
+        """Add a method to be called whenever the text is edited.
+        @param listener: method taking two arguments: sender, keycode"""
+        self.edit_listeners.append(listener)
+
 
 class LightTextEditor(BaseTextEditor, HTML, FocusHandler, KeyboardHandler):
     """Manage a simple text editor whith the HTML 5 "contenteditable" property."""
@@ -430,7 +436,7 @@
         HTML.__init__(self)
         if single_line:
             FocusHandler.__init__(self)
-            KeyboardHandler.__init__(self)
+        KeyboardHandler.__init__(self)
         self.__single_line = single_line
         self.__enhance_display = enhance_display
         strproc = lambda text: html_sanitize(html_strip(text)) if self.__single_line else html_strip(text)
@@ -451,14 +457,14 @@
         if edit:
             if self.__single_line:
                 self.addFocusListener(self)
-                self.addKeyboardListener(self)
+            self.addKeyboardListener(self)
         else:
             self.setDisplayContent()
             if self.__single_line:
                 if self in self._focusListeners:
                     self.removeFocusListener(self)
-                if self in self._keyboardListeners:
-                    self.removeKeyboardListener(self)
+            if self in self._keyboardListeners:
+                self.removeKeyboardListener(self)
 
     def setDisplayContent(self):
         text = addURLToImage(self._original_content['text'])
@@ -470,7 +476,13 @@
         else:
             self.getElement().blur()
 
+    def onKeyDown(self, sender, keycode, modifiers):
+        for listener in self.edit_listeners:
+            listener(self, keycode)
+
     def onKeyPress(self, sender, keycode, modifiers):
+        if not self.__single_line:
+            return
         if keycode == KEY_ENTER:
             self.setFocus(False)  # finish the edition