[Sugar-devel] [PATCH] Only add one time every object in the clipboard v2 - SL #3371

godiard at sugarlabs.org godiard at sugarlabs.org
Thu Apr 19 10:17:22 EDT 2012


From: Gonzalo Odiard <godiard at gmail.com>

This patch change the behaviour of the clipboard tray,
every object is added only one time, if already exist,
the already added object is selected.
Is needed because a bad interaction between the clipboard in write and
the text to speech feature. See the ticket for more information.

v2: Select the already added object if needed, as sugested by Sasha.

Signed-off-by: Gonzalo Odiard <gonzalo at laptop.org>
---
 src/jarabe/frame/clipboard.py            |   17 +++++++++++++----
 src/jarabe/frame/clipboardpanelwindow.py |    5 ++++-
 src/jarabe/frame/clipboardtray.py        |    6 ++++++
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/jarabe/frame/clipboard.py b/src/jarabe/frame/clipboard.py
index be2b902..ae1ceb9 100644
--- a/src/jarabe/frame/clipboard.py
+++ b/src/jarabe/frame/clipboard.py
@@ -36,7 +36,9 @@ class Clipboard(gobject.GObject):
         'object-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                         ([object])),
         'object-deleted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                        ([int])),
+                        ([long])),
+        'object-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+                        ([long])),
         'object-state-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                         ([object])),
     }
@@ -51,9 +53,16 @@ class Clipboard(gobject.GObject):
         self._next_id += 1
         return self._next_id
 
-    def add_object(self, name):
-        logging.debug('Clipboard.add_object')
-        object_id = self._get_next_object_id()
+    def add_object(self, name, data_hash=None):
+        logging.debug('Clipboard.add_object hash %s', data_hash)
+        if data_hash is None:
+            object_id = self._get_next_object_id()
+        else:
+            object_id = data_hash
+        if object_id in self._objects:
+            logging.debug('Object rejected, already exist')
+            self.emit('object-selected', object_id)
+            return None
         self._objects[object_id] = ClipboardObject(object_id, name)
         self.emit('object-added', self._objects[object_id])
         return object_id
diff --git a/src/jarabe/frame/clipboardpanelwindow.py b/src/jarabe/frame/clipboardpanelwindow.py
index b73572e..28c5726 100644
--- a/src/jarabe/frame/clipboardpanelwindow.py
+++ b/src/jarabe/frame/clipboardpanelwindow.py
@@ -70,7 +70,10 @@ class ClipboardPanelWindow(FrameWindow):
                 cb_selections.append(selection)
 
         if len(cb_selections) > 0:
-            key = cb_service.add_object(name="")
+            key = cb_service.add_object(name="",
+                    data_hash=hash(selection.data))
+            if key is None:
+                return
             cb_service.set_object_percent(key, percent=0)
             for selection in cb_selections:
                 self._add_selection(key, selection)
diff --git a/src/jarabe/frame/clipboardtray.py b/src/jarabe/frame/clipboardtray.py
index f49b799..e78ef4a 100644
--- a/src/jarabe/frame/clipboardtray.py
+++ b/src/jarabe/frame/clipboardtray.py
@@ -70,6 +70,7 @@ class ClipboardTray(tray.VTray):
         cb_service = clipboard.get_instance()
         cb_service.connect('object-added', self._object_added_cb)
         cb_service.connect('object-deleted', self._object_deleted_cb)
+        cb_service.connect('object-selected', self._object_selected_cb)
 
     def owns_clipboard(self):
         for icon in self._icons.values():
@@ -125,6 +126,11 @@ class ClipboardTray(tray.VTray):
         del self._icons[object_id]
         logging.debug('ClipboardTray: %r was deleted', object_id)
 
+    def _object_selected_cb(self, cb_service, object_id):
+        icon = self._icons[object_id]
+        icon.props.active = True
+        logging.debug('ClipboardTray: %r was activated', object_id)
+
     def drag_motion_cb(self, widget, context, x, y, time):
         logging.debug('ClipboardTray._drag_motion_cb')
 
-- 
1.7.7.6



More information about the Sugar-devel mailing list