diff browser_side/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 f4efffb9627c
children a74a2dfbe4f5
line wrap: on
line diff
--- a/browser_side/panels.py	Wed Feb 19 14:17:03 2014 +0100
+++ b/browser_side/panels.py	Wed Feb 19 16:38:13 2014 +0100
@@ -232,7 +232,6 @@
     def onKeyPress(self, sender, keycode, modifiers):
         _txt = self.getText()
         target_hook, type_, msg = self._getTarget(_txt)
-        self.host.showWarning(type_, msg)
 
         if keycode == KEY_ENTER:
             if _txt:
@@ -242,6 +241,8 @@
                     self.host._updateInputHistory(_txt)
                     self.setText('')
             self.host.showWarning(None, None)
+        else:
+            self.host.showWarning(type_, msg)
         MessageBox.onKeyPress(self, sender, keycode, modifiers)
 
     def getTargetAndData(self):
@@ -529,6 +530,13 @@
         self.bubble.setStyleName("bubble")
         self.entry_dialog.add(self.bubble)
         self.bubble.edit(False)
+        self.bubble.addEditListener(self.__showWarning)
+
+    def __showWarning(self, sender, keycode):
+        if keycode == KEY_ENTER:
+            self._blog_panel.host.showWarning(None, None)
+        else:
+            self._blog_panel.host.showWarning(*self._blog_panel.getWarningData(self.type == 'comment'))
 
     def _delete(self, empty=False):
         """Ask confirmation for deletion.
@@ -647,13 +655,18 @@
         entity.sort()  # sort() do not return the sorted list: do it here, not on the "return" line
         return self.accepted_groups == entity
 
-    def getWarningData(self):
-        if self.selected_entry:
-            if not self.selected_entry.comments:
+    def getWarningData(self, comment=None):
+        """
+        @param comment: True if the composed message is a comment. If None, consider we are
+        composing from the unibox and guess the message type from self.selected_entry
+        @return: a couple (type, msg) for calling self.host.showWarning"""
+        if comment is None:  # composing from the unibox
+            if self.selected_entry and not self.selected_entry.comments:
                 print ("ERROR: an item without comment is selected")
                 return ("NONE", None)
+            comment = self.selected_entry is not None
+        if comment:
             return ("PUBLIC", "This is a <span class='warningTarget'>comment</span> and keep the initial post visibility, so it is potentialy public")
-
         elif not self._accepted_groups:
             # we have a meta MicroblogPanel, we publish publicly
             return ("PUBLIC", self.warning_msg_public)