changeset 315:09205b410a53

browser_side: handle successive click on blog post "edit" and "comment" icons
author souliane <souliane@mailoo.org>
date Thu, 02 Jan 2014 16:10:27 +0100
parents 70ac3067d641
children 4148f8f4caa0
files browser_side/panels.py
diffstat 1 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/panels.py	Mon Dec 30 13:02:03 2013 +0100
+++ b/browser_side/panels.py	Thu Jan 02 16:10:27 2014 +0100
@@ -422,7 +422,7 @@
     def _setContent(self):
         """Actually set the entry content (header, icons, bubble...)"""
         self.delete_label = self.update_label = self.comment_label = None
-        self.bubble = self.editbox = None
+        self.bubble = self.editbox = self._current_comment = None
         self._setHeader()
         if self.empty:
             self.editable_content = ['', const.SYNTAX_XHTML]
@@ -505,8 +505,10 @@
         def removeNewEntry():
             if self.empty:
                 self._blog_panel.removeEntry(self.type, self.id)
-                if self.type == 'main_item':
+                if self.type == 'main_item':  # restore the "New message" button
                     self._blog_panel.setUniBox(enable=False)
+                else:  # allow to create a new comment
+                    self._parent_entry._current_comment = None
 
         if cancel or new_text == self.editable_content[0] or new_text == "":
             removeNewEntry()
@@ -528,17 +530,17 @@
         """Set the bubble or the editor
         @param edit: set to True to display the editor"""
         if edit:
+            if self.editbox and self.editbox.getVisible():
+                self.editbox.setFocus(True)
+                return
             if self.empty or self.xhtml:
-                if not self.editbox:
-
-                    def cb(result):
-                        self._updateContent(result == richtext.CANCEL)
+                def cb(result):
+                    self._updateContent(result == richtext.CANCEL)
 
-                    options = ('no_recipient', 'no_sync_unibox', 'no_style', 'update_msg', 'no_close')
-                    editor = richtext.RichTextEditor(self._blog_panel.host, self.panel, cb, options=options)
-                    editor.setWidth('100%')
-                    self.editbox = editor.textarea
-
+                options = ('no_recipient', 'no_sync_unibox', 'no_style', 'update_msg', 'no_close')
+                editor = richtext.RichTextEditor(self._blog_panel.host, self.panel, cb, options=options)
+                editor.setWidth('100%')
+                self.editbox = editor.textarea
                 editor.setVisible(True)  # needed to build the toolbar
                 if self.editable_content[0]:
                     self._blog_panel.host.bridge.call('syntaxConvert', lambda d: self._setOriginalText(d, editor),
@@ -590,6 +592,9 @@
 
     def _comment(self):
         """Add an empty entry for a new comment"""
+        if self._current_comment:
+            self._current_comment.editbox.setFocus(True)
+            return
         data = {'id': str(time()),
                 'new': True,
                 'type': 'comment',
@@ -599,6 +604,7 @@
                 }
         entry = self._blog_panel.addEntry(data)
         entry._parent_entry = self
+        self._current_comment = entry
         entry.setEntryDialog(edit=True)