1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-18 05:07:18 +00:00

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

View File

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