Recognize images dropped into the clipboard as such.
This commit is contained in:
parent
71d718e97b
commit
d223579f22
@ -1,5 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
import urlparse
|
||||||
|
import posixpath
|
||||||
|
|
||||||
class FileType:
|
class FileType:
|
||||||
def __init__(self, formats):
|
def __init__(self, formats):
|
||||||
@ -200,15 +202,33 @@ class OOTextFileType(FileType):
|
|||||||
class UriListFileType(FileType):
|
class UriListFileType(FileType):
|
||||||
|
|
||||||
_types = set(['text/uri-list'])
|
_types = set(['text/uri-list'])
|
||||||
|
|
||||||
|
def _is_image(self):
|
||||||
|
uris = self._formats['text/uri-list'].get_data().split('\n')
|
||||||
|
if len(uris) == 1:
|
||||||
|
uri = urlparse.urlparse(uris[0])
|
||||||
|
ext = posixpath.splitext(uri.path)[1]
|
||||||
|
logging.debug(ext)
|
||||||
|
# FIXME: Bad hack, the type registry should treat text/uri-list as a special case.
|
||||||
|
if ext in ['.jpg', '.jpeg', '.gif', '.png', '.svg']:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return _('text/uri-list')
|
if self._is_image():
|
||||||
|
return _('Image')
|
||||||
|
else:
|
||||||
|
return _('File')
|
||||||
|
|
||||||
def get_icon(self):
|
def get_icon(self):
|
||||||
return 'theme:stock-missing'
|
if self._is_image():
|
||||||
|
return 'theme:object-image'
|
||||||
|
else:
|
||||||
|
return 'theme:stock-missing'
|
||||||
|
|
||||||
def get_preview(self):
|
def get_preview(self):
|
||||||
return 'preview'
|
return ''
|
||||||
|
|
||||||
def get_activity(self):
|
def get_activity(self):
|
||||||
return ''
|
return ''
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import urlparse
|
||||||
|
|
||||||
import hippo
|
import hippo
|
||||||
import gtk
|
import gtk
|
||||||
@ -79,15 +80,19 @@ class ClipboardBox(hippo.CanvasBox):
|
|||||||
|
|
||||||
cb_service = clipboardservice.get_instance()
|
cb_service = clipboardservice.get_instance()
|
||||||
if selection.type == 'text/uri-list':
|
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.')
|
||||||
|
uri = urlparse.urlparse(uris[0])
|
||||||
|
path, file_name = os.path.split(uri.path)
|
||||||
|
|
||||||
# Copy the file, as it will be deleted when the dnd operation finishes.
|
# Copy the file, as it will be deleted when the dnd operation finishes.
|
||||||
file_path = selection.data.replace('file://', '')
|
new_file_path = os.path.join(path, 'cb' + file_name)
|
||||||
new_file_path = os.path.join(os.path.split(file_path)[0],
|
shutil.copyfile(uri.path, new_file_path)
|
||||||
"cb" + os.path.split(file_path)[1])
|
|
||||||
shutil.copyfile(file_path, new_file_path)
|
|
||||||
|
|
||||||
cb_service.add_object_format(object_id,
|
cb_service.add_object_format(object_id,
|
||||||
selection.type,
|
selection.type,
|
||||||
'file://' + new_file_path,
|
uri.scheme + "://" + new_file_path,
|
||||||
on_disk=True)
|
on_disk=True)
|
||||||
else:
|
else:
|
||||||
cb_service.add_object_format(object_id,
|
cb_service.add_object_format(object_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user