Repository navigation
Make Open With palette commands bindable #4112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
90ecd13
Make open-with palette commands bindable
austinywang 4832bc0
Address open-with directory launch review feedback
austinywang b04c227
Address open-with shortcut review feedback
austinywang 4aacabc
Refine open-with shortcut routing
austinywang dabae5c
Merge remote-tracking branch 'origin/main' into issue-4111-bindable-o…
austinywang 26974b0
Merge remote-tracking branch 'origin/main' into issue-4111-bindable-o…
austinywang 77a7fcc
fix: restore open-with directory fallback
austinywang 9aaade6
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 8c804de
fix: address terminal open shortcut review
austinywang fd5125c
Merge remote-tracking branch 'origin/main' into issue-4111-bindable-o…
austinywang 6a22307
fix: unwrap terminal open launcher test error
austinywang bf486da
fix: localize open with shortcut category
austinywang 61b8b8d
Merge remote-tracking branch 'origin/main' into issue-4111-bindable-o…
austinywang 1519d76
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang 73a764b
Merge remote-tracking branch 'origin/main' into issue-4111-bindable-o…
austinywang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Sources/App/KeyboardShortcutSettings+TerminalDirectoryOpen.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| enum TerminalDirectoryOpenShortcutBindings { | ||
| typealias Binding = (target: TerminalDirectoryOpenTarget, action: KeyboardShortcutSettings.Action) | ||
|
|
||
| static let all: [Binding] = TerminalDirectoryOpenTarget.commandPaletteShortcutTargets.map { target in | ||
| (target, KeyboardShortcutSettings.Action.terminalDirectoryOpenAction(for: target)) | ||
| } | ||
|
|
||
| static let actions: [KeyboardShortcutSettings.Action] = all.map { $0.action } | ||
| } | ||
|
|
||
| extension KeyboardShortcutSettings.Action { | ||
| static var terminalDirectoryOpenActions: [Self] { | ||
| TerminalDirectoryOpenShortcutBindings.actions | ||
| } | ||
|
|
||
| static var terminalDirectoryOpenShortcutBindings: [TerminalDirectoryOpenShortcutBindings.Binding] { | ||
| TerminalDirectoryOpenShortcutBindings.all | ||
| } | ||
|
|
||
| static func terminalDirectoryOpenAction(for target: TerminalDirectoryOpenTarget) -> Self { | ||
| switch target { | ||
| case .androidStudio: | ||
| return .terminalOpenDirectoryAndroidStudio | ||
| case .antigravity: | ||
| return .terminalOpenDirectoryAntigravity | ||
| case .cursor: | ||
| return .terminalOpenDirectoryCursor | ||
| case .finder: | ||
| return .terminalOpenDirectoryFinder | ||
| case .ghostty: | ||
| return .terminalOpenDirectoryGhostty | ||
| case .intellij: | ||
| return .terminalOpenDirectoryIntelliJ | ||
| case .iterm2: | ||
| return .terminalOpenDirectoryITerm2 | ||
| case .terminal: | ||
| return .terminalOpenDirectoryTerminal | ||
| case .tower: | ||
| return .terminalOpenDirectoryTower | ||
| case .vscode: | ||
| return .terminalOpenDirectoryVSCode | ||
| case .vscodeInline: | ||
| return .terminalOpenDirectoryVSCodeInline | ||
| case .warp: | ||
| return .terminalOpenDirectoryWarp | ||
| case .windsurf: | ||
| return .terminalOpenDirectoryWindsurf | ||
| case .xcode: | ||
| return .terminalOpenDirectoryXcode | ||
| case .zed: | ||
| return .terminalOpenDirectoryZed | ||
| } | ||
| } | ||
|
|
||
| var terminalDirectoryOpenTarget: TerminalDirectoryOpenTarget? { | ||
| TerminalDirectoryOpenShortcutBindings.all.first { $0.action == self }?.target | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import AppKit | ||
| import Foundation | ||
|
|
||
| @MainActor | ||
| enum TerminalDirectoryOpenLauncher { | ||
| typealias ApplicationOpenCompletion = @MainActor (Error?) -> Void | ||
| typealias ApplicationOpenHandler = ( | ||
| _ urls: [URL], | ||
| _ applicationURL: URL, | ||
| _ configuration: NSWorkspace.OpenConfiguration, | ||
| _ completion: @escaping ApplicationOpenCompletion | ||
| ) -> Void | ||
|
|
||
| static func currentDirectoryURL(in tabManager: TabManager?) -> URL? { | ||
| guard let workspace = tabManager?.selectedWorkspace else { return nil } | ||
| let focusedPanelDirectory = workspace.focusedPanelId.flatMap { workspace.panelDirectories[$0] } | ||
| return firstValidDirectoryURL(in: [focusedPanelDirectory, workspace.currentDirectory]) | ||
| } | ||
|
|
||
| static func firstValidDirectoryURL(in rawDirectories: [String?]) -> URL? { | ||
| for rawDirectory in rawDirectories { | ||
| let trimmed = rawDirectory?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" | ||
| guard !trimmed.isEmpty else { continue } | ||
| var isDirectory: ObjCBool = false | ||
| guard FileManager.default.fileExists(atPath: trimmed, isDirectory: &isDirectory), | ||
| isDirectory.boolValue else { | ||
| continue | ||
| } | ||
| return URL(fileURLWithPath: trimmed, isDirectory: true) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| static func openCurrentDirectory( | ||
| in target: TerminalDirectoryOpenTarget, | ||
| tabManager: TabManager?, | ||
| onOpenFailure: ApplicationOpenCompletion? = nil | ||
| ) -> Bool { | ||
| guard let directoryURL = currentDirectoryURL(in: tabManager) else { return false } | ||
| return openDirectory( | ||
| directoryURL, | ||
| in: target, | ||
| tabManager: tabManager, | ||
| onOpenFailure: onOpenFailure | ||
| ) | ||
| } | ||
|
|
||
| static func openDirectory( | ||
| _ directoryURL: URL, | ||
| in target: TerminalDirectoryOpenTarget, | ||
| tabManager: TabManager?, | ||
| onOpenFailure: ApplicationOpenCompletion? = nil, | ||
| applicationURLProvider: (TerminalDirectoryOpenTarget) -> URL? = { $0.applicationURL() }, | ||
| openWithApplication: ApplicationOpenHandler? = nil | ||
| ) -> Bool { | ||
| switch target { | ||
| case .finder: | ||
| return NSWorkspace.shared.selectFile(nil, inFileViewerRootedAtPath: directoryURL.path) | ||
| case .vscodeInline: | ||
| return AppDelegate.shared?.openDirectoryInInlineVSCode(directoryURL, tabManager: tabManager) ?? false | ||
| default: | ||
| guard let applicationURL = applicationURLProvider(target) else { return false } | ||
| let configuration = NSWorkspace.OpenConfiguration() | ||
| let openWithApplication = openWithApplication ?? openURLsWithApplication | ||
| openWithApplication([directoryURL], applicationURL, configuration) { error in | ||
| guard error != nil else { return } | ||
| onOpenFailure?(error) | ||
| } | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| private static func openURLsWithApplication( | ||
| _ urls: [URL], | ||
| applicationURL: URL, | ||
| configuration: NSWorkspace.OpenConfiguration, | ||
| completion: @escaping ApplicationOpenCompletion | ||
| ) { | ||
| NSWorkspace.shared.open(urls, withApplicationAt: applicationURL, configuration: configuration) { _, error in | ||
| Task { @MainActor in | ||
| completion(error) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.