diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-08 10:58:56 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-08 10:58:56 +0200 |
| commit | 3cca7e9f25166c995a9b9b7bca5beb20be969ac7 (patch) | |
| tree | e4c373b3ed71e08010e53e4efdd92f82692dba97 /Map/Presentation/Commands/MapCommands.swift | |
| parent | 1b098db3824728699b2dd9d0820b8599a7750560 (diff) | |
Comment out unused preferences4.0.0
Diffstat (limited to 'Map/Presentation/Commands/MapCommands.swift')
| -rw-r--r-- | Map/Presentation/Commands/MapCommands.swift | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/Map/Presentation/Commands/MapCommands.swift b/Map/Presentation/Commands/MapCommands.swift index bcdfd1f..2d9809d 100644 --- a/Map/Presentation/Commands/MapCommands.swift +++ b/Map/Presentation/Commands/MapCommands.swift @@ -69,15 +69,15 @@ struct MapCommands: Commands { var formatPopup: NSPopUpButton! let savePanel: NSSavePanel - let formats: [(String, NSBitmapImageRep.FileType, UTType, String)] + let formats: [ExportFormats] let baseFilename: String init( savePanel: NSSavePanel, - formats: [(String, NSBitmapImageRep.FileType, UTType, String)], baseFilename: String + baseFilename: String ) { self.savePanel = savePanel - self.formats = formats + self.formats = ExportFormats.allCases self.baseFilename = baseFilename super.init(nibName: nil, bundle: nil) } @@ -97,8 +97,8 @@ struct MapCommands: Commands { frame: NSRect(x: 60, y: 5, width: 120, height: 20), pullsDown: false) formatPopup.autoenablesItems = false - for (name, _, _, _) in formats { - formatPopup.addItem(withTitle: name) + for format in ExportFormats.allCases { + formatPopup.addItem(withTitle: format.title) } for item in formatPopup.itemArray { @@ -106,9 +106,11 @@ struct MapCommands: Commands { } // Restore last selected format - let lastSelectedFormat = UserDefaults.standard.integer(forKey: "lastExportFormat") - let validIndex = min(max(lastSelectedFormat, 0), formats.count - 1) - formatPopup.selectItem(at: validIndex) + let lastSelectedFormat = + UserDefaults.standard.string(forKey: "defaultExportFormat") ?? "png" + let format = ExportFormats(rawValue: lastSelectedFormat) ?? .png + savePanel.allowedContentTypes = [format.utType] + formatPopup.selectItem(withTitle: format.title) formatPopup.target = self formatPopup.action = #selector(formatChanged(_:)) @@ -123,28 +125,21 @@ struct MapCommands: Commands { let selectedFormat = formats[selectedIndex] // Update allowed content types - savePanel.allowedContentTypes = [selectedFormat.2] + savePanel.allowedContentTypes = [selectedFormat.utType] // Save the selection for next time - UserDefaults.standard.set(selectedIndex, forKey: "lastExportFormat") + UserDefaults.standard.set(selectedFormat.rawValue, forKey: "defaultExportFormat") } } - // Add format options - let formats: [(String, NSBitmapImageRep.FileType, UTType, String)] = [ - ("PNG", .png, .png, "png"), - ("JPEG", .jpeg, .jpeg, "jpg"), - ("TIFF", .tiff, .tiff, "tiff"), - ("BMP", .bmp, .bmp, "bmp"), - ("GIF", .gif, .gif, "gif"), - ] + let formats = ExportFormats.allCases let savePanel = NSSavePanel() - // Set initial content type based on last selection - let lastSelectedFormat = UserDefaults.standard.integer(forKey: "lastExportFormat") - let validIndex = min(max(lastSelectedFormat, 0), formats.count - 1) - savePanel.allowedContentTypes = [formats[validIndex].2] + let lastSelectedFormat = + UserDefaults.standard.string(forKey: "defaultExportFormat") ?? "png" + let format = ExportFormats(rawValue: lastSelectedFormat) ?? .png + savePanel.allowedContentTypes = [format.utType] savePanel.canCreateDirectories = true savePanel.isExtensionHidden = false @@ -153,7 +148,7 @@ struct MapCommands: Commands { savePanel.nameFieldStringValue = "\(filename)" let accessoryController = ExportAccessoryViewController( - savePanel: savePanel, formats: formats, baseFilename: filename) + savePanel: savePanel, baseFilename: filename) savePanel.accessoryView = accessoryController.view savePanel.begin { result in @@ -164,7 +159,7 @@ struct MapCommands: Commands { // Generate data based on selected format let imageData = bitmapImage?.representation( - using: selectedFormat.1, properties: [:]) + using: selectedFormat.fileType, properties: [:]) do { try imageData?.write(to: url) |