From 1eb9ede9603b32f2ecfa818f244ca52b487f85e3 Mon Sep 17 00:00:00 2001 From: Feror Date: Tue, 2 Jun 2026 14:51:19 +0200 Subject: [PATCH] fix(workspace): present AppKit folder picker --- Sources/SaplingApp/SaplingApp.swift | 36 +++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Sources/SaplingApp/SaplingApp.swift b/Sources/SaplingApp/SaplingApp.swift index 1c8e904..f8dd671 100644 --- a/Sources/SaplingApp/SaplingApp.swift +++ b/Sources/SaplingApp/SaplingApp.swift @@ -66,7 +66,6 @@ private final class SaplingAppModel: ObservableObject { @Published var editorViewModel: HybridMarkdownEditorViewModel? @Published var configuration: SaplingConfiguration @Published var editorErrorMessage: String? - @Published var isImportingWorkspace = false private let configurationStore: any ConfigurationStore private let workspaceManager: any WorkspaceManaging @@ -92,7 +91,25 @@ private final class SaplingAppModel: ObservableObject { } 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 { @@ -249,21 +266,6 @@ private struct MainWindow: View { .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( isPresented: $isImportingMarkdown, allowedContentTypes: [.saplingMarkdown, .plainText],