This is a set of patches I worked on recently, and need to rebase on
the latest jhbuild before I post them officially.  I wanted to expose
them for comments before I put in that effort, since there are no
doubt other things that will need to be changed upon review.

Thanks!

- Eben

PS.  I just noticed upon attaching that the first isn't actually a
clipboard patch, but it was part of a sprint on clipboard and
drag'n'drop in general, so I include it.
From 08d4c23ff0cd0e48842c189711ef1dd7d3a05c05 Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED](none)>
Date: Mon, 22 Sep 2008 11:36:22 -0400
Subject: [PATCH] Lock cursor to center of icons in favorites view on drag (#7408)

---
 src/view/home/favoritesview.py |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/view/home/favoritesview.py b/src/view/home/favoritesview.py
index 0a7f0b3..7449b4c 100644
--- a/src/view/home/favoritesview.py
+++ b/src/view/home/favoritesview.py
@@ -75,6 +75,8 @@ class FavoritesView(hippo.Canvas):
         self._pressed_button = None
         self._press_start_x = None
         self._press_start_y = None
+        self._hot_x = None
+        self._hot_y = None
         self._last_clicked_icon = None
 
         self._box = hippo.CanvasBox()
@@ -221,8 +223,9 @@ class FavoritesView(hippo.Canvas):
         # TODO: we should get the pixbuf from the widget, so it has colors, etc
         pixbuf = gtk.gdk.pixbuf_new_from_file(icon_file_name)
         
-        hot_spot = style.zoom(10)
-        context.set_icon_pixbuf(pixbuf, hot_spot, hot_spot)
+        self._hot_x = pixbuf.props.width / 2
+        self._hot_y = pixbuf.props.height / 2
+        context.set_icon_pixbuf(pixbuf, self._hot_x, self._hot_y)
 
     def __drag_motion_cb(self, widget, context, x, y, time):
         if self._last_clicked_icon is not None:
@@ -235,11 +238,14 @@ class FavoritesView(hippo.Canvas):
         if self._last_clicked_icon is not None:
             self.drag_get_data(context, _ICON_DND_TARGET[0])
 
-            self._layout.move_icon(self._last_clicked_icon, x, y)
+            self._layout.move_icon(self._last_clicked_icon,
+                                   x - self._hot_x, y - self._hot_y)
 
             self._pressed_button = None
             self._press_start_x = None
             self._press_start_y = None
+            self._hot_x = None
+            self._hot_y = None
             self._last_clicked_icon = None
 
             return True
-- 
1.5.4.3

From 3f25f0e4701ea485621af7e663388a9c4d16483d Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED](none)>
Date: Mon, 22 Sep 2008 11:56:56 -0400
Subject: [PATCH] Title clippings appropriately eg. "Text clipping" (#5751)

---
 src/model/clipboardobject.py |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/model/clipboardobject.py b/src/model/clipboardobject.py
index a4cd388..2f494d0 100644
--- a/src/model/clipboardobject.py
+++ b/src/model/clipboardobject.py
@@ -18,6 +18,7 @@ import os
 import logging
 import urlparse
 
+from gettext import gettext as _
 from sugar import mime
 from sugar.bundle.activitybundle import ActivityBundle
 
@@ -39,9 +40,12 @@ class ClipboardObject(object):
     def get_name(self):
         name = self._name
         if not name:
-            name = mime.get_mime_description(self.get_mime_type())
-        if not name:
-            name = ''
+            type = mime.get_mime_description(self.get_mime_type())
+
+            if not type:
+                type = 'Data'
+            name = _('%s clipping') % type
+
         return name
 
     def get_icon(self):
-- 
1.5.4.3

From 1fea17a5fd980048d74f90dd83dd5591c11fcc32 Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED](none)>
Date: Mon, 22 Sep 2008 12:17:30 -0400
Subject: [PATCH] Add descriptions to clippings (#5751)

This patch adds support for descriptions for text clippings,
showing a preview of the clipped string in the primary palette.
In the future we'll want to add meaningful descriptions for
clippings of other types, perhaps by noting what activity they
were clipped from to provide some context.
---
 src/model/clipboardobject.py |   27 +++++++++++++++++++++++++++
 src/view/clipboardmenu.py    |    7 ++++++-
 2 files changed, 33 insertions(+), 1 deletions(-)

diff --git a/src/model/clipboardobject.py b/src/model/clipboardobject.py
index 2f494d0..5ecec38 100644
--- a/src/model/clipboardobject.py
+++ b/src/model/clipboardobject.py
@@ -22,6 +22,8 @@ from gettext import gettext as _
 from sugar import mime
 from sugar.bundle.activitybundle import ActivityBundle
 
+_MAX_DESCRIPTION_LENGTH = 50
+
 class ClipboardObject(object):
 
     def __init__(self, object_path, name):
@@ -48,6 +50,31 @@ class ClipboardObject(object):
 
         return name
 
+    # TODO: This only handles text clippings.  We should provide info about
+    # where a clipping came from for other formats, eg. "Clipped from TamTam"
+    def get_description(self):
+        desc = None
+        for key in self._formats:
+            if key == 'STRING':
+                format = self._formats[key]
+
+                # Strip whitespace
+                data = format.get_data().strip('\n\r\t \x00')
+
+                # Trim to a short, single line snippet
+                cutoff = data.find('\n')
+                if cutoff > 0:
+                    cutoff = min(cutoff, _MAX_DESCRIPTION_LENGTH)
+                else:
+                    cutoff = _MAX_DESCRIPTION_LENGTH
+
+                if len(data) > cutoff:
+                    desc = '\"%s..."' % data[0:cutoff]
+                else:
+                    desc = '"%s"' % data
+
+        return desc
+
     def get_icon(self):
         return mime.get_mime_icon(self.get_mime_type())
 
diff --git a/src/view/clipboardmenu.py b/src/view/clipboardmenu.py
index f71e8cf..8b613d8 100644
--- a/src/view/clipboardmenu.py
+++ b/src/view/clipboardmenu.py
@@ -36,7 +36,8 @@ import journal.misc
 class ClipboardMenu(Palette):
 
     def __init__(self, cb_object):
-        Palette.__init__(self, cb_object.get_name())
+        Palette.__init__(self, primary_text=cb_object.get_name(),
+                         secondary_text=cb_object.get_description())
 
         self._cb_object = cb_object
 
@@ -123,6 +124,9 @@ class ClipboardMenu(Palette):
 
         self._update_progress_bar()
 
+    def _update_description(self):
+        self.props.secondary_text = self._cb_object.get_description()
+
     def _get_activities(self):
         mime_type = self._cb_object.get_mime_type()
         if not mime_type:
@@ -157,6 +161,7 @@ class ClipboardMenu(Palette):
         self._update_progress_bar()
         self._update_items_visibility()
         self._update_open_submenu()
+        self._update_description()
 
     def _open_item_activate_cb(self, menu_item):
         logging.debug('_open_item_activate_cb')
-- 
1.5.4.3

From 93a78763892ea376ef436838abbdb501122ca1c3 Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED](none)>
Date: Mon, 22 Sep 2008 12:24:51 -0400
Subject: [PATCH] Highlight clipboard on drag (#8604)

---
 src/view/frame/clipboardpanelwindow.py |    1 +
 src/view/frame/clipboardtray.py        |    4 ++++
 2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/src/view/frame/clipboardpanelwindow.py b/src/view/frame/clipboardpanelwindow.py
index 08794b8..80b8ce4 100644
--- a/src/view/frame/clipboardpanelwindow.py
+++ b/src/view/frame/clipboardpanelwindow.py
@@ -44,6 +44,7 @@ class ClipboardPanelWindow(FrameWindow):
         # Receiving dnd drops
         self.drag_dest_set(0, [], 0)
         self.connect("drag_motion", self._clipboard_tray.drag_motion_cb)
+        self.connect("drag_leave", self._clipboard_tray.drag_leave_cb)
         self.connect("drag_drop", self._clipboard_tray.drag_drop_cb)
         self.connect("drag_data_received",
                      self._clipboard_tray.drag_data_received_cb)
diff --git a/src/view/frame/clipboardtray.py b/src/view/frame/clipboardtray.py
index 8c3939f..4fc5ed6 100644
--- a/src/view/frame/clipboardtray.py
+++ b/src/view/frame/clipboardtray.py
@@ -126,8 +126,12 @@ class ClipboardTray(tray.VTray):
     def drag_motion_cb(self, widget, context, x, y, time):
         logging.debug('ClipboardTray._drag_motion_cb')
         context.drag_status(gtk.gdk.ACTION_COPY, time)
+        self.props.drag_active = True
         return True
 
+    def drag_leave_cb(self, widget, context, time):
+         self.props.drag_active = False
+
     def drag_drop_cb(self, widget, context, x, y, time):
         logging.debug('ClipboardTray._drag_drop_cb')
         cb_service = clipboard.get_instance()
-- 
1.5.4.3

From aa9bf17c8fdfd3a5de830f03697cc7f1b65e2197 Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED](none)>
Date: Mon, 22 Sep 2008 12:44:28 -0400
Subject: [PATCH] Prevent duplicate clippings on drag within clipboard (#8606)

---
 src/view/frame/clipboardtray.py |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/view/frame/clipboardtray.py b/src/view/frame/clipboardtray.py
index 4fc5ed6..f916e4a 100644
--- a/src/view/frame/clipboardtray.py
+++ b/src/view/frame/clipboardtray.py
@@ -125,8 +125,13 @@ class ClipboardTray(tray.VTray):
 
     def drag_motion_cb(self, widget, context, x, y, time):
         logging.debug('ClipboardTray._drag_motion_cb')
-        context.drag_status(gtk.gdk.ACTION_COPY, time)
-        self.props.drag_active = True
+
+        if self._internal_drag(context):
+            context.drag_status(gtk.gdk.ACTION_MOVE, time)
+        else:
+            context.drag_status(gtk.gdk.ACTION_COPY, time)
+            self.props.drag_active = True
+
         return True
 
     def drag_leave_cb(self, widget, context, time):
@@ -134,6 +139,13 @@ class ClipboardTray(tray.VTray):
 
     def drag_drop_cb(self, widget, context, x, y, time):
         logging.debug('ClipboardTray._drag_drop_cb')
+
+        if self._internal_drag(context):
+            # TODO: We should move the object within the clipboard here
+            if not self._context_map.has_context(context):
+                context.drop_finish(False, gtk.get_current_event_time())
+            return False
+
         cb_service = clipboard.get_instance()
         object_id = cb_service.add_object(name="")
 
@@ -195,3 +207,10 @@ class ClipboardTray(tray.VTray):
             if not self._context_map.has_context(context):
                 context.drop_finish(True, gtk.get_current_event_time())
 
+    def _internal_drag(self, context):
+        view_ancestor = context.get_source_widget().get_ancestor(gtk.Viewport)
+        if view_ancestor is self._viewport:
+            return True
+        else:
+            return False
+
-- 
1.5.4.3

diff --git a/cursor/sugar/sugar.cursortheme b/cursor/sugar/sugar.cursortheme
index 0480165..3859ae0 100644
--- a/cursor/sugar/sugar.cursortheme
+++ b/cursor/sugar/sugar.cursortheme
@@ -111,11 +111,17 @@
 	<alias name="dnd_none" target="forbidden"/>
 	<alias name="unavailable" target="forbidden"/>
 	
-	<alias name="dnd_none" target="forbidden"/>
 	<alias name="dnd_copy" target="plus"/>
-	<alias name="dnd_move" target="plus"/>
+	<alias name="dnd_move" target="left_ptr"/>
 	<alias name="dnd_ask" target="question_arrow"/>
-	<alias name="dnd_none" target="left_ptr_modify"/>
+	<alias name="dnd_link" target="left_ptr"/>
+	<alias name="dnd_none" target="left_ptr"/>
+
+	<alias name="dnd-copy" target="plus"/>
+	<alias name="dnd-move" target="left_ptr"/>
+	<alias name="dnd-ask" target="question_arrow"/>
+	<alias name="dnd-link" target="left_ptr"/>
+	<alias name="dnd-none" target="left_ptr"/>
 	
 	<alias name="copy" target="plus"/>
 	<alias name="add" target="plus"/>
_______________________________________________
Sugar mailing list
Sugar@lists.laptop.org
http://lists.laptop.org/listinfo/sugar

Reply via email to