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 | |
| parent | 1b098db3824728699b2dd9d0820b8599a7750560 (diff) | |
Comment out unused preferences4.0.0
| -rw-r--r-- | Map/Data/ExportFormats.swift | 55 | ||||
| -rw-r--r-- | Map/Localizable.xcstrings | 75 | ||||
| -rw-r--r-- | Map/Presentation/Commands/MapCommands.swift | 43 | ||||
| -rw-r--r-- | Map/Presentation/Preferences/EditorPreferencesView.swift | 10 | ||||
| -rw-r--r-- | Map/Presentation/Preferences/MapPreferencesView.swift | 23 | ||||
| -rw-r--r-- | Map/Presentation/PreferencesWindow.swift | 16 |
6 files changed, 188 insertions, 34 deletions
diff --git a/Map/Data/ExportFormats.swift b/Map/Data/ExportFormats.swift new file mode 100644 index 0000000..b0b916b --- /dev/null +++ b/Map/Data/ExportFormats.swift @@ -0,0 +1,55 @@ +import SwiftUI +import UniformTypeIdentifiers + +enum ExportFormats: String, CaseIterable { + case png + case jpeg + case tiff + case bmp + case gif + + var title: String { + switch self { + case .png: + String(localized: "export_formats.png") + case .jpeg: + String(localized: "export_formats.jpeg") + case .tiff: + String(localized: "export_formats.tiff") + case .bmp: + String(localized: "export_formats.bmp") + case .gif: + String(localized: "export_formats.gif") + } + } + + var utType: UTType { + switch self { + case .png: + .png + case .jpeg: + .jpeg + case .tiff: + .tiff + case .bmp: + .bmp + case .gif: + .gif + } + } + + var fileType: NSBitmapImageRep.FileType { + switch self { + case .png: + .png + case .jpeg: + .jpeg + case .tiff: + .tiff + case .bmp: + .bmp + case .gif: + .gif + } + } +} diff --git a/Map/Localizable.xcstrings b/Map/Localizable.xcstrings index f2c0b6c..d7cc56a 100644 --- a/Map/Localizable.xcstrings +++ b/Map/Localizable.xcstrings @@ -169,12 +169,65 @@ } } }, + "export_formats.bmp" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "BMP" + } + } + } + }, + "export_formats.gif" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "GIF" + } + } + } + }, + "export_formats.jpeg" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "JPEG" + } + } + } + }, + "export_formats.png" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "PNG" + } + } + } + }, + "export_formats.tiff" : { + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "TIFF" + } + } + } + }, "General Preferences" : { }, "General settings will be available here in a future version." : { }, + "Key" : { + "extractionState" : "manual" + }, "map_editor.zoom_in" : { "extractionState" : "manual", "localizations" : { @@ -340,6 +393,28 @@ } } }, + "preferences.map.export.default_format" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Default Format" + } + } + } + }, + "preferences.map.export.title" : { + "extractionState" : "manual", + "localizations" : { + "en" : { + "stringUnit" : { + "state" : "translated", + "value" : "Export Options:" + } + } + } + }, "preferences.map.map_style.show_background" : { "extractionState" : "manual", "localizations" : { 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) diff --git a/Map/Presentation/Preferences/EditorPreferencesView.swift b/Map/Presentation/Preferences/EditorPreferencesView.swift index 3d456c9..cf584ff 100644 --- a/Map/Presentation/Preferences/EditorPreferencesView.swift +++ b/Map/Presentation/Preferences/EditorPreferencesView.swift @@ -95,19 +95,25 @@ struct EditorPreferencesView: View { .frame(maxWidth: .infinity, alignment: .leading) } + /* + + Disabled because we haven't written the smart editor yet. + Call it aspirational preferences. + Divider() - + HStack(alignment: .firstTextBaseline, spacing: Dimensions.Spacing.regular) { Text("preferences.editor.smart_editor.title") .font(.Theme.Body.emphasized) .frame(maxWidth: 250, alignment: .trailing) - + VStack(alignment: .leading, spacing: Dimensions.Spacing.cozy) { Toggle( String(localized: "preferences.editor.smart_editor.enabled"), isOn: $useSmartEditor) } .frame(maxWidth: .infinity, alignment: .leading) } + */ Spacer() }.padding(.vertical, Dimensions.Spacing.loose) diff --git a/Map/Presentation/Preferences/MapPreferencesView.swift b/Map/Presentation/Preferences/MapPreferencesView.swift index d81916f..f6c909c 100644 --- a/Map/Presentation/Preferences/MapPreferencesView.swift +++ b/Map/Presentation/Preferences/MapPreferencesView.swift @@ -19,6 +19,7 @@ struct MapPreferencesView: View { @AppStorage("showMapBackground") private var showBackground = true @AppStorage("useCustomFont") private var useCustomFont = false @AppStorage("customFontName") private var customFontName = "Helvetica" + @AppStorage("defaultExportFormat") private var defaultExportFormat = "png" var body: some View { VStack(alignment: .center, spacing: Dimensions.Spacing.loose) { @@ -55,6 +56,28 @@ struct MapPreferencesView: View { .frame(maxWidth: .infinity, alignment: .leading) } + Divider() + + HStack(alignment: .firstTextBaseline, spacing: Dimensions.Spacing.regular) { + Text("preferences.map.export.title") + .font(.Theme.Body.emphasized) + .frame(maxWidth: 250, alignment: .trailing) + + VStack(alignment: .leading, spacing: Dimensions.Spacing.cozy) { + Text("preferences.map.export.default_format") + .font(.Theme.Body.regular) + Picker("", selection: $defaultExportFormat) { + ForEach(ExportFormats.allCases, id: \.self) { exportFormat in + Text(exportFormat.title).tag(exportFormat.rawValue) + } + } + .pickerStyle(MenuPickerStyle()) + .frame(maxWidth: 250) + .padding(.leading, -Dimensions.Spacing.regular) + } + .frame(maxWidth: .infinity, alignment: .leading) + } + Spacer() }.padding(.vertical, Dimensions.Spacing.loose) .padding(.horizontal, Dimensions.Spacing.indulgent) diff --git a/Map/Presentation/PreferencesWindow.swift b/Map/Presentation/PreferencesWindow.swift index fa5bd4c..06153ed 100644 --- a/Map/Presentation/PreferencesWindow.swift +++ b/Map/Presentation/PreferencesWindow.swift @@ -17,7 +17,7 @@ import SwiftUI enum PreferencesTab: CaseIterable { - case general + // case general case editor case map case stages @@ -25,8 +25,8 @@ enum PreferencesTab: CaseIterable { var localizedStringKey: LocalizedStringKey { switch self { - case .general: - return "preferences.menu.general" + // case .general: + // return "preferences.menu.general" case .editor: return "preferences.menu.editor" case .map: @@ -40,8 +40,8 @@ enum PreferencesTab: CaseIterable { var systemImage: String { switch self { - case .general: - return "gearshape" + // case .general: + // return "gearshape" case .editor: return "text.word.spacing" case .map: @@ -55,13 +55,13 @@ enum PreferencesTab: CaseIterable { } struct PreferencesWindow: View { - @State private var selectedTab: PreferencesTab = .general + @State private var selectedTab: PreferencesTab = .editor var body: some View { Group { switch selectedTab { - case .general: - GeneralPreferencesView() + // case .general: + // GeneralPreferencesView() case .editor: EditorPreferencesView() case .map: |