[Sugar-devel] Activity title update

James Cameron quozl at laptop.org
Tue Jul 6 05:52:54 EDT 2010


On Tue, Jul 06, 2010 at 07:30:52PM +1000, James Cameron wrote:
> [...] and as far as I can tell a metadata update could be deferred
> until changed plus a delta time, or focus-out, whichever occurs first.

This is what I mean: untested.  I also think the metadata update should
be avoided if there is no change to the value, which occurs if (a)
changes are made and then reverted before timeout, or (b) focus out.  I
don't know that the way I've done it below will work.

diff --git a/src/sugar/activity/widgets.py b/src/sugar/activity/widgets.py
index 5b712f2..f2f4693 100644
--- a/src/sugar/activity/widgets.py
+++ b/src/sugar/activity/widgets.py
@@ -190,6 +190,7 @@ class TitleEntry(gtk.ToolItem):
         self.entry = gtk.Entry(**kwargs)
         self.entry.set_size_request(int(gtk.gdk.screen_width() / 3), -1)
         self.entry.set_text(activity.metadata['title'])
+        self.entry.connect('focus-out-event', self.__title_focus_out_cb, activity)
         self.entry.connect('changed', self.__title_changed_cb, activity)
         self.entry.show()
         self.add(self.entry)
@@ -203,6 +204,11 @@ class TitleEntry(gtk.ToolItem):
     def __jobject_updated_cb(self, jobject):
         self.entry.set_text(jobject['title'])
 
+    def __title_focus_out_cb(self, entry, event, activity):
+        if self._update_title_sid is not None:
+            gobject.source_remove(self._update_title_sid)
+        self.__update_title_cb(activity)
+
     def __title_changed_cb(self, entry, activity):
         if self._update_title_sid is not None:
             gobject.source_remove(self._update_title_sid)
@@ -212,9 +218,10 @@ class TitleEntry(gtk.ToolItem):
     def __update_title_cb(self, activity):
         title = self.entry.get_text()
 
-        activity.metadata['title'] = title
-        activity.metadata['title_set_by_user'] = '1'
-        activity.save()
+        if activity.metadata['title'] != title:
+            activity.metadata['title'] = title
+            activity.metadata['title_set_by_user'] = '1'
+            activity.save()
 
         shared_activity = activity.get_shared_activity()
         if shared_activity is not None:
-- 
James Cameron
http://quozl.linux.org.au/


More information about the Sugar-devel mailing list