diff options
Diffstat (limited to 'Map/Presentation')
| -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 |
4 files changed, 58 insertions, 34 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) 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: |