aboutsummaryrefslogtreecommitdiff
path: root/Map/Presentation/Commands/MapCommands.swift
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-09-16 20:32:25 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2024-09-16 20:32:25 +0200
commit144915635bdfc90445321189914929a911fe77d4 (patch)
tree20f77a976c19f9c8bd138cd3dce06a742acb5113 /Map/Presentation/Commands/MapCommands.swift
parentf93215a7b37e065a0a52a852bb2c35d2a3d77b0b (diff)
Add search
Diffstat (limited to 'Map/Presentation/Commands/MapCommands.swift')
-rw-r--r--Map/Presentation/Commands/MapCommands.swift62
1 files changed, 58 insertions, 4 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()
}