diff --git a/CHANGELOG.md b/CHANGELOG.md index 76eba7065879..093496001d0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ All notable changes to cmux are documented here. ## [0.64.3] - 2026-05-05 ### Added +- Added Show in Finder to the workspace sidebar right-click menu. - `cmux config` CLI with `cmux config doctor` for validating `cmux.json` without a socket, plus `cmux config path`, `cmux config docs`, and `cmux config reload` aliases ([#3454](https://github.com/manaflow-ai/cmux/pull/3454)) ### Fixed diff --git a/GhosttyTabs.xcodeproj/project.pbxproj b/GhosttyTabs.xcodeproj/project.pbxproj index fdd1f92f4a78..ba607359dfe7 100644 --- a/GhosttyTabs.xcodeproj/project.pbxproj +++ b/GhosttyTabs.xcodeproj/project.pbxproj @@ -122,6 +122,7 @@ B37A00000000000000000001 /* BetaFeaturesSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B37A00000000000000000002 /* BetaFeaturesSettingsView.swift */; }; B37A00000000000000000007 /* SettingsCardNote.swift in Sources */ = {isa = PBXBuildFile; fileRef = B37A00000000000000000008 /* SettingsCardNote.swift */; }; A5001002 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001012 /* ContentView.swift */; }; + C0DE36230000000000000001 /* WorkspaceFinderDirectoryResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DE36230000000000000002 /* WorkspaceFinderDirectoryResolver.swift */; }; A5001F000000000000000001 /* DetachedFolderDragIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5001F000000000000000002 /* DetachedFolderDragIcon.swift */; }; C0DE35010000000000000001 /* SidebarScrim.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DE35010000000000000002 /* SidebarScrim.swift */; }; 62270F3DCECB4787D789CCE3 /* SidebarWorkspaceSnapshotRefreshPolicyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F016B5C09357B3226FA2E014 /* SidebarWorkspaceSnapshotRefreshPolicyTests.swift */; }; @@ -578,6 +579,7 @@ B37A00000000000000000002 /* BetaFeaturesSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetaFeaturesSettingsView.swift; sourceTree = ""; }; B37A00000000000000000008 /* SettingsCardNote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCardNote.swift; sourceTree = ""; }; A5001012 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + C0DE36230000000000000002 /* WorkspaceFinderDirectoryResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WorkspaceFinderDirectoryResolver.swift; sourceTree = ""; }; A5001F000000000000000002 /* DetachedFolderDragIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetachedFolderDragIcon.swift; sourceTree = ""; }; C0DE35010000000000000002 /* SidebarScrim.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarScrim.swift; sourceTree = ""; }; C3408A000000000000000002 /* ContentView+RightSidebarCommandPalette.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ContentView+RightSidebarCommandPalette.swift"; sourceTree = ""; }; @@ -1072,6 +1074,7 @@ B37A00000000000000000002 /* BetaFeaturesSettingsView.swift */, B37A00000000000000000008 /* SettingsCardNote.swift */, A5001012 /* ContentView.swift */, + C0DE36230000000000000002 /* WorkspaceFinderDirectoryResolver.swift */, A5001F000000000000000002 /* DetachedFolderDragIcon.swift */, D0B1001BA1B2C3D4E5F60001 /* FileDropHintBadgeView.swift */, D0B10021A1B2C3D4E5F60001 /* FileDropOverlayView.swift */, @@ -1696,6 +1699,7 @@ B37A00000000000000000001 /* BetaFeaturesSettingsView.swift in Sources */, B37A00000000000000000007 /* SettingsCardNote.swift in Sources */, A5001002 /* ContentView.swift in Sources */, + C0DE36230000000000000001 /* WorkspaceFinderDirectoryResolver.swift in Sources */, A5001F000000000000000001 /* DetachedFolderDragIcon.swift in Sources */, C0DE35010000000000000001 /* SidebarScrim.swift in Sources */, C3408A000000000000000001 /* ContentView+RightSidebarCommandPalette.swift in Sources */, diff --git a/Resources/Localizable.xcstrings b/Resources/Localizable.xcstrings index 5a324ffd2b11..16cb0b4f2bee 100644 --- a/Resources/Localizable.xcstrings +++ b/Resources/Localizable.xcstrings @@ -105119,6 +105119,23 @@ } } }, + "contextMenu.showWorkspaceInFinder": { + "extractionState": "manual", + "localizations": { + "en": { + "stringUnit": { + "state": "translated", + "value": "Show in Finder" + } + }, + "ja": { + "stringUnit": { + "state": "translated", + "value": "Finderで表示" + } + } + } + }, "contextMenu.workspaceSettings": { "extractionState": "manual", "localizations": { diff --git a/Sources/ContentView.swift b/Sources/ContentView.swift index 449b60e23086..4b67b277d08c 100644 --- a/Sources/ContentView.swift +++ b/Sources/ContentView.swift @@ -12132,6 +12132,8 @@ private struct TabItemView: View, Equatable { @StateObject private var contextMenuState = SidebarTabItemContextMenuState() @State private var rowInteractionState = SidebarWorkspaceRowInteractionState() @State private var rowHeight: CGFloat = 1 + @State private var workspaceFinderDirectoryCache = WorkspaceFinderDirectoryCache() + @State private var workspaceFinderDirectoryOpenRequest: WorkspaceFinderDirectoryOpenRequest? var isMultiSelected: Bool { selectedTabIds.contains(tab.id) @@ -12372,6 +12374,8 @@ private struct TabItemView: View, Equatable { let accessibilityHintText = String(localized: "sidebar.workspace.accessibilityHint", defaultValue: "Activate to focus this workspace. Drag to reorder, or use Move Up and Move Down actions.") let moveUpActionText = String(localized: "sidebar.workspace.moveUpAction", defaultValue: "Move Up") let moveDownActionText = String(localized: "sidebar.workspace.moveDownAction", defaultValue: "Move Down") + let finderDirectoryPath = WorkspaceFinderDirectoryResolver.path(for: tab) + let finderDirectoryCacheKey = WorkspaceFinderDirectoryCacheKey(path: finderDirectoryPath) let latestNotificationSubtitle = latestNotificationText let submittedMessageSubtitle = settings.iMessageModeEnabled ? workspaceSnapshot.latestSubmittedMessage? @@ -12680,6 +12684,17 @@ private struct TabItemView: View, Equatable { .onAppear { refreshWorkspaceSnapshot(force: true) } + .task(id: finderDirectoryCacheKey) { + let cache = await WorkspaceFinderDirectoryResolver.cache(for: finderDirectoryCacheKey) + guard !Task.isCancelled else { return } + workspaceFinderDirectoryCache = cache + } + .task(id: workspaceFinderDirectoryOpenRequest) { + guard let request = workspaceFinderDirectoryOpenRequest else { return } + await WorkspaceFinderDirectoryOpener.openInFinder(request.directoryURL) + guard !Task.isCancelled, workspaceFinderDirectoryOpenRequest == request else { return } + workspaceFinderDirectoryOpenRequest = nil + } .onReceive( tab.sidebarImmediateObservationPublisher .receive(on: RunLoop.main) @@ -12859,6 +12874,10 @@ private struct TabItemView: View, Equatable { let renameWorkspaceShortcut = KeyboardShortcutSettings.shortcut(for: .renameWorkspace) let editWorkspaceDescriptionShortcut = KeyboardShortcutSettings.shortcut(for: .editWorkspaceDescription) let closeWorkspaceShortcut = KeyboardShortcutSettings.shortcut(for: .closeWorkspace) + let finderDirectoryCacheKey = WorkspaceFinderDirectoryCacheKey( + path: isMulti ? nil : WorkspaceFinderDirectoryResolver.path(for: tab) + ) + let finderDirectoryURL = workspaceFinderDirectoryCache.url(for: finderDirectoryCacheKey) Button(pinLabel) { guard let contextMenuPinState else { NSSound.beep() @@ -12906,6 +12925,7 @@ private struct TabItemView: View, Equatable { tabManager.clearCustomDescription(tabId: tab.id) } } + } if !remoteContextMenuWorkspaceIds.isEmpty { @@ -13073,6 +13093,13 @@ private struct TabItemView: View, Equatable { copyWorkspaceIdsToPasteboard(targetIds) } .disabled(targetIds.isEmpty) + + if !isMulti { + Button(String(localized: "contextMenu.showWorkspaceInFinder", defaultValue: "Show in Finder")) { + workspaceFinderDirectoryOpenRequest = WorkspaceFinderDirectoryOpenRequest(directoryURL: finderDirectoryURL) + } + .disabled(finderDirectoryURL == nil) + } } private var backgroundColor: Color { diff --git a/Sources/Workspace.swift b/Sources/Workspace.swift index afd1ff5faf5b..180331abf128 100644 --- a/Sources/Workspace.swift +++ b/Sources/Workspace.swift @@ -8887,7 +8887,7 @@ final class Workspace: Identifiable, ObservableObject { return resolved } - func sidebarDirectoriesInDisplayOrder(orderedPanelIds: [UUID]) -> [String] { + func sidebarDirectoriesInDisplayOrder(orderedPanelIds: [UUID], includeFallback: Bool = true) -> [String] { let resolvedDirectories = sidebarResolvedPanelDirectories(orderedPanelIds: orderedPanelIds) let homeDirectoryForCanonicalization = sidebarHomeDirectoryForCanonicalization( resolvedPanelDirectories: resolvedDirectories @@ -8906,7 +8906,7 @@ final class Workspace: Identifiable, ObservableObject { } } - if ordered.isEmpty, let fallbackDirectory = normalizedSidebarDirectory(currentDirectory) { + if includeFallback, ordered.isEmpty, let fallbackDirectory = normalizedSidebarDirectory(currentDirectory) { return [fallbackDirectory] } @@ -8916,6 +8916,16 @@ final class Workspace: Identifiable, ObservableObject { func sidebarDirectoriesInDisplayOrder() -> [String] { sidebarDirectoriesInDisplayOrder(orderedPanelIds: sidebarOrderedPanelIds()) } + func sidebarFinderDirectory() -> String? { + guard !isRemoteWorkspace else { return nil } + let panelIds = sidebarOrderedPanelIds() + let localPanelIds = panelIds.filter { + !remoteDetectedSurfaceIds.contains($0) + && !isRemoteTerminalSurface($0) + && !pendingRemoteTerminalChildExitSurfaceIds.contains($0) + } + return sidebarDirectoriesInDisplayOrder(orderedPanelIds: localPanelIds, includeFallback: panelIds.isEmpty || localPanelIds.count == panelIds.count).first + } func sidebarGitBranchesInDisplayOrder(orderedPanelIds: [UUID]) -> [SidebarGitBranchState] { SidebarBranchOrdering diff --git a/Sources/WorkspaceFinderDirectoryResolver.swift b/Sources/WorkspaceFinderDirectoryResolver.swift new file mode 100644 index 000000000000..41399aad9659 --- /dev/null +++ b/Sources/WorkspaceFinderDirectoryResolver.swift @@ -0,0 +1,72 @@ +import AppKit +import Foundation + +struct WorkspaceFinderDirectoryCacheKey: Equatable, Sendable { + var path: String? +} + +struct WorkspaceFinderDirectoryCache: Equatable, Sendable { + var key: WorkspaceFinderDirectoryCacheKey? = nil + var directoryURL: URL? = nil + + func url(for currentKey: WorkspaceFinderDirectoryCacheKey) -> URL? { + guard key == currentKey else { return nil } + return directoryURL + } +} + +struct WorkspaceFinderDirectoryOpenRequest: Equatable, Sendable { + var id = UUID() + var directoryURL: URL? +} + +enum WorkspaceFinderDirectoryResolver { + @MainActor + static func path(for workspace: Workspace) -> String? { + guard let directory = workspace.sidebarFinderDirectory() else { return nil } + let path = NSString(string: directory).expandingTildeInPath + return path.isEmpty ? nil : path + } + + static func cache(for key: WorkspaceFinderDirectoryCacheKey) async -> WorkspaceFinderDirectoryCache { + guard let path = key.path else { return WorkspaceFinderDirectoryCache(key: key) } + let directoryURL = await existingDirectoryURL(for: path) + return WorkspaceFinderDirectoryCache(key: key, directoryURL: directoryURL) + } + + static func existingDirectoryURL(for path: String) async -> URL? { + guard !Task.isCancelled else { return nil } + let directoryURL = await Task.detached(priority: .utility) { + existingDirectoryURLUnchecked(for: path) + }.value + guard !Task.isCancelled else { return nil } + return directoryURL + } + + private nonisolated static func existingDirectoryURLUnchecked(for path: String) -> URL? { + var isDirectory: ObjCBool = false + guard FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory), + isDirectory.boolValue else { + return nil + } + return URL(fileURLWithPath: path, isDirectory: true).standardizedFileURL + } +} + +enum WorkspaceFinderDirectoryOpener { + @MainActor + static func openInFinder(_ directoryURL: URL?) async { + guard !Task.isCancelled else { return } + guard let directoryURL else { + NSSound.beep() + return + } + if let refreshedURL = await WorkspaceFinderDirectoryResolver.existingDirectoryURL(for: directoryURL.path) { + guard !Task.isCancelled else { return } + NSWorkspace.shared.activateFileViewerSelecting([refreshedURL]) + } else { + guard !Task.isCancelled else { return } + NSSound.beep() + } + } +}