diff options
Diffstat (limited to 'Map/Presentation/Commands')
| -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") } } } |