History

mac/dialog: add support for title, file selection and initial directory

der richter committed 1 year ago

Commit ebb0fe61 parent c75779d1 file · +9 −5Browse files

Unified · Split

osdep/mac/dialog.swift+9−5
@@ -25,22 +25,26 @@ class Dialog { · 24 unmodified lines
25 self.option = option25 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)?.first39 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 = directories48 panel.canChooseDirectories = directories
45 panel.allowsMultipleSelection = multiple49 panel.allowsMultipleSelection = multiple
46 panel.allowedContentTypes = types50 panel.allowedContentTypes = types

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