Fix drag/drop bug: allow multiple drop on gallery

svn: r14515
This commit is contained in:
Benny Malengier 2010-02-28 14:02:45 +00:00
parent 24bf1c6434
commit 528ba93613
2 changed files with 30 additions and 25 deletions

View File

@ -456,29 +456,31 @@ class GalleryTab(ButtonTab, DbGUIElement):
elif self._DND_EXTRA and mytype == self._DND_EXTRA.drag_type:
self.handle_extra_type(mytype, obj)
except pickle.UnpicklingError:
d = Utils.fix_encoding(sel_data.data.replace('\0',' ').strip())
protocol, site, mfile, j, k, l = urlparse.urlparse(d)
if protocol == "file":
name = Utils.fix_encoding(mfile)
name = unicode(urllib.url2pathname(name.encode(sys.getfilesystemencoding())))
mime = gen.mime.get_type(name)
if not gen.mime.is_valid_type(mime):
return
photo = gen.lib.MediaObject()
photo.set_path(name)
photo.set_mime_type(mime)
basename = os.path.basename(name)
(root, ext) = os.path.splitext(basename)
photo.set_description(root)
trans = self.dbstate.db.transaction_begin()
self.dbstate.db.add_object(photo, trans)
oref = gen.lib.MediaRef()
oref.set_reference_handle(photo.get_handle())
self.get_data().append(oref)
self.changed = True
# self.dataobj.add_media_reference(oref)
self.dbstate.db.transaction_commit(trans,
_("Drag Media Object"))
#We assume this is for URI_LIST
for file in sel_data.get_uris():
d = Utils.fix_encoding(file.replace('\0',' ').strip())
protocol, site, mfile, j, k, l = urlparse.urlparse(d)
if protocol == "file":
name = Utils.fix_encoding(mfile)
name = unicode(urllib.url2pathname(
name.encode(sys.getfilesystemencoding())))
mime = gen.mime.get_type(name)
if not gen.mime.is_valid_type(mime):
return
photo = gen.lib.MediaObject()
photo.set_path(name)
photo.set_mime_type(mime)
basename = os.path.basename(name)
(root, ext) = os.path.splitext(basename)
photo.set_description(root)
trans = self.dbstate.db.transaction_begin()
self.dbstate.db.add_object(photo, trans)
oref = gen.lib.MediaRef()
oref.set_reference_handle(photo.get_handle())
self.get_data().append(oref)
self.changed = True
self.dbstate.db.transaction_commit(trans,
_("Drag Media Object"))
self.rebuild()
def handle_extra_type(self, objtype, obj):

View File

@ -148,11 +148,12 @@ class MediaView(ListView):
dnd_types = [ self._DND_TYPE.target() ]
self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types,
gtk.gdk.ACTION_COPY)
gtk.gdk.ACTION_PRIVATE)
self.list.drag_source_set(gtk.gdk.BUTTON1_MASK,
[self._DND_TYPE.target()],
gtk.gdk.ACTION_COPY)
self.list.connect('drag_data_get', self.drag_data_get)
#connected in listview already
#self.list.connect('drag_data_get', self.drag_data_get)
self.list.connect('drag_data_received', self.drag_data_received)
def drag_data_get(self, widget, context, sel_data, info, time):
@ -194,6 +195,8 @@ class MediaView(ListView):
If the selection data is define, extract the value from sel_data.data,
and decide if this is a move or a reorder.
The only data we accept on mediaview is dropping a file, so URI_LIST.
We assume this is what we obtain
"""
if sel_data and sel_data.data:
cleaned_string = sel_data.data.replace('\0', ' ')