Use 'focus-out' event instead of 'changed' event for title entry OLPC #10956, SL #2608

To determine if the title has changed we use the 'focus-out'
event now instead of the 'changed' signal of the gtk.Entry. This
removes races we had before.

Signed-off-by: Daniel Drake <dsd@laptop.org>
Acked-By: Simon Schampijer <simon@laptop.org>
Acked-By: Sascha Silbe <silbe@activitycentral.com>
This commit is contained in:
Simon Schampijer 2011-06-20 17:48:51 +02:00
parent 1ea1b2a0ab
commit 7a0d5d9398
2 changed files with 21 additions and 12 deletions

View File

@ -223,6 +223,9 @@ class Activity(Window, gtk.Container):
__gsignals__ = { __gsignals__ = {
'shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'shared': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])), 'joined': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
# For internal use only, use can_close() if you want to perform extra
# checks before actually closing
'_closing': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
} }
def __init__(self, handle, create_jobject=True): def __init__(self, handle, create_jobject=True):
@ -863,6 +866,8 @@ class Activity(Window, gtk.Container):
if not self.can_close(): if not self.can_close():
return return
self.emit('_closing')
if skip_save or self._jobject is None or \ if skip_save or self._jobject is None or \
self.metadata.get('title_set_by_user', '0') == '1': self.metadata.get('title_set_by_user', '0') == '1':
if not self._closing: if not self._closing:

View File

@ -16,7 +16,6 @@
# Boston, MA 02111-1307, USA. # Boston, MA 02111-1307, USA.
import gtk import gtk
import gobject
import gettext import gettext
import gconf import gconf
@ -186,32 +185,40 @@ class TitleEntry(gtk.ToolItem):
def __init__(self, activity, **kwargs): def __init__(self, activity, **kwargs):
gtk.ToolItem.__init__(self) gtk.ToolItem.__init__(self)
self.set_expand(False) self.set_expand(False)
self._update_title_sid = None
self.entry = gtk.Entry(**kwargs) self.entry = gtk.Entry(**kwargs)
self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1) self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1)
self.entry.set_text(activity.metadata['title']) self.entry.set_text(activity.metadata['title'])
self.entry.connect('changed', self.__title_changed_cb, activity) self.entry.connect('focus-out-event', self.__title_changed_cb, activity)
self.entry.show() self.entry.show()
self.add(self.entry) self.add(self.entry)
activity.metadata.connect('updated', self.__jobject_updated_cb) activity.metadata.connect('updated', self.__jobject_updated_cb)
activity.connect('_closing', self.__closing_cb)
def modify_bg(self, state, color): def modify_bg(self, state, color):
gtk.ToolItem.modify_bg(self, state, color) gtk.ToolItem.modify_bg(self, state, color)
self.entry.modify_bg(state, color) self.entry.modify_bg(state, color)
def __jobject_updated_cb(self, jobject): def __jobject_updated_cb(self, jobject):
if self.entry.flags() & gtk.HAS_FOCUS:
return
if self.entry.get_text() == jobject['title']:
return
self.entry.set_text(jobject['title']) self.entry.set_text(jobject['title'])
def __title_changed_cb(self, entry, activity): def __closing_cb(self, activity):
if self._update_title_sid is not None: self.save_title(activity)
gobject.source_remove(self._update_title_sid) return False
self._update_title_sid = gobject.timeout_add_seconds(
1, self.__update_title_cb, activity)
def __update_title_cb(self, activity): def __title_changed_cb(self, editable, event, activity):
self.save_title(activity)
return False
def save_title(self, activity):
title = self.entry.get_text() title = self.entry.get_text()
if title == activity.metadata['title']:
return
activity.metadata['title'] = title activity.metadata['title'] = title
activity.metadata['title_set_by_user'] = '1' activity.metadata['title_set_by_user'] = '1'
@ -221,9 +228,6 @@ class TitleEntry(gtk.ToolItem):
if shared_activity is not None: if shared_activity is not None:
shared_activity.props.name = title shared_activity.props.name = title
self._update_title_sid = None
return False
class ActivityToolbar(gtk.Toolbar): class ActivityToolbar(gtk.Toolbar):
"""The Activity toolbar with the Journal entry title, sharing, """The Activity toolbar with the Journal entry title, sharing,