#5097: Fix pasting text between activities through the clipboard.

This commit is contained in:
Tomeu Vizoso 2007-11-23 18:38:55 +01:00
parent 1cecee8da3
commit 972fecd920
4 changed files with 41 additions and 31 deletions

1
NEWS
View File

@ -1,3 +1,4 @@
* #5097: Fix pasting text between activities through the clipboard. (tomeu)
* #4660: Use improved PS API which streamlines ShareActivity process (smcv)
0.70.1

View File

@ -44,12 +44,14 @@ class ClipboardIcon(RadioToolButton):
self._preview = None
self._activity = None
self.owns_clipboard = False
self.props.sensitive = False
self.props.active = False
self._icon = Icon()
self._icon.props.xo_color = profile.get_color()
self.set_icon_widget(self._icon)
self._icon.show()
cb_service = clipboardservice.get_instance()
cb_service.connect('object-state-changed', self._object_state_changed_cb)
obj = cb_service.get_object(self._object_id)
@ -80,6 +82,10 @@ class ClipboardIcon(RadioToolButton):
def _put_in_clipboard(self):
logging.debug('ClipboardIcon._put_in_clipboard')
if self._percent < 100:
raise ValueError('Object is not complete, cannot be put into the clipboard.')
targets = self._get_targets()
if targets:
clipboard = gtk.Clipboard()
@ -125,14 +131,19 @@ class ClipboardIcon(RadioToolButton):
self.child.drag_source_set_icon_name(self._icon.props.icon_name)
self._name = name
self._percent = percent
self._preview = preview
self._activity = activity
self.palette.set_state(name, percent, preview, activity,
self._is_bundle(obj['FORMATS']))
if self.props.active:
self._put_in_clipboard()
old_percent = self._percent
self._percent = percent
if self._percent == 100:
self.props.sensitive = True
# Clipboard object became complete. Make it the active one.
if old_percent < 100 and self._percent == 100:
self.props.active = True
def _notify_active_cb(self, widget, pspec):
if self.props.active:

View File

@ -62,7 +62,6 @@ class ClipboardBox(hippo.CanvasBox):
hippo.CanvasBox.__init__(self)
self._icons = {}
self._context_map = _ContextMap()
self._selected_icon = None
self._tray = VTray()
self.append(hippo.CanvasWidget(widget=self._tray), hippo.PACK_EXPAND)
@ -109,17 +108,10 @@ class ClipboardBox(hippo.CanvasBox):
icon = ClipboardIcon(object_id, name, group)
self._tray.add_item(icon, 0)
icon.show()
self._set_icon_selected(icon)
self._icons[object_id] = icon
logging.debug('ClipboardBox: ' + object_id + ' was added.')
def _set_icon_selected(self, icon):
logging.debug('_set_icon_selected')
icon.props.active = True
self._selected_icon = icon
def _object_deleted_cb(self, cb_service, object_id):
icon = self._icons[object_id]
self._tray.remove_item(icon)

View File

@ -59,29 +59,35 @@ class ClipboardPanelWindow(FrameWindow):
targets = clipboard.wait_for_targets()
for target in targets:
if target not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE', 'SAVE_TARGETS'):
logging.debug('Asking for target %s.' % target)
selection = clipboard.wait_for_contents(target)
if selection:
self._add_selection(key, selection)
if not selection:
logging.warning('no data for selection target %s.' % target)
continue
self._add_selection(key, selection)
cb_service.set_object_percent(key, percent=100)
def _add_selection(self, key, selection):
if selection.data:
logging.debug('adding type ' + selection.type + '.')
cb_service = clipboardservice.get_instance()
if selection.type == 'text/uri-list':
uris = selection.data.split('\n')
if len(uris) > 1:
raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
if not selection.data:
logging.warning('no data for selection target %s.' % selection.type)
return
logging.debug('adding type ' + selection.type + '.')
cb_service = clipboardservice.get_instance()
if selection.type == 'text/uri-list':
uris = selection.data.split('\n')
if len(uris) > 1:
raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
cb_service.add_object_format(key,
selection.type,
uris[0],
on_disk=True)
else:
cb_service.add_object_format(key,
selection.type,
selection.data,
on_disk=False)
cb_service.add_object_format(key,
selection.type,
uris[0],
on_disk=True)
else:
cb_service.add_object_format(key,
selection.type,
selection.data,
on_disk=False)