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

Prevent drag operations (and thus crash) on macOS TableView #2291

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion examples/table/table/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ExampleTableApp(toga.App):
lbl_fontsize = None

def load_data(self):
yak = toga.Icon.TOGA_ICON
yak = toga.Icon.DEFAULT_ICON
red = toga.Icon("icons/red")
green = toga.Icon("icons/green")

Expand Down
2 changes: 1 addition & 1 deletion examples/tutorial2/tutorial/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def startup(self):
action2,
text="Action 2",
tooltip="Perform action 2",
icon=toga.Icon.TOGA_ICON,
icon=toga.Icon.DEFAULT_ICON,
group=things,
)

Expand Down