aboutsummaryrefslogtreecommitdiff
path: root/Hotline
diff options
context:
space:
mode:
authorJeff Verkoeyen <jverkoey@gmail.com>2024-07-31 21:14:11 -0400
committerElectric Sidecar <github@electricsidecar.app>2024-07-31 21:29:02 -0400
commit5dc0ed09a3cdebad75d46aa3ef8f7a83b18ba449 (patch)
treeba3e3d567872c92a74734c593e9717aa12a0441a /Hotline
parent93841e378308f959566e1411a7cba6a2602db2e8 (diff)
Add Cmd+Down keyboard shortcut for connecting to servers.
Diffstat (limited to 'Hotline')
-rw-r--r--Hotline/Application-macOS.swift19
-rw-r--r--Hotline/macOS/TrackerView.swift16
2 files changed, 30 insertions, 5 deletions
diff --git a/Hotline/Application-macOS.swift b/Hotline/Application-macOS.swift
index 56ead01..fe3a828 100644
--- a/Hotline/Application-macOS.swift
+++ b/Hotline/Application-macOS.swift
@@ -77,6 +77,7 @@ struct Application: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@State private var hotlinePanel: HotlinePanel? = nil
+ @State private var selection: Bookmark? = nil
@FocusedValue(\.activeHotlineModel) private var activeHotline: Hotline?
@FocusedValue(\.activeServerState) private var activeServerState: ServerState?
@@ -97,7 +98,7 @@ struct Application: App {
var body: some Scene {
// MARK: Tracker Window
Window("Servers", id: "servers") {
- TrackerView()
+ TrackerView(selection: $selection)
.frame(minWidth: 250, minHeight: 250)
}
.modelContainer(self.modelContainer)
@@ -195,6 +196,14 @@ struct Application: App {
}
}
CommandMenu("Server") {
+ Button("Connect") {
+ guard let selection else {
+ return
+ }
+ connect(to: selection)
+ }
+ .disabled(selection == nil || selection?.server == nil)
+ .keyboardShortcut(.downArrow, modifiers: .command)
Button("Disconnect") {
activeHotline?.disconnect()
}
@@ -259,7 +268,13 @@ struct Application: App {
.defaultSize(width: 450, height: 550)
.defaultPosition(.center)
}
-
+
+ func connect(to item: Bookmark) {
+ if let server = item.server {
+ openWindow(id: "server", value: server)
+ }
+ }
+
func showBannerWindow() {
if hotlinePanel == nil {
hotlinePanel = HotlinePanel(HotlinePanelView())
diff --git a/Hotline/macOS/TrackerView.swift b/Hotline/macOS/TrackerView.swift
index a52bccd..0fac8b0 100644
--- a/Hotline/macOS/TrackerView.swift
+++ b/Hotline/macOS/TrackerView.swift
@@ -18,8 +18,8 @@ struct TrackerView: View {
@State private var bookmarkExport: BookmarkDocument? = nil
@Query(sort: \Bookmark.order) private var bookmarks: [Bookmark]
- @State private var selection: Bookmark? = nil
-
+ @Binding var selection: Bookmark?
+
var body: some View {
List(selection: $selection) {
ForEach(bookmarks, id: \.self) { bookmark in
@@ -459,6 +459,16 @@ struct TrackerItemView: View {
}
}
+#if DEBUG
+private struct TrackerViewPreview: View {
+ @State var selection: Bookmark? = nil
+
+ var body: some View {
+ TrackerView(selection: $selection)
+ }
+}
+
#Preview {
- TrackerView()
+ TrackerViewPreview()
}
+#endif