changeset 294:a6b3715f0bd6

browser_side: bug fixes for switching between unibox and rich text editor: - handle non selectable widget in UniBox._getTarget - reset the selection when selected LiberviaWidget is closed
author souliane <souliane@mailoo.org>
date Mon, 16 Dec 2013 16:39:03 +0100
parents 7c79d4d66161
children 33e0eb212b14
files browser_side/base_widget.py browser_side/panels.py
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/browser_side/base_widget.py	Sun Dec 15 12:01:25 2013 +0100
+++ b/browser_side/base_widget.py	Mon Dec 16 16:39:03 2013 +0100
@@ -177,12 +177,14 @@
         self.__close_button_id = HTMLPanel.createUniqueId()
         self.__title = Label(title)
         self.__title.setStyleName('widgetHeader_title')
+        self._close_listeners = []
         header = WidgetHeader(self, self.__title)
         self.add(header)
         self.setSize('100%', '100%')
         self.addStyleName('widget')
         if self.__selectable:
             self.addClickListener(self)
+            self.addCloseListener(self.host.uni_box.onWidgetClosed)
         self.host.registerWidget(self)
 
     def getDebugName(self):
@@ -204,12 +206,19 @@
         """ Called when the close button is pushed """
         _widgetspanel = self.getWidgetsPanel()
         _widgetspanel.removeWidget(self)
+        for callback in self._close_listeners:
+            callback(self)
         self.onQuit()
 
     def onQuit(self):
         """ Called when the widget is actually ending """
         pass
 
+    def addCloseListener(self, callback):
+        """Add a close listener to this widget
+        @param callback: function to be called from self.onClose"""
+        self._close_listeners.append(callback)
+
     def refresh(self):
         """This can be overwritten by a child class to refresh the display when,
         instead of creating a new one, an existing widget is found and reused.
--- a/browser_side/panels.py	Sun Dec 15 12:01:25 2013 +0100
+++ b/browser_side/panels.py	Mon Dec 16 16:39:03 2013 +0100
@@ -187,7 +187,7 @@
         target = self._selected_cache
 
         def getSelectedOrStatus():
-            if target:
+            if target and target.isSelectable():
                 _type, msg = target.getWarningData()
                 target_hook = None  # we use the selected widget, not a hook
             else:
@@ -284,6 +284,8 @@
                 Window.alert("Sole the first group of the selected panel is taken in consideration: '%s'" % groups[0])
         elif isinstance(self._selected_cache, ChatPanel):
             target = self._selected_cache.target
+        else:
+            target = None
         return (_txt, target)
 
     def __onComposing(self):
@@ -300,6 +302,11 @@
     def onSelectedChange(self, selected):
         self._selected_cache = selected
 
+    def onWidgetClosed(self, lib_wid):
+        """Called when a libervia widget is closed"""
+        if self._selected_cache == lib_wid:
+            self.onSelectedChange(None)
+
     """def complete(self):
 
         #self.visible=False #XXX: self.visible is not unset in pyjamas when ENTER is pressed and a completion is done