4788: Fix drag-and-drop of files onto the media view

svn: r17084
This commit is contained in:
Nick Hall 2011-04-09 14:08:29 +00:00
parent 8dd6ff1585
commit 4518d3ca02
2 changed files with 23 additions and 21 deletions

View File

@ -153,9 +153,17 @@ class ListView(NavigationView):
else: else:
# Tree # Tree
self.list.connect('key-press-event', self._key_press_tree) self.list.connect('key-press-event', self._key_press_tree)
if self.drag_info(): if self.drag_info():
self.list.connect('drag_data_get', self.drag_data_get) self.list.connect('drag_data_get', self.drag_data_get)
self.list.connect('drag_begin', self.drag_begin) self.list.connect('drag_begin', self.drag_begin)
if self.drag_dest_info():
self.list.connect('drag_data_received', self.drag_data_received)
self.list.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
gtk.DEST_DEFAULT_DROP,
[self.drag_dest_info().target()],
gtk.gdk.ACTION_MOVE |
gtk.gdk.ACTION_COPY)
scrollwindow = gtk.ScrolledWindow() scrollwindow = gtk.ScrolledWindow()
scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrollwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
@ -409,6 +417,9 @@ class ListView(NavigationView):
#################################################################### ####################################################################
def drag_info(self): def drag_info(self):
"""
Specify the drag type for a single selected row
"""
return None return None
def drag_list_info(self): def drag_list_info(self):
@ -417,6 +428,12 @@ class ListView(NavigationView):
""" """
return DdTargets.LINK_LIST return DdTargets.LINK_LIST
def drag_dest_info(self):
"""
Specify the drag type for objects dropped on the view
"""
return None
def drag_begin(self, widget, context): def drag_begin(self, widget, context):
widget.drag_source_set_icon_stock(self.get_stock()) widget.drag_source_set_icon_stock(self.get_stock())
return True return True

View File

@ -113,8 +113,6 @@ class MediaView(ListView):
FILTER_TYPE = 'MediaObject' FILTER_TYPE = 'MediaObject'
QR_CATEGORY = CATEGORY_QR_MEDIA QR_CATEGORY = CATEGORY_QR_MEDIA
_DND_TYPE = DdTargets.URI_LIST
def __init__(self, pdata, dbstate, uistate, nav_group=0): def __init__(self, pdata, dbstate, uistate, nav_group=0):
signal_map = { signal_map = {
@ -144,25 +142,6 @@ class MediaView(ListView):
def navigation_type(self): def navigation_type(self):
return 'Media' return 'Media'
def _set_dnd(self):
"""
Set up drag-n-drop. The source and destination are set by calling .target()
on the _DND_TYPE. Obviously, this means that there must be a _DND_TYPE
variable defined that points to an entry in DdTargets.
"""
dnd_types = [ self._DND_TYPE.target() ]
self.list.drag_dest_set(gtk.DEST_DEFAULT_MOTION|gtk.DEST_DEFAULT_DROP,
dnd_types,
gtk.gdk.ACTION_MOVE|gtk.gdk.ACTION_COPY)
self.list.drag_source_set(gtk.gdk.BUTTON1_MASK,
[self._DND_TYPE.target()],
gtk.gdk.ACTION_COPY)
#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_info(self): def drag_info(self):
""" """
Return the type of DND targets that this view will accept. For Media Return the type of DND targets that this view will accept. For Media
@ -170,6 +149,12 @@ class MediaView(ListView):
""" """
return DdTargets.MEDIAOBJ return DdTargets.MEDIAOBJ
def drag_dest_info(self):
"""
Specify the drag type for objects dropped on the view
"""
return DdTargets.URI_LIST
def find_index(self, obj): def find_index(self, obj):
""" """
returns the index of the object within the associated data returns the index of the object within the associated data