Skip to content

Commit b89643c

Browse files
mobile-arnikitabobko
authored andcommitted
Display shortcut for each MessageView button
closes #1570
1 parent b51e29b commit b89643c

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

Sources/AppBundle/ui/MenuBar.swift

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public func menuBar(viewModel: TrayMenuModel) -> some Scene { // todo should it
4242
}
4343
}.keyboardShortcut("E", modifiers: .command)
4444
getExperimentalUISettingsMenu(viewModel: viewModel)
45-
openConfigButton
46-
reloadConfigButton
45+
openConfigButton()
46+
reloadConfigButton()
4747
Button("Quit \(aeroSpaceAppName)") {
4848
Task {
4949
defer { terminateApp() }
@@ -70,9 +70,10 @@ public func menuBar(viewModel: TrayMenuModel) -> some Scene { // todo should it
7070
}
7171
}
7272

73-
var openConfigButton: some View {
73+
@MainActor @ViewBuilder
74+
func openConfigButton(showShortcutGroup: Bool = false) -> some View {
7475
let editor = getTextEditorToOpenConfig()
75-
return Button("Open config in '\(editor.lastPathComponent)'") {
76+
let button = Button("Open config in '\(editor.lastPathComponent)'") {
7677
let fallbackConfig: URL = FileManager.default.homeDirectoryForCurrentUser.appending(path: configDotfileName)
7778
switch findCustomConfigUrl() {
7879
case .file(let url):
@@ -84,16 +85,36 @@ var openConfigButton: some View {
8485
fallbackConfig.open(with: editor)
8586
}
8687
}.keyboardShortcut(",", modifiers: .command)
88+
if showShortcutGroup {
89+
shortcutGroup(label: Text("⌘ ,"), content: button)
90+
} else {
91+
button
92+
}
8793
}
8894

8995
@MainActor @ViewBuilder
90-
var reloadConfigButton: some View {
96+
func reloadConfigButton(showShortcutGroup: Bool = false) -> some View {
9197
if let token: RunSessionGuard = .isServerEnabled {
92-
Button("Reload config") {
98+
let button = Button("Reload config") {
9399
Task {
94100
try await runSession(.menuBarButton, token) { _ = reloadConfig() }
95101
}
96102
}.keyboardShortcut("R", modifiers: .command)
103+
if showShortcutGroup {
104+
shortcutGroup(label: Text("⌘ R"), content: button)
105+
} else {
106+
button
107+
}
108+
}
109+
}
110+
111+
func shortcutGroup(label: some View, content: some View) -> some View {
112+
GroupBox {
113+
VStack(alignment: .trailing, spacing: 6) {
114+
label
115+
.foregroundStyle(Color.secondary)
116+
content
117+
}
97118
}
98119
}
99120

Sources/AppBundle/ui/MessageView.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,12 @@ public struct MessageView: View {
6767
if let type = model.message?.type {
6868
switch type {
6969
case .config:
70-
reloadConfigButton
71-
openConfigButton
70+
reloadConfigButton(showShortcutGroup: true)
71+
openConfigButton(showShortcutGroup: true)
7272
}
7373
}
74-
Button("Close") {
75-
model.message = nil
76-
}
77-
.keyboardShortcut(.defaultAction)
74+
let closeButton = Button("Close") { model.message = nil }.keyboardShortcut(.defaultAction)
75+
shortcutGroup(label: Image(systemName: "return.left"), content: closeButton)
7876
}
7977
.padding()
8078
}

0 commit comments

Comments
 (0)