Skip to content

Commit d355b8e

Browse files
committed
updated
1 parent 92785ef commit d355b8e

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

Example/Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"location" : "https://github.com/flocked/FZSwiftUtils.git",
1616
"state" : {
1717
"branch" : "main",
18-
"revision" : "46706eedbacdc373b75c12c61a876a69e310858c"
18+
"revision" : "b232aa1776a3f9024456556b400ab0555f9a1150"
1919
}
2020
},
2121
{

Sources/AdvancedCollectionTableView/DiffableDataSource/NSCollectionView/CollectionViewDiffableDataSource.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,6 @@ open class CollectionViewDiffableDataSource<Section: Identifiable & Hashable, El
285285
collectionView.setDraggingSourceOperationMask(.copy, forLocal: false)
286286

287287
collectionView.addGestureRecognizer(dragGesture)
288-
289-
290288
// collectionView.setDraggingSourceOperationMask(.move, forLocal: true)
291289
}
292290

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// NSCollectionView+DragSessionMove.swift
3+
//
4+
//
5+
// Created by Florian Zand on 02.03.25.
6+
//
7+
8+
import AppKit
9+
import FZSwiftUtils
10+
11+
extension NSCollectionView {
12+
var draggingSessionMoveHandler: ((NSDraggingSession, CGPoint)->())? {
13+
get { getAssociatedValue("draggingSessionMoveHandler") }
14+
set {
15+
setAssociatedValue(newValue, key: "draggingSessionMoveHandler")
16+
let selector = #selector(NSCollectionView.draggingSession(_:movedTo:))
17+
if newValue != nil {
18+
guard !isMethodReplaced(selector) else { return }
19+
do {
20+
try replaceMethod(
21+
selector,
22+
methodSignature: (@convention(c) (AnyObject, Selector, NSDraggingSession, CGPoint) -> ()).self,
23+
hookSignature: (@convention(block) (AnyObject, NSDraggingSession, CGPoint) -> ()).self) { store in {
24+
object, session, point in
25+
(object as? NSCollectionView)?.draggingSessionMoveHandler?(session, point)
26+
store.original(object, selector, session, point)
27+
}
28+
}
29+
} catch {
30+
debugPrint(error)
31+
}
32+
} else {
33+
resetMethod(selector)
34+
}
35+
}
36+
}
37+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// NSTableView+DragSessionMove.swift
3+
//
4+
//
5+
// Created by Florian Zand on 02.03.25.
6+
//
7+
8+
import AppKit
9+
import FZSwiftUtils
10+
11+
extension NSTableView {
12+
var draggingSessionMoveHandler: ((NSDraggingSession, CGPoint)->())? {
13+
get { getAssociatedValue("draggingSessionMoveHandler") }
14+
set {
15+
setAssociatedValue(newValue, key: "draggingSessionMoveHandler")
16+
let selector = #selector(NSTableView.draggingSession(_:movedTo:))
17+
if newValue != nil {
18+
guard !isMethodReplaced(selector) else { return }
19+
do {
20+
if responds(to: selector) {
21+
try replaceMethod(
22+
selector,
23+
methodSignature: (@convention(c) (AnyObject, Selector, NSDraggingSession, CGPoint) -> ()).self,
24+
hookSignature: (@convention(block) (AnyObject, NSDraggingSession, CGPoint) -> ()).self) { store in {
25+
object, session, point in
26+
(object as? NSTableView)?.draggingSessionMoveHandler?(session, point)
27+
store.original(object, selector, session, point)
28+
}
29+
}
30+
} else {
31+
try addMethod(
32+
selector,
33+
methodSignature: (@convention(c) (AnyObject, Selector, NSDraggingSession, CGPoint) -> ()).self,
34+
hookSignature: (@convention(block) (AnyObject, NSDraggingSession, CGPoint) -> ()).self) { store in {
35+
object, session, point in
36+
(object as? NSTableView)?.draggingSessionMoveHandler?(session, point)
37+
}
38+
}
39+
}
40+
} catch {
41+
debugPrint(error)
42+
}
43+
} else {
44+
resetMethod(selector)
45+
}
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)