Skip to content

Commit

Permalink
Prevent table views from initiating drags.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Dec 20, 2023
1 parent 2d027ce commit d1f54a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/1156.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TableViews on macOS will no longer crash if a drag operation is initiated from inside the table.
13 changes: 12 additions & 1 deletion cocoa/src/toga_cocoa/widgets/table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from rubicon.objc import SEL, at, objc_method, objc_property
from rubicon.objc import SEL, NSPoint, at, objc_method, objc_property
from travertino.size import at_least

import toga
Expand All @@ -21,6 +21,16 @@ class TogaTable(NSTableView):
interface = objc_property(object, weak=True)
impl = objc_property(object, weak=True)

# NSTableView methods
@objc_method
def canDragRowsWithIndexes_atPoint_(
self,
rowIndexes,
mouseDownPoint: NSPoint,
) -> bool:
# Disable all drags
return False

# TableDataSource methods
@objc_method
def numberOfRowsInTableView_(self, table) -> int:
Expand Down Expand Up @@ -140,6 +150,7 @@ def create(self):
)
self.native_table.usesAlternatingRowBackgroundColors = True
self.native_table.allowsMultipleSelection = self.interface.multiple_select
self.native_table.allowsColumnReordering = False

# Create columns for the table
self.columns = []
Expand Down

0 comments on commit d1f54a5

Please sign in to comment.