changeset 356:307c2501d8b2

chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one: Chat instances can be shown on any WHWrapper, even in all at the same time, so we keep as many instances as active wrapper to avoid unnecessary widget (re)creation
author Goffi <goffi@goffi.org>
date Fri, 17 Jan 2020 20:35:57 +0100
parents 8b6621cc142c
children 4d3a0c4f2430
files cagou/core/cagou_main.py cagou/plugins/plugin_wid_chat.py
diffstat 2 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/cagou_main.py	Fri Jan 17 20:33:43 2020 +0100
+++ b/cagou/core/cagou_main.py	Fri Jan 17 20:35:57 2020 +0100
@@ -925,8 +925,8 @@
     ## misc ##
 
     def plugging_profiles(self):
-        self._widgets_handler = widgets_handler.WidgetsHandler()
-        self.app.root.changeWidget(self._widgets_handler)
+        self.widgets_handler = widgets_handler.WidgetsHandler()
+        self.app.root.changeWidget(self.widgets_handler)
         self.bridge.menusGet("", C.NO_SECURITY_LIMIT, callback=self._menusGetCb)
 
     def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
--- a/cagou/plugins/plugin_wid_chat.py	Fri Jan 17 20:33:43 2020 +0100
+++ b/cagou/plugins/plugin_wid_chat.py	Fri Jan 17 20:35:57 2020 +0100
@@ -767,13 +767,13 @@
         if not self.sync:
             self.resync()
 
-    def onDelete(self):
+    def onDelete(self, **kwargs):
         # we always keep one widget, so it's available when swiping
         # TODO: delete all widgets when chat is closed
         nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self))
-        if nb_instances > 1:
-            return super(Chat, self).onDelete()
-        else:
+        # we want to keep at least one instance of Chat by WHWrapper
+        nb_to_keep = len(G.host.widgets_handler.children)
+        if nb_instances <= nb_to_keep:
             return False
 
     def _history_unlock(self, __):