Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable autoscroll when rubberband selecting #266

Merged
merged 1 commit into from
Aug 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 30 additions & 18 deletions pdfarranger/pdfarranger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,22 +1249,7 @@ def iv_dnd_data_delete(self, _widget, _context):
def iv_dnd_motion(self, iconview, context, x, y, etime):
"""Handles drag motion: autoscroll, select move or copy, select drag cursor location."""
# Auto-scroll when drag up/down
autoscroll_area = 40
sw_vadj = self.sw.get_vadjustment()
sw_height = self.sw.get_allocation().height
if y - sw_vadj.get_value() < autoscroll_area - self.vp_css_margin:
if not self.iv_auto_scroll_timer:
self.iv_auto_scroll_direction = Gtk.DirectionType.UP
self.iv_auto_scroll_timer = GObject.timeout_add(150,
self.iv_auto_scroll)
elif y - sw_vadj.get_value() > sw_height - autoscroll_area - self.vp_css_margin:
if not self.iv_auto_scroll_timer:
self.iv_auto_scroll_direction = Gtk.DirectionType.DOWN
self.iv_auto_scroll_timer = GObject.timeout_add(150,
self.iv_auto_scroll)
elif self.iv_auto_scroll_timer:
GObject.source_remove(self.iv_auto_scroll_timer)
self.iv_auto_scroll_timer = None
self.iv_autoscroll(x, y, autoscroll_area=40)

# Select move or copy dragAction
drag_move_posix = os.name == 'posix' and context.get_actions() & Gdk.DragAction.MOVE
Expand Down Expand Up @@ -1315,6 +1300,24 @@ def iv_dnd_motion(self, iconview, context, x, y, etime):
iconview.set_drag_dest_item(self.drag_path, self.drag_pos)
return True

def iv_autoscroll(self, x, y, autoscroll_area):
"""Iconview auto-scrolling."""
sw_vadj = self.sw.get_vadjustment()
sw_height = self.sw.get_allocation().height
if y - sw_vadj.get_value() < autoscroll_area - self.vp_css_margin:
if not self.iv_auto_scroll_timer:
self.iv_auto_scroll_direction = Gtk.DirectionType.UP
self.iv_auto_scroll_timer = GObject.timeout_add(150,
self.iv_auto_scroll)
elif y - sw_vadj.get_value() > sw_height - autoscroll_area - self.vp_css_margin:
if not self.iv_auto_scroll_timer:
self.iv_auto_scroll_direction = Gtk.DirectionType.DOWN
self.iv_auto_scroll_timer = GObject.timeout_add(150,
self.iv_auto_scroll)
elif self.iv_auto_scroll_timer:
GObject.source_remove(self.iv_auto_scroll_timer)
self.iv_auto_scroll_timer = None

def iv_dnd_leave_end(self, _widget, _context, _ignored=None):
"""Ends the auto-scroll during DND"""

Expand All @@ -1336,8 +1339,8 @@ def iv_auto_scroll(self):
return True # call me again

def iv_motion(self, iconview, event):
"""Manages mouse movement on the iconview to detect drag and drop events"""

"""Manages mouse movement on the iconview."""
# Detect drag and drop events
if self.pressed_button:
if iconview.drag_check_threshold(self.pressed_button.x,
self.pressed_button.y,
Expand All @@ -1347,6 +1350,10 @@ def iv_motion(self, iconview, event):
self.pressed_button.button, event, -1, -1)
self.pressed_button = None

# Detect if rubberband selecting is in progress
if event.state & Gdk.ModifierType.BUTTON1_MASK:
self.iv_autoscroll(event.x, event.y, autoscroll_area=4)

def iv_button_release_event(self, iconview, event):
"""Manages mouse releases on the iconview"""

Expand All @@ -1364,6 +1371,11 @@ def iv_button_release_event(self, iconview, event):
iconview.set_cursor(path, None, False) # for consistent shift+click selection
self.pressed_button = None

# Stop rubberband autoscrolling when mouse button is released
if self.iv_auto_scroll_timer:
GObject.source_remove(self.iv_auto_scroll_timer)
self.iv_auto_scroll_timer = None

def iv_button_press_event(self, iconview, event):
"""Manages mouse clicks on the iconview"""

Expand Down