diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-07 16:52:28 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-07 16:52:28 +0200 |
| commit | e59dcf2bcf7841ebe6f3d85ec3ec03319b261da4 (patch) | |
| tree | 3311ea9e5fbc9f26fe1b170318c9b179faf42dff /Map/Presentation/Commands/MapCommands.swift | |
| parent | 3bacbf6ac85330d35493953d7296e5ba420b7750 (diff) | |
More localization keys, font editor preferences, better new file
Diffstat (limited to 'Map/Presentation/Commands/MapCommands.swift')
| -rw-r--r-- | Map/Presentation/Commands/MapCommands.swift | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/Map/Presentation/Commands/MapCommands.swift b/Map/Presentation/Commands/MapCommands.swift index bd0227d..baf69ad 100644 --- a/Map/Presentation/Commands/MapCommands.swift +++ b/Map/Presentation/Commands/MapCommands.swift @@ -66,8 +66,8 @@ struct MapCommands: Commands { 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.title = String(localized: "commands.file.export.panel.title \(filename)") + savePanel.message = String(localized: "commands.file.export.panel.content") savePanel.nameFieldStringValue = "\(filename).png" savePanel.begin { result in if result == .OK, let url = savePanel.url { @@ -139,17 +139,16 @@ struct MapCommands: Commands { @MainActor private func createNewDocument(from template: Template) { - // Create a temporary file with the template content - let temporaryDirectory = FileManager.default.temporaryDirectory - let temporaryFile = temporaryDirectory.appendingPathComponent("Template-\(template.name).wmap") + // Store the template content in UserDefaults temporarily + UserDefaults.standard.set(template.content, forKey: "pendingTemplateContent") - do { - try template.content.write(to: temporaryFile, atomically: true, encoding: .utf8) - NSWorkspace.shared.open(temporaryFile) - } catch { - // Fallback: just trigger the new document command - NSApplication.shared.sendAction( - #selector(NSDocumentController.newDocument(_:)), to: nil, from: nil) + // Create a new document using the standard mechanism + NSApplication.shared.sendAction( + #selector(NSDocumentController.newDocument(_:)), to: nil, from: nil) + + // Clear the pending template content after a short delay + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + UserDefaults.standard.removeObject(forKey: "pendingTemplateContent") } } } |