History

mac/view: optimise drag and drop event handling

der richter committed 2 years ago

Commit 3afcaeb1 parent 2a36ed91 file · +11 −17Browse files

Unified · Split

video/out/mac/view.swift+11−17
@@ -78,30 +78,24 @@ class View: NSView, CALayerDelegate { · 77 unmodified lines
78 override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {78 override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
79 let pb = sender.draggingPasteboard79 let pb = sender.draggingPasteboard
80 guard let types = pb.types else { return false }80 guard let types = pb.types else { return false }
81 var files: [String] = []
81 82
82 if types.contains(.fileURL) || types.contains(.URL) {83 if types.contains(.fileURL) || types.contains(.URL) {
83 if let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] {84 guard let urls = pb.readObjects(forClasses: [NSURL.self]) as? [URL] else { return false }
84 let files = urls.map { $0.absoluteString }85 files = urls.map { $0.absoluteString }
85 input?.open(files: files)
86 return true
87 }
88 } else if types.contains(.string) {86 } else if types.contains(.string) {
89 guard let str = pb.string(forType: .string) else { return false }87 guard let str = pb.string(forType: .string) else { return false }
90 var filesArray: [String] = []88 files = str.components(separatedBy: "\n").compactMap {
91 89 let url = $0.trimmingCharacters(in: .whitespacesAndNewlines)
92 for val in str.components(separatedBy: "\n") {
93 let url = val.trimmingCharacters(in: .whitespacesAndNewlines)
94 let path = (url as NSString).expandingTildeInPath90 let path = (url as NSString).expandingTildeInPath
95 if isURL(url) {91 if isURL(url) { return url }
96 filesArray.append(url)92 if path.starts(with: "/") { return path }
97 } else if path.starts(with: "/") {93 return nil
98 filesArray.append(path)
99 }
100 }94 }
101 input?.open(files: filesArray)
102 return true
103 }95 }
104 return false96 if files.isEmpty { return false }
97 input?.open(files: files)
98 return true
105 }99 }
106 100
107 override func acceptsFirstMouse(for event: NSEvent?) -> Bool {101 override func acceptsFirstMouse(for event: NSEvent?) -> Bool {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t