Repo // Refactoring how tab icons are managed in PrefWindow / PrefUI.

This commit is contained in:
ShikiSuen 2022-08-19 09:02:18 +08:00
parent 31e715ba52
commit 664e86006c
5 changed files with 60 additions and 62 deletions

View File

@ -9,68 +9,94 @@
import Cocoa import Cocoa
import SwiftUI import SwiftUI
@available(macOS 10.15, *) extension NSImage {
class ctlPrefUI { static var tabImageGeneral: NSImage! {
private(set) var tabImageGeneral: NSImage! = NSImage(named: "PrefToolbar-General") if #unavailable(macOS 11.0) {
private(set) var tabImageExperiences: NSImage! = NSImage(named: "PrefToolbar-Experiences") return NSImage(named: "PrefToolbar-General")
private(set) var tabImageDictionary: NSImage! = NSImage(named: "PrefToolbar-Dictionary") } else {
private(set) var tabImageKeyboard: NSImage! = NSImage(named: "PrefToolbar-Keyboard") return NSImage(
private(set) var tabImageDevZone: NSImage! = NSImage(named: "PrefToolbar-DevZone")
init() {
if #available(macOS 11.0, *) {
tabImageGeneral = NSImage(
systemSymbolName: "wrench.and.screwdriver.fill", accessibilityDescription: "General Preferences" systemSymbolName: "wrench.and.screwdriver.fill", accessibilityDescription: "General Preferences"
) )
tabImageExperiences = NSImage(
systemSymbolName: "person.fill.questionmark", accessibilityDescription: "Experiences Preferences"
)
tabImageDictionary = NSImage(
systemSymbolName: "character.book.closed.fill", accessibilityDescription: "Dictionary Preferences"
)
tabImageKeyboard = NSImage(
systemSymbolName: "keyboard.macwindow", accessibilityDescription: "Keyboard Preferences"
)
tabImageDevZone = NSImage(
systemSymbolName: "hand.raised.circle", accessibilityDescription: "DevZone Preferences"
)
} }
} }
static var tabImageExperience: NSImage! {
if #unavailable(macOS 11.0) {
return NSImage(named: "PrefToolbar-Experience")
} else {
return NSImage(
systemSymbolName: "person.fill.questionmark", accessibilityDescription: "Experience Preferences"
)
}
}
static var tabImageDictionary: NSImage! {
if #unavailable(macOS 11.0) {
return NSImage(named: "PrefToolbar-Dictionary")
} else {
return NSImage(
systemSymbolName: "character.book.closed.fill", accessibilityDescription: "Dictionary Preferences"
)
}
}
static var tabImageKeyboard: NSImage! {
if #unavailable(macOS 11.0) {
return NSImage(named: "PrefToolbar-Keyboard")
} else {
return NSImage(
systemSymbolName: "keyboard.macwindow", accessibilityDescription: "Keyboard Preferences"
)
}
}
static var tabImageDevZone: NSImage! {
if #unavailable(macOS 11.0) {
return NSImage(named: "PrefToolbar-DevZone")
} else {
return NSImage(
systemSymbolName: "hand.raised.circle", accessibilityDescription: "DevZone Preferences"
)
}
}
}
@available(macOS 10.15, *)
class ctlPrefUI {
lazy var controller = PreferencesWindowController( lazy var controller = PreferencesWindowController(
panes: [ panes: [
Preferences.Pane( Preferences.Pane(
identifier: Preferences.PaneIdentifier(rawValue: "General"), identifier: Preferences.PaneIdentifier(rawValue: "General"),
title: NSLocalizedString("General", comment: ""), title: NSLocalizedString("General", comment: ""),
toolbarIcon: tabImageGeneral toolbarIcon: .tabImageGeneral
) { ) {
suiPrefPaneGeneral() suiPrefPaneGeneral()
}, },
Preferences.Pane( Preferences.Pane(
identifier: Preferences.PaneIdentifier(rawValue: "Experiences"), identifier: Preferences.PaneIdentifier(rawValue: "Experience"),
title: NSLocalizedString("Experience", comment: ""), title: NSLocalizedString("Experience", comment: ""),
toolbarIcon: tabImageExperiences toolbarIcon: .tabImageExperience
) { ) {
suiPrefPaneExperience() suiPrefPaneExperience()
}, },
Preferences.Pane( Preferences.Pane(
identifier: Preferences.PaneIdentifier(rawValue: "Dictionary"), identifier: Preferences.PaneIdentifier(rawValue: "Dictionary"),
title: NSLocalizedString("Dictionary", comment: ""), title: NSLocalizedString("Dictionary", comment: ""),
toolbarIcon: tabImageDictionary toolbarIcon: .tabImageDictionary
) { ) {
suiPrefPaneDictionary() suiPrefPaneDictionary()
}, },
Preferences.Pane( Preferences.Pane(
identifier: Preferences.PaneIdentifier(rawValue: "Keyboard"), identifier: Preferences.PaneIdentifier(rawValue: "Keyboard"),
title: NSLocalizedString("Keyboard", comment: ""), title: NSLocalizedString("Keyboard", comment: ""),
toolbarIcon: tabImageKeyboard toolbarIcon: .tabImageKeyboard
) { ) {
suiPrefPaneKeyboard() suiPrefPaneKeyboard()
}, },
Preferences.Pane( Preferences.Pane(
identifier: Preferences.PaneIdentifier(rawValue: "DevZone"), identifier: Preferences.PaneIdentifier(rawValue: "DevZone"),
title: NSLocalizedString("DevZone", comment: ""), title: NSLocalizedString("DevZone", comment: ""),
toolbarIcon: tabImageDevZone toolbarIcon: .tabImageDevZone
) { ) {
suiPrefPaneDevZone() suiPrefPaneDevZone()
}, },

View File

@ -389,59 +389,31 @@ extension ctlPrefWindow: NSToolbarDelegate {
case .ofGeneral: case .ofGeneral:
let title = NSLocalizedString("General", comment: "") let title = NSLocalizedString("General", comment: "")
item.label = title item.label = title
if #available(macOS 11.0, *) { item.image = .tabImageGeneral
item.image = NSImage(
systemSymbolName: "wrench.and.screwdriver.fill", accessibilityDescription: "General Preferences"
)
} else {
item.image = NSImage(named: "PrefToolbar-General")
}
item.action = #selector(showGeneralView(_:)) item.action = #selector(showGeneralView(_:))
case .ofExperience: case .ofExperience:
let title = NSLocalizedString("Experience", comment: "") let title = NSLocalizedString("Experience", comment: "")
item.label = title item.label = title
if #available(macOS 11.0, *) { item.image = .tabImageExperience
item.image = NSImage(
systemSymbolName: "person.fill.questionmark", accessibilityDescription: "Experiences Preferences"
)
} else {
item.image = NSImage(named: "PrefToolbar-Experiences")
}
item.action = #selector(showExperienceView(_:)) item.action = #selector(showExperienceView(_:))
case .ofDictionary: case .ofDictionary:
let title = NSLocalizedString("Dictionary", comment: "") let title = NSLocalizedString("Dictionary", comment: "")
item.label = title item.label = title
if #available(macOS 11.0, *) { item.image = .tabImageDictionary
item.image = NSImage(
systemSymbolName: "character.book.closed.fill", accessibilityDescription: "Dictionary Preferences"
)
} else {
item.image = NSImage(named: "PrefToolbar-Dictionary")
}
item.action = #selector(showDictionaryView(_:)) item.action = #selector(showDictionaryView(_:))
case .ofKeyboard: case .ofKeyboard:
let title = NSLocalizedString("Keyboard", comment: "") let title = NSLocalizedString("Keyboard", comment: "")
item.label = title item.label = title
if #available(macOS 11.0, *) { item.image = .tabImageKeyboard
item.image = NSImage(systemSymbolName: "keyboard.macwindow", accessibilityDescription: "Keyboard Preferences")
} else {
item.image = NSImage(named: "PrefToolbar-Keyboard")
}
item.action = #selector(showKeyboardView(_:)) item.action = #selector(showKeyboardView(_:))
case .ofDevZone: case .ofDevZone:
let title = NSLocalizedString("DevZone", comment: "") let title = NSLocalizedString("DevZone", comment: "")
item.label = title item.label = title
if #available(macOS 11.0, *) { item.image = .tabImageDevZone
item.image = NSImage(
systemSymbolName: "hand.raised.circle", accessibilityDescription: "DevZone Preferences"
)
} else {
item.image = NSImage(named: "PrefToolbar-DevZone")
}
item.action = #selector(showDevZoneView(_:)) item.action = #selector(showDevZoneView(_:))
default: default: