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

View File

@ -148,11 +148,12 @@ class MediaView(ListView):
dnd_types = [ self._DND_TYPE.target() ] dnd_types = [ self._DND_TYPE.target() ]
self.list.drag_dest_set(gtk.DEST_DEFAULT_ALL, dnd_types, 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.list.drag_source_set(gtk.gdk.BUTTON1_MASK,
[self._DND_TYPE.target()], [self._DND_TYPE.target()],
gtk.gdk.ACTION_COPY) 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) self.list.connect('drag_data_received', self.drag_data_received)
def drag_data_get(self, widget, context, sel_data, info, time): 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, If the selection data is define, extract the value from sel_data.data,
and decide if this is a move or a reorder. 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: if sel_data and sel_data.data:
cleaned_string = sel_data.data.replace('\0', ' ') cleaned_string = sel_data.data.replace('\0', ' ')