Mercurial > libervia-desktop-kivy
comparison cagou/core/cagou_main.py @ 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 | 12d188cb1206 |
children | 3c9ba4a694ef |
comparison
equal
deleted
inserted
replaced
444:e578df3304d8 | 445:9b73a1879989 |
---|---|
811 raise exceptions.InternalError("no CagouWidget found when " | 811 raise exceptions.InternalError("no CagouWidget found when " |
812 "trying to switch widget") | 812 "trying to switch widget") |
813 | 813 |
814 # selected_widget can be modified in changeWidget, so we need to set it before | 814 # selected_widget can be modified in changeWidget, so we need to set it before |
815 self.selected_widget = new | 815 self.selected_widget = new |
816 if to_change == new: | |
817 log.debug("switchWidget called with old==new, nothing to do") | |
818 return new | |
816 to_change.whwrapper.changeWidget(new) | 819 to_change.whwrapper.changeWidget(new) |
817 return new | 820 return new |
818 | 821 |
819 def _addVisibleWidget(self, widget): | 822 def _addVisibleWidget(self, widget): |
820 """declare a widget visible | 823 """declare a widget visible |
943 plg_infos = [p for p in self.getPluggedWidgets() | 946 plg_infos = [p for p in self.getPluggedWidgets() |
944 if action in p['import_name']][0] | 947 if action in p['import_name']][0] |
945 except IndexError: | 948 except IndexError: |
946 log.warning("No plugin widget found to do {action}".format(action=action)) | 949 log.warning("No plugin widget found to do {action}".format(action=action)) |
947 else: | 950 else: |
948 factory = plg_infos['factory'] | 951 try: |
949 return self.switchWidget( | 952 # does the widget already exist? |
950 None, | 953 wid = next(self.widgets.getWidgets( |
951 factory(plg_infos, target=target, profiles=profiles)) | 954 plg_infos['main'], |
955 target=target, | |
956 profiles=profiles)) | |
957 except StopIteration: | |
958 # no, let's create a new one | |
959 factory = plg_infos['factory'] | |
960 wid = factory(plg_infos, target=target, profiles=profiles) | |
961 | |
962 return self.switchWidget(None, wid) | |
952 | 963 |
953 ## bridge handlers ## | 964 ## bridge handlers ## |
954 | 965 |
955 def otrStateHandler(self, state, dest_jid, profile): | 966 def otrStateHandler(self, state, dest_jid, profile): |
956 """OTR state has changed for on destinee""" | 967 """OTR state has changed for on destinee""" |