# HG changeset patch # User Goffi # Date 1471892211 -7200 # Node ID f3940f6a322247dd78a91108678a6fa45bf2d78b # Parent 2e948c2286435242b79647a05aeab0c5d932adab quick frontend (widgets): a deletion with onDelete can now be cancelled if onDelete return False diff -r 2e948c228643 -r f3940f6a3222 frontends/src/quick_frontend/quick_widgets.py --- a/frontends/src/quick_frontend/quick_widgets.py Sun Aug 21 20:39:43 2016 +0200 +++ b/frontends/src/quick_frontend/quick_widgets.py Mon Aug 22 20:56:51 2016 +0200 @@ -253,9 +253,14 @@ def deleteWidget(self, widget_to_delete): """Delete a widget + this method must be called by frontends when a widget is deleted widget's onDelete method will be called before deletion """ - widget_to_delete.onDelete() + if widget_to_delete.onDelete() == False: + return + + if self.host.selected_widget == widget_to_delete: + self.host.selected_widget = None for widget_map in self._widgets.itervalues(): to_delete = set() @@ -335,8 +340,11 @@ return unicode(target) # by defaut, there is one hash for one target def onDelete(self): - """Called when a widget is deleted""" - log.debug(u"deleting widget {}".format(self)) # Must be implemented by frontends - if self.host.selected_widget == self: - self.host.selected_widget = None + """Called when a widget is being deleted + @return (boot, None): False to cancel deletion + all other value continue deletion + """ + log.debug(u"widget {} deleted".format(self)) + return True +