diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-23 12:50:16 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-23 12:50:16 -0700 |
| commit | 23b3f338f0818a53b2499692e999a0528e5d9753 (patch) | |
| tree | 19f2d018824cdc41c0aa37dde6bde5d9054be9f2 /Hotline/macOS | |
| parent | 842611754debec7d1814e44e6a2cf302e84c0d66 (diff) | |
Add Bookmark exporting to Server window context menu.
Diffstat (limited to 'Hotline/macOS')
| -rw-r--r-- | Hotline/macOS/TrackerView.swift | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Hotline/macOS/TrackerView.swift b/Hotline/macOS/TrackerView.swift index 5a9db9b..5ab4c65 100644 --- a/Hotline/macOS/TrackerView.swift +++ b/Hotline/macOS/TrackerView.swift @@ -1,9 +1,9 @@ import SwiftUI import SwiftData +import Foundation import UniformTypeIdentifiers struct TrackerView: View { -// @Environment(BookmarksOld.self) private var bookmarks: BookmarksOld @Environment(\.colorScheme) private var colorScheme @Environment(\.openWindow) private var openWindow @Environment(\.controlActiveState) private var controlActiveState @@ -14,6 +14,8 @@ struct TrackerView: View { @State private var trackerSheetBookmark: Bookmark? = nil @State private var attemptedPrepopulate: Bool = false @State private var fileDropActive = false + @State private var bookmarkExportActive = false + @State private var bookmarkExport: BookmarkDocument? = nil @Query(sort: \Bookmark.order) private var bookmarks: [Bookmark] @State private var selection: Bookmark? = nil @@ -96,6 +98,17 @@ struct TrackerView: View { } } + if item.type == .server { + Button { + bookmarkExport = BookmarkDocument(bookmark: item) + bookmarkExportActive = true + } label: { + Label("Export Bookmark...", systemImage: "bookmark.square") + } + } + + Divider() + Button { Bookmark.delete(item, context: modelContext) } label: { @@ -121,6 +134,17 @@ struct TrackerView: View { openWindow(id: "server", value: server) } } + .fileExporter(isPresented: $bookmarkExportActive, document: bookmarkExport, contentTypes: [.data], defaultFilename: "\(bookmarkExport?.bookmark.name ?? "Hotline Bookmark").hlbm", onCompletion: { result in + switch result { + case .success(let fileURL): + print("Hotline Bookmark: Successfully exported:", fileURL) + case .failure(let err): + print("Hotline Bookmark: Failed to export:", err) + } + + bookmarkExport = nil + bookmarkExportActive = false + }, onCancellation: {}) .onKeyPress(.rightArrow) { if let bookmark = selection, |