changeset 445:9b73a1879989

core: fixed doAction when new widget is already existing and visible: when the doAction new widget was existing and visible, the factory was creating a new one, which could result in a consusing situation for the user (share widget's attachment added to an non visible widget for instance).
author Goffi <goffi@goffi.org>
date Wed, 18 Mar 2020 20:26:21 +0100
parents e578df3304d8
children ffdf2390ea56
files cagou/core/cagou_main.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/cagou_main.py	Sat Mar 07 00:05:50 2020 +0100
+++ b/cagou/core/cagou_main.py	Wed Mar 18 20:26:21 2020 +0100
@@ -813,6 +813,9 @@
 
         # selected_widget can be modified in changeWidget, so we need to set it before
         self.selected_widget = new
+        if to_change == new:
+            log.debug("switchWidget called with old==new, nothing to do")
+            return new
         to_change.whwrapper.changeWidget(new)
         return new
 
@@ -945,10 +948,18 @@
         except IndexError:
             log.warning("No plugin widget found to do {action}".format(action=action))
         else:
-            factory = plg_infos['factory']
-            return self.switchWidget(
-                None,
-                factory(plg_infos, target=target, profiles=profiles))
+            try:
+                # does the widget already exist?
+                wid = next(self.widgets.getWidgets(
+                    plg_infos['main'],
+                    target=target,
+                    profiles=profiles))
+            except StopIteration:
+                # no, let's create a new one
+                factory = plg_infos['factory']
+                wid = factory(plg_infos, target=target, profiles=profiles)
+
+            return self.switchWidget(None, wid)
 
     ## bridge handlers ##