fix(workspace): present AppKit folder picker
This commit is contained in:
parent
1d7840e45c
commit
1eb9ede960
1 changed files with 19 additions and 17 deletions
|
|
@ -66,7 +66,6 @@ private final class SaplingAppModel: ObservableObject {
|
||||||
@Published var editorViewModel: HybridMarkdownEditorViewModel?
|
@Published var editorViewModel: HybridMarkdownEditorViewModel?
|
||||||
@Published var configuration: SaplingConfiguration
|
@Published var configuration: SaplingConfiguration
|
||||||
@Published var editorErrorMessage: String?
|
@Published var editorErrorMessage: String?
|
||||||
@Published var isImportingWorkspace = false
|
|
||||||
|
|
||||||
private let configurationStore: any ConfigurationStore
|
private let configurationStore: any ConfigurationStore
|
||||||
private let workspaceManager: any WorkspaceManaging
|
private let workspaceManager: any WorkspaceManaging
|
||||||
|
|
@ -92,7 +91,25 @@ private final class SaplingAppModel: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func presentWorkspaceImporter() {
|
func presentWorkspaceImporter() {
|
||||||
isImportingWorkspace = true
|
#if os(macOS)
|
||||||
|
let panel = NSOpenPanel()
|
||||||
|
panel.title = "Open Workspace"
|
||||||
|
panel.message = "Choose a folder to use as your Sapling workspace."
|
||||||
|
panel.prompt = "Open"
|
||||||
|
panel.canChooseDirectories = true
|
||||||
|
panel.canChooseFiles = false
|
||||||
|
panel.allowsMultipleSelection = false
|
||||||
|
panel.canCreateDirectories = false
|
||||||
|
panel.resolvesAliases = true
|
||||||
|
|
||||||
|
guard panel.runModal() == .OK, let url = panel.url else { return }
|
||||||
|
|
||||||
|
Task {
|
||||||
|
await openWorkspace(at: url)
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
editorErrorMessage = "Workspace selection is currently available on macOS."
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
func openWorkspace(at url: URL) async {
|
func openWorkspace(at url: URL) async {
|
||||||
|
|
@ -249,21 +266,6 @@ private struct MainWindow: View {
|
||||||
.keyboardShortcut("s", modifiers: .command)
|
.keyboardShortcut("s", modifiers: .command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.fileImporter(
|
|
||||||
isPresented: $model.isImportingWorkspace,
|
|
||||||
allowedContentTypes: [.folder],
|
|
||||||
allowsMultipleSelection: false
|
|
||||||
) { result in
|
|
||||||
switch result {
|
|
||||||
case .success(let urls):
|
|
||||||
guard let url = urls.first else { return }
|
|
||||||
Task {
|
|
||||||
await model.openWorkspace(at: url)
|
|
||||||
}
|
|
||||||
case .failure(let error):
|
|
||||||
model.editorErrorMessage = "Unable to open workspace: \(error.localizedDescription)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.fileImporter(
|
.fileImporter(
|
||||||
isPresented: $isImportingMarkdown,
|
isPresented: $isImportingMarkdown,
|
||||||
allowedContentTypes: [.saplingMarkdown, .plainText],
|
allowedContentTypes: [.saplingMarkdown, .plainText],
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue