diff src/browser/sat_browser/panels.py @ 496:0924710b666a

browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
author souliane <souliane@mailoo.org>
date Thu, 17 Jul 2014 12:59:33 +0200
parents 587fe75d1b16
children 60be99de3808
line wrap: on
line diff
--- a/src/browser/sat_browser/panels.py	Tue Jul 15 18:45:33 2014 +0200
+++ b/src/browser/sat_browser/panels.py	Thu Jul 17 12:59:33 2014 +0200
@@ -482,19 +482,12 @@
 
     def onClick(self, sender):
         if sender == self:
-            try:  # prevent re-selection of the main entry after a comment has been focused
-                if self.__ignoreNextEvent:
-                    self.__ignoreNextEvent = False
-                    return
-            except AttributeError:
-                pass
             self._blog_panel.setSelectedEntry(self)
         elif sender == self.delete_label:
             self._delete()
         elif sender == self.update_label:
             self.edit(True)
         elif sender == self.comment_label:
-            self.__ignoreNextEvent = True
             self._comment()
 
     def __modifiedCb(self, content):
@@ -586,7 +579,7 @@
         """Add an empty entry for a new comment"""
         if self._current_comment:
             self._current_comment.bubble.setFocus(True)
-            self._blog_panel.setSelectedEntry(self._current_comment)
+            self._blog_panel.setSelectedEntry(self._current_comment, True)
             return
         data = {'id': str(time()),
                 'new': True,
@@ -602,7 +595,7 @@
         entry._parent_entry = self
         self._current_comment = entry
         self.edit(True, entry)
-        self._blog_panel.setSelectedEntry(entry)
+        self._blog_panel.setSelectedEntry(entry, True)
 
     def edit(self, edit, entry=None):
         """Toggle the bubble between display and edit mode
@@ -928,24 +921,38 @@
                         self.selected_entry = None
                         break
 
-    def setSelectedEntry(self, entry):
+    def ensureVisible(self, entry):
+        """Scroll to an entry to ensure its visibility
+
+        @param entry (MicroblogEntry): the entry
+        """
         try:
             self.vpanel.getParent().ensureVisible(entry)  # scroll to the clicked entry
         except AttributeError:
             log.warning("FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!")
-        removeStyle = lambda entry: entry.removeStyleName('selected_entry')
+
+    def setSelectedEntry(self, entry, ensure_visible=False):
+        """Select an entry.
+
+        @param entry (MicroblogEntry): the entry to select
+        @param ensure_visible (boolean): if True, also scroll to the entry
+        """
+        if ensure_visible:
+            self.ensureVisible(entry)
+
         if not self.host.uni_box or not entry.comments:
             entry.addStyleName('selected_entry')  # blink the clicked entry
             clicked_entry = entry  # entry may be None when the timer is done
-            Timer(500, lambda timer: removeStyle(clicked_entry))
+            Timer(500, lambda timer: clicked_entry.removeStyleName('selected_entry'))
         if not self.host.uni_box:
             return  # unibox is disabled
+
         # from here the previous behavior (toggle main item selection) is conserved
         entry = entry if entry.comments else None
         if self.selected_entry == entry:
             entry = None
         if self.selected_entry:
-            removeStyle(self.selected_entry)
+            self.selected_entry.removeStyleName('selected_entry')
         if entry:
             log.debug("microblog entry selected (author=%s)" % entry.author)
             entry.addStyleName('selected_entry')