Unified · Split
| @@ -25,22 +25,26 @@ class Dialog { · 24 unmodified lines | |||
| 25 | self.option = option | 25 | self.option = option |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | func openFiles() -> [String]? { | 28 | func openFiles(title: String? = nil, path: URL? = nil) -> [String]? { |
| 29 | let types: [UTType] = (TypeHelper.toStringArray(option?.root.video_exts) + | 29 | let types: [UTType] = (TypeHelper.toStringArray(option?.root.video_exts) + |
| 30 | TypeHelper.toStringArray(option?.root.audio_exts) + | 30 | TypeHelper.toStringArray(option?.root.audio_exts) + |
| 31 | TypeHelper.toStringArray(option?.root.image_exts) + | 31 | TypeHelper.toStringArray(option?.root.image_exts) + |
| 32 | TypeHelper.toStringArray(option?.root.archive_exts) + | 32 | TypeHelper.toStringArray(option?.root.archive_exts) + |
| 33 | TypeHelper.toStringArray(option?.root.playlist_exts)).compactMap { UTType(filenameExtension: $0) } | 33 | TypeHelper.toStringArray(option?.root.playlist_exts)).compactMap { UTType(filenameExtension: $0) } |
| 34 | return open(types: types) | 34 | return open(title: title, path: path, types: types) |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | func openPlaylist() -> String? { | 37 | func openPlaylist(title: String? = nil, path: URL? = nil) -> String? { |
| 38 | let types: [UTType] = TypeHelper.toStringArray(option?.root.playlist_exts).compactMap { UTType(filenameExtension: $0) } | 38 | let types: [UTType] = TypeHelper.toStringArray(option?.root.playlist_exts).compactMap { UTType(filenameExtension: $0) } |
| 39 | return open(directories: false, multiple: false, types: types)?.first | 39 | return open(title: title, path: path, directories: false, multiple: false, types: types)?.first |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | func open(directories: Bool = true, multiple: Bool = true, types: [UTType] = []) -> [String]? { | 42 | func open(title: String? = nil, path: URL? = nil, files: Bool = true, |
| 43 | directories: Bool = true, multiple: Bool = true, types: [UTType] = []) -> [String]? { | ||
| 43 | let panel = NSOpenPanel() | 44 | let panel = NSOpenPanel() |
| 45 | panel.title = title ?? panel.title | ||
| 46 | panel.directoryURL = path | ||
| 47 | panel.canChooseFiles = files | ||
| 44 | panel.canChooseDirectories = directories | 48 | panel.canChooseDirectories = directories |
| 45 | panel.allowsMultipleSelection = multiple | 49 | panel.allowsMultipleSelection = multiple |
| 46 | panel.allowedContentTypes = types | 50 | panel.allowedContentTypes = types |