diff --git a/phpmon/Common/Helpers/MenuBarImageGenerator.swift b/phpmon/Common/Helpers/MenuBarImageGenerator.swift index f699c42..744d62a 100644 --- a/phpmon/Common/Helpers/MenuBarImageGenerator.swift +++ b/phpmon/Common/Helpers/MenuBarImageGenerator.swift @@ -75,7 +75,7 @@ class MenuBarImageGenerator { // Then we'll fetch the image we want on the left var iconType = Preferences.preferences[.iconTypeToDisplay] as? String - if iconType == nil { + if iconType == nil || !MenuBarIcon.allCases.map({ $0.rawValue }).contains(iconType) { Log.warn("Invalid icon type found, using the default") iconType = MenuBarIcon.iconPhp.rawValue } diff --git a/phpmon/Domain/Preferences/PreferencesVC.swift b/phpmon/Domain/Preferences/PreferencesVC.swift index 74129d1..bb47051 100644 --- a/phpmon/Domain/Preferences/PreferencesVC.swift +++ b/phpmon/Domain/Preferences/PreferencesVC.swift @@ -49,12 +49,20 @@ class GenericPreferenceVC: NSViewController { } func getLanguageOptionsPV() -> NSView { + var options = Bundle.main.localizations + .filter({ $0 != "Base"}) + .map({ lang in + return PreferenceDropdownOption( + label: Locale.current.localizedString(forLanguageCode: lang)!, + value: lang + ) + }) + options.insert(PreferenceDropdownOption(label: "System Default", value: ""), at: 0) + return SelectPreferenceView.make( - sectionText: "", + sectionText: "prefs.language".localized, descriptionText: "prefs.language_options_desc".localized, - options: Bundle.main.localizations - .filter({ $0 != "Base"}), - localizationPrefix: "lang", + options: options, preference: .languageOverride, action: { MainMenu.shared.refreshIcon() @@ -66,7 +74,8 @@ class GenericPreferenceVC: NSViewController { return SelectPreferenceView.make( sectionText: "", descriptionText: "prefs.icon_options_desc".localized, - options: MenuBarIcon.allCases.map({ return $0.rawValue }), + options: MenuBarIcon.allCases + .map({ return PreferenceDropdownOption(label: $0.rawValue, value: $0.rawValue) }), localizationPrefix: "prefs.icon_options", preference: .iconTypeToDisplay, action: { diff --git a/phpmon/Domain/Preferences/PreferencesWindowController.swift b/phpmon/Domain/Preferences/PreferencesWindowController.swift index 501bd02..c925cab 100644 --- a/phpmon/Domain/Preferences/PreferencesWindowController.swift +++ b/phpmon/Domain/Preferences/PreferencesWindowController.swift @@ -68,6 +68,8 @@ class PreferencesWindowController: PMWindowController { App.shared.preferencesWindowController?.positionWindowInTopRightCorner() } + App.shared.preferencesWindowController?.window?.orderFrontRegardless() + NSApp.activate(ignoringOtherApps: true) } diff --git a/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.xib b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.xib index 42fd99a..8350fc7 100644 --- a/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.xib +++ b/phpmon/Domain/Preferences/Views/CheckboxPreferenceView.xib @@ -1,8 +1,8 @@ - + - + @@ -23,7 +23,7 @@ - + @@ -31,7 +31,7 @@ - + diff --git a/phpmon/Domain/Preferences/Views/SelectPreferenceView.swift b/phpmon/Domain/Preferences/Views/SelectPreferenceView.swift index cc6f392..e1dbbe9 100644 --- a/phpmon/Domain/Preferences/Views/SelectPreferenceView.swift +++ b/phpmon/Domain/Preferences/Views/SelectPreferenceView.swift @@ -9,30 +9,34 @@ import Foundation import Cocoa -class SelectPreferenceView: NSView, XibLoadable { +struct PreferenceDropdownOption { + let label: String + let value: String +} +class SelectPreferenceView: NSView, XibLoadable { @IBOutlet weak var labelSection: NSTextField! @IBOutlet weak var labelDescription: NSTextField! @IBOutlet weak var popupButton: NSPopUpButton! - var localizationPrefix: String = "" + var localizationPrefix: String? var imagePrefix: String? - var options: [String] = [] { + var options: [PreferenceDropdownOption] = [] { didSet { self.popupButton.removeAllItems() - self.options.forEach { value in - self.popupButton.addItem( - withTitle: "\(localizationPrefix).\(value)".localized - ) + self.options.forEach { option in + if let prefix = localizationPrefix { + self.popupButton.addItem(withTitle: "\(prefix).\(option.label)".localized) + } else { + self.popupButton.addItem(withTitle: option.label) + } } - if imagePrefix == nil { - return - } - - self.popupButton.itemArray.enumerated().forEach { item in - item.element.image = NSImage(named: "\(imagePrefix!)_\(self.options[item.offset])") + if let prefix = imagePrefix { + self.popupButton.itemArray.enumerated().forEach { item in + item.element.image = NSImage(named: "\(prefix)_\(self.options[item.offset].value)") + } } } } @@ -43,19 +47,18 @@ class SelectPreferenceView: NSView, XibLoadable { didSet { let value = Preferences.preferences[preference] as! String self.options.enumerated().forEach { option in - if option.element == value { + if option.element.value == value { self.popupButton.selectItem(at: option.offset) } } } } - // swiftlint:disable function_parameter_count static func make( sectionText: String, descriptionText: String, - options: [String], - localizationPrefix: String, + options: [PreferenceDropdownOption], + localizationPrefix: String? = nil, imagePrefix: String? = nil, preference: PreferenceName, action: @escaping () -> Void) -> NSView { @@ -72,11 +75,10 @@ class SelectPreferenceView: NSView, XibLoadable { return view } - // swiftlint:enable function_parameter_count @IBAction func valueChanged(_ sender: Any) { let index = self.popupButton.indexOfSelectedItem - Preferences.update(self.preference, value: self.options[index]) + Preferences.update(self.preference, value: self.options[index].value) self.action() } diff --git a/phpmon/Domain/Preferences/Views/SelectPreferenceView.xib b/phpmon/Domain/Preferences/Views/SelectPreferenceView.xib index 4871c5f..74ffa91 100644 --- a/phpmon/Domain/Preferences/Views/SelectPreferenceView.xib +++ b/phpmon/Domain/Preferences/Views/SelectPreferenceView.xib @@ -1,8 +1,8 @@ - + - + @@ -13,16 +13,16 @@ - - + + - - + + @@ -33,7 +33,7 @@ - + @@ -58,7 +58,7 @@ - + diff --git a/phpmon/en.lproj/Localizable.strings b/phpmon/en.lproj/Localizable.strings index 311ae3c..76d1d57 100644 --- a/phpmon/en.lproj/Localizable.strings +++ b/phpmon/en.lproj/Localizable.strings @@ -378,6 +378,7 @@ This has no effect on other terminals, only for the particular terminal session "prefs.tabs.visibility" = "Visibility"; "prefs.tabs.notifications" = "Notifications"; +"prefs.language" = "Language:"; "prefs.global_shortcut" = "Global Shortcut:"; "prefs.dynamic_icon" = "Dynamic Icon:"; "prefs.dynamic_icon" = "Icon Type:"; @@ -392,6 +393,8 @@ This has no effect on other terminals, only for the particular terminal session "prefs.menu_contents" = "Features in Menu:"; "prefs.startup" = "Startup:"; +"prefs.language_options_desc" = "Choose a different language to use with PHP Monitor."; + "prefs.auto_start_desc" = "Automatically starts PHP Monitor when you log into your Mac."; "prefs.auto_start_title" = "Start PHP Monitor at login";