mac/menu: optimise loading files function

don't save files in a temporary array and use an in place mapping.
This commit is contained in:
der richter 2024-03-03 15:39:07 +01:00
parent cb807ff063
commit eadd85a6ac
1 changed files with 3 additions and 7 deletions

View File

@ -106,7 +106,7 @@ class MenuBar: NSObject {
]
let fileMenuConfigs = [
Config(name: "Open File…", key: "o", action: #selector(openFile), target: self),
Config(name: "Open File…", key: "o", action: #selector(openFiles), target: self),
Config(name: "Open URL…", key: "O", action: #selector(openUrl), target: self),
Config(name: "Open Playlist…", action: #selector(openPlaylist), target: self),
Config(name: "separator"),
@ -329,17 +329,13 @@ class MenuBar: NSObject {
}
}
@objc func openFile() {
@objc func openFiles() {
let panel = NSOpenPanel()
panel.allowsMultipleSelection = true
panel.canChooseDirectories = true
if panel.runModal() == .OK {
var files: [String] = []
for url in panel.urls {
files += [url.path]
}
(NSApp as? Application)?.openFiles(files)
(NSApp as? Application)?.openFiles(panel.urls.map { $0.path })
}
}