From e8ef399b3aad32f794a5e0c9b121dd1b8c7807ef Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Thu, 22 Apr 2010 03:32:25 +0000 Subject: sl#1948: Race condition with name widget in the activity toolbar The fix consists in hooking to the focus-out-event to trigger a save to the datastore. Previously, we were using the change event along with a timeout of one second, which was likely to trigger while the user was still updating the edit widget. --- diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py index c948bda..3e97485 100644 --- a/src/sugar/activity/activity.py +++ b/src/sugar/activity/activity.py @@ -109,7 +109,7 @@ class ActivityToolbar(gtk.Toolbar): self.title = gtk.Entry() self.title.set_size_request(int(gtk.gdk.screen_width() / 3), -1) self.title.set_text(activity.metadata['title']) - self.title.connect('changed', self.__title_changed_cb) + self.title.connect('focus-out-event', self.__title_changed_cb) self._add_widget(self.title) activity.metadata.connect('updated', self.__jobject_updated_cb) @@ -147,8 +147,6 @@ class ActivityToolbar(gtk.Toolbar): self.insert(self.stop, -1) self.stop.show() - self._update_title_sid = None - def _update_share(self): self._updating_share = True @@ -183,13 +181,12 @@ class ActivityToolbar(gtk.Toolbar): def __jobject_updated_cb(self, jobject): self.title.set_text(jobject['title']) - def __title_changed_cb(self, entry): - if not self._update_title_sid: - self._update_title_sid = gobject.timeout_add_seconds( - 1, self.__update_title_cb) + def __title_changed_cb(self, editable, event): + title = editable.get_text() - def __update_title_cb(self): - title = self.title.get_text() + # Title really changed? + if title == self._activity.metadata['title']: + return False self._activity.metadata['title'] = title self._activity.metadata['title_set_by_user'] = '1' @@ -198,8 +195,6 @@ class ActivityToolbar(gtk.Toolbar): shared_activity = self._activity.get_shared_activity() if shared_activity: shared_activity.props.name = title - - self._update_title_sid = None return False def _add_widget(self, widget, expand=False): -- cgit v0.9.1