diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-09-16 20:32:25 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2024-09-16 20:32:25 +0200 |
| commit | 144915635bdfc90445321189914929a911fe77d4 (patch) | |
| tree | 20f77a976c19f9c8bd138cd3dce06a742acb5113 /Map/Presentation/Commands | |
| parent | f93215a7b37e065a0a52a852bb2c35d2a3d77b0b (diff) | |
Add search
Diffstat (limited to 'Map/Presentation/Commands')
| -rw-r--r-- | Map/Presentation/Commands/MapCommands.swift | 62 | ||||
| -rw-r--r-- | Map/Presentation/Commands/UpdateCommands.swift | 43 |
2 files changed, 79 insertions, 26 deletions
diff --git a/Map/Presentation/Commands/MapCommands.swift b/Map/Presentation/Commands/MapCommands.swift index b0fbf9c..83c4b27 100644 --- a/Map/Presentation/Commands/MapCommands.swift +++ b/Map/Presentation/Commands/MapCommands.swift @@ -20,9 +20,63 @@ struct MapCommands: Commands { @AppStorage("viewStyle") var viewStyle: ViewStyle = .horizontal @AppStorage("zoom") var zoom = 1.0 + @FocusedBinding(\.document) var document: MapDocument? + @FocusedValue(\.fileURL) var url: URL? + @FocusedBinding(\.selectedEvolution) var selectedEvolution: StageType? + @FocusedBinding(\.isSearching) var isSearching var body: some Commands { + // File + + CommandGroup(after: CommandGroupPlacement.saveItem) { + Divider() + Button("Export...") { + if let selectedEvolution, let document { + if let image = document.exportAsImage(withEvolution: selectedEvolution) { + + let filename = url?.deletingPathExtension().lastPathComponent ?? "Untitled" + + let savePanel = NSSavePanel() + savePanel.allowedContentTypes = [.png] + savePanel.canCreateDirectories = true + savePanel.isExtensionHidden = false + savePanel.title = "Save \(filename) as image" + savePanel.message = "Choose a location to save the image" + savePanel.nameFieldStringValue = "\(filename).png" + savePanel.begin { result in + if result == .OK, let url = savePanel.url { + if let tiffRepresentation = image.tiffRepresentation { + let bitmapImage = NSBitmapImageRep(data: tiffRepresentation) + let pngData = bitmapImage?.representation(using: .png, properties: [:]) + do { + try pngData?.write(to: url) + } catch { + return + } + } + } + } + } + } + }.keyboardShortcut( + "e", modifiers: EventModifiers([.command]) + ).disabled(document == nil) + } + + // Edit + + CommandGroup(after: CommandGroupPlacement.pasteboard) { + Divider() + Button("Find...") { + withAnimation { + isSearching = isSearching != nil ? !isSearching! : true + } + }.keyboardShortcut( + "f", modifiers: EventModifiers([.command]) + ).disabled(document == nil) + } + // View CommandGroup(after: CommandGroupPlacement.toolbar) { @@ -31,25 +85,25 @@ struct MapCommands: Commands { viewStyle = .vertical }.keyboardShortcut( "l", modifiers: EventModifiers([.command]) - ) + ).disabled(document == nil) } else { Button("Use Horizontal Layout") { viewStyle = .horizontal }.keyboardShortcut( "l", modifiers: EventModifiers([.command]) - ) + ).disabled(document == nil) } Divider() Button("Zoom In") { zoom = min(Constants.kMaxZoom, zoom + 0.1) }.keyboardShortcut( "+", modifiers: EventModifiers([.command]) - ) + ).disabled(document == nil) Button("Zoom Out") { zoom = max(Constants.kMinZoom, zoom - 0.1) }.keyboardShortcut( "-", modifiers: EventModifiers([.command]) - ) + ).disabled(document == nil) Divider() } diff --git a/Map/Presentation/Commands/UpdateCommands.swift b/Map/Presentation/Commands/UpdateCommands.swift index 51d2b0a..3a019cc 100644 --- a/Map/Presentation/Commands/UpdateCommands.swift +++ b/Map/Presentation/Commands/UpdateCommands.swift @@ -1,3 +1,4 @@ +import Sparkle /* Copyright (C) 2024 Rubén Beltrán del Río @@ -15,11 +16,10 @@ along with this program. If not, see https://map.tranquil.systems. */ import SwiftUI -import Sparkle struct UpdateCommands: Commands { let updaterController: SPUStandardUpdaterController - + var body: some Commands { CommandGroup(after: .appInfo) { CheckForUpdatesView(updater: updaterController.updater) @@ -27,29 +27,28 @@ struct UpdateCommands: Commands { } } - struct CheckForUpdatesView: View { - @ObservedObject private var checkForUpdatesViewModel: CheckForUpdatesViewModel - private let updater: SPUUpdater - - init(updater: SPUUpdater) { - self.updater = updater - - // Create our view model for our CheckForUpdatesView - self.checkForUpdatesViewModel = CheckForUpdatesViewModel(updater: updater) - } - - var body: some View { - Button("Check for Updates…", action: updater.checkForUpdates) - .disabled(!checkForUpdatesViewModel.canCheckForUpdates) - } + @ObservedObject private var checkForUpdatesViewModel: CheckForUpdatesViewModel + private let updater: SPUUpdater + + init(updater: SPUUpdater) { + self.updater = updater + + // Create our view model for our CheckForUpdatesView + self.checkForUpdatesViewModel = CheckForUpdatesViewModel(updater: updater) + } + + var body: some View { + Button("Check for Updates…", action: updater.checkForUpdates) + .disabled(!checkForUpdatesViewModel.canCheckForUpdates) + } } final class CheckForUpdatesViewModel: ObservableObject { - @Published var canCheckForUpdates = false + @Published var canCheckForUpdates = false - init(updater: SPUUpdater) { - updater.publisher(for: \.canCheckForUpdates) - .assign(to: &$canCheckForUpdates) - } + init(updater: SPUUpdater) { + updater.publisher(for: \.canCheckForUpdates) + .assign(to: &$canCheckForUpdates) + } } |