From e8ef399b3aad32f794a5e0c9b121dd1b8c7807ef Mon Sep 17 00:00:00 2001
From: Bernie Innocenti <bernie@codewiz.org>
Date: Wed, 21 Apr 2010 23:32:25 -0400
Subject: [PATCH] sl#1948: Race condition with name widget in the activity toolbar
Organization: Sugar Labs Foundation
X-Subversion: sucks
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.
---
src/sugar/activity/activity.py | 17 ++++++-----------
1 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/src/sugar/activity/activity.py b/src/sugar/activity/activity.py
index c948bda..3e97485 100644
a
|
b
|
class ActivityToolbar(gtk.Toolbar): |
109 | 109 | self.title = gtk.Entry() |
110 | 110 | self.title.set_size_request(int(gtk.gdk.screen_width() / 3), -1) |
111 | 111 | self.title.set_text(activity.metadata['title']) |
112 | | self.title.connect('changed', self.__title_changed_cb) |
| 112 | self.title.connect('focus-out-event', self.__title_changed_cb) |
113 | 113 | self._add_widget(self.title) |
114 | 114 | |
115 | 115 | activity.metadata.connect('updated', self.__jobject_updated_cb) |
… |
… |
class ActivityToolbar(gtk.Toolbar): |
147 | 147 | self.insert(self.stop, -1) |
148 | 148 | self.stop.show() |
149 | 149 | |
150 | | self._update_title_sid = None |
151 | | |
152 | 150 | def _update_share(self): |
153 | 151 | self._updating_share = True |
154 | 152 | |
… |
… |
class ActivityToolbar(gtk.Toolbar): |
183 | 181 | def __jobject_updated_cb(self, jobject): |
184 | 182 | self.title.set_text(jobject['title']) |
185 | 183 | |
186 | | def __title_changed_cb(self, entry): |
187 | | if not self._update_title_sid: |
188 | | self._update_title_sid = gobject.timeout_add_seconds( |
189 | | 1, self.__update_title_cb) |
| 184 | def __title_changed_cb(self, editable, event): |
| 185 | title = editable.get_text() |
190 | 186 | |
191 | | def __update_title_cb(self): |
192 | | title = self.title.get_text() |
| 187 | # Title really changed? |
| 188 | if title == self._activity.metadata['title']: |
| 189 | return False |
193 | 190 | |
194 | 191 | self._activity.metadata['title'] = title |
195 | 192 | self._activity.metadata['title_set_by_user'] = '1' |
… |
… |
class ActivityToolbar(gtk.Toolbar): |
198 | 195 | shared_activity = self._activity.get_shared_activity() |
199 | 196 | if shared_activity: |
200 | 197 | shared_activity.props.name = title |
201 | | |
202 | | self._update_title_sid = None |
203 | 198 | return False |
204 | 199 | |
205 | 200 | def _add_widget(self, widget, expand=False): |