Skip to content

Commit

Permalink
ensure only valid sources that are droppable show the drop icon. Also…
Browse files Browse the repository at this point in the history
… switch to source if we hover over a source for a couple of seconds - issue #49
  • Loading branch information
fossfreedom committed May 26, 2015
1 parent d543c60 commit 7092a6c
Showing 1 changed file with 56 additions and 21 deletions.
77 changes: 56 additions & 21 deletions alttoolbar_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def __init__(self, toolbar, rbtree):
self.plugin = toolbar.plugin
self.rbtree = rbtree

self._drag_dest_source = None
self._drag_motion_counter = -1

# locale stuff
cl = CoverLocale()
cl.switch_locale(cl.Locale.LOCALE_DOMAIN)
Expand Down Expand Up @@ -155,6 +158,7 @@ def _connect_signals(self):
self.connect('drag-drop', self.on_drag_drop)
self.connect('drag-data-received',
self.on_drag_data_received)
self.connect('drag-motion', self.on_drag_motion)

def cleanup(self):
model = self.shell.props.display_page_model
Expand All @@ -174,19 +178,11 @@ def on_drag_drop(self, widget, context, x, y, time):
target = self.drag_dest_find_target(context, None)
widget.drag_get_data(context, target, time)

return True
self._drag_dest_source = None

def on_drag_data_received(self, widget, drag_context, x, y, data, info,
time):
'''
Callback called when the drag source has prepared the data (pixbuf)
for us to use.
'''
print ("on_drag_data_received")
# stop the propagation of the signal (deactivates superclass callback)
widget.stop_emission_by_name('drag-data-received')
return True

# get the album and the info and ask the loader to update the cover
def on_drag_motion(self, widget, drag_context, x, y, time):
path = False

try:
Expand All @@ -203,22 +199,61 @@ def on_drag_data_received(self, widget, drag_context, x, y, data, info,
elif dest_source.can_paste():
result = True

if result:
# can drop here
drag_context.finish(True, False, time)
if dest_source and result:
if dest_source != self._drag_dest_source:
if self._drag_motion_counter != -1:
self._drag_motion_counter = 0
self._drag_dest_source = dest_source

dest_query_model = dest_source.props.query_model
def delayed(*args):
if self._drag_motion_counter < 2 and self._drag_dest_source:
self._drag_motion_counter += 1
return True

uris = data.get_uris()
if self._drag_dest_source and self._drag_motion_counter >= 2:
if self.shell.props.display_page_tree:
self.shell.props.display_page_tree.select(self._drag_dest_source)
self.rbtree.expand_all()

for uri in uris:
self._drag_motion_counter = -1
return False

entry = self.shell.props.db.entry_lookup_by_location(uri)
if entry:
dest_query_model.add_entry(entry, -1)
if self._drag_motion_counter == -1:
self._drag_motion_counter = 0
GLib.timeout_add_seconds(1, delayed)

if result:
Gdk.drag_status(drag_context, Gdk.DragAction.COPY, time)
else:
# cannot drop here
Gdk.drag_status(drag_context, 0, time)
self._drag_dest_source = None

return True

def on_drag_data_received(self, widget, drag_context, x, y, data, info,
time):
'''
Callback called when the drag source has prepared the data (pixbuf)
for us to use.
'''
print ("on_drag_data_received")
# stop the propagation of the signal (deactivates superclass callback)
widget.stop_emission_by_name('drag-data-received')

path, pos = widget.get_dest_row_at_pos(x, y)
dest_source = self.treestore_filter[path][1]

drag_context.finish(True, False, time)

dest_query_model = dest_source.props.query_model

uris = data.get_uris()

for uri in uris:

entry = self.shell.props.db.entry_lookup_by_location(uri)
if entry:
dest_query_model.add_entry(entry, -1)


def _on_playing_song_changed(self, *args):
Expand Down

0 comments on commit 7092a6c

Please sign in to comment.