Skip to content

Commit

Permalink
Merge pull request #2291 from freakboy3742/table-crash
Browse files Browse the repository at this point in the history
Prevent drag operations (and thus crash) on macOS TableView
  • Loading branch information
mhsmith authored Dec 20, 2023
2 parents 2d027ce + 86328a6 commit de1b76f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
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

0 comments on commit de1b76f

Please sign in to comment.