diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 7d7715f..3dfe9cb 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -13,7 +13,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate { } open override func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) { - if let path = keyPath, path == "values.globalPing" { + if let path = keyPath, path == PreferencesConstants.hotKeyPathIdentifier { let hotKeyCenter = PTHotKeyCenter.shared() // Unregister old hot key @@ -213,7 +213,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate { private func assignShortcut() { NSUserDefaultsController.shared.addObserver(self, - forKeyPath: "values.globalPing", + forKeyPath: PreferencesConstants.hotKeyPathIdentifier, options: [.initial, .new], context: nil) } diff --git a/Clocker/Preferences/General/PreferencesDataSource.swift b/Clocker/Preferences/General/PreferencesDataSource.swift index 0df73b7..7f346eb 100644 --- a/Clocker/Preferences/General/PreferencesDataSource.swift +++ b/Clocker/Preferences/General/PreferencesDataSource.swift @@ -2,6 +2,13 @@ import Cocoa +struct PreferencesDataSourceConstants { + static let timezoneNameIdentifier = "formattedAddress" + static let customLabelIdentifier = "label" + static let availableTimezoneIdentifier = "availableTimezones" + static let favoriteTimezoneIdentifier = "favouriteTimezone" +} + protocol PreferenceSelectionUpdates: AnyObject { func markAsFavorite(_ dataObject: TimezoneData) func unfavourite(_ dataObject: TimezoneData) @@ -99,15 +106,15 @@ extension PreferencesDataSource: NSTableViewDataSource { selectedDataSource = model } - if tableColumn?.identifier.rawValue == PreferencesConstants.timezoneNameIdentifier { + if tableColumn?.identifier.rawValue == PreferencesDataSourceConstants.timezoneNameIdentifier { return handleTimezoneNameIdentifier(selectedDataSource) } - if tableColumn?.identifier.rawValue == PreferencesConstants.customLabelIdentifier { + if tableColumn?.identifier.rawValue == PreferencesDataSourceConstants.customLabelIdentifier { return selectedDataSource?.customLabel ?? "Error" } - if tableColumn?.identifier.rawValue == "favouriteTimezone" { + if tableColumn?.identifier.rawValue == PreferencesDataSourceConstants.favoriteTimezoneIdentifier { return selectedDataSource?.isFavourite ?? 0 } diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index 2713567..cef71ef 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -3,15 +3,13 @@ import Cocoa struct PreferencesConstants { - static let timezoneNameIdentifier = "formattedAddress" - static let customLabelIdentifier = "label" - static let availableTimezoneIdentifier = "availableTimezones" static let noTimezoneSelectedErrorMessage = "Please select a timezone!" static let maxTimezonesErrorMessage = "Maximum 100 timezones allowed!" static let maxCharactersAllowed = "Only 50 characters allowed!" static let noInternetConnectivityError = "You're offline, maybe?" static let tryAgainMessage = "Try again, maybe?" static let offlineErrorMessage = "The Internet connection appears to be offline." + static let hotKeyPathIdentifier = "values.globalPing" } enum RowType { @@ -299,14 +297,14 @@ class PreferencesViewController: ParentViewController { recorderControl.bind(NSBindingName.value, to: defaults, - withKeyPath: "values.globalPing", + withKeyPath: PreferencesConstants.hotKeyPathIdentifier, options: nil) recorderControl.delegate = self } override func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) { - if let path = keyPath, path == "values.globalPing" { + if let path = keyPath, path == PreferencesConstants.hotKeyPathIdentifier { let hotKeyCenter = PTHotKeyCenter.shared() let oldHotKey = hotKeyCenter?.hotKey(withIdentifier: path) hotKeyCenter?.unregisterHotKey(oldHotKey) @@ -367,13 +365,11 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate } func tableView(_: NSTableView, shouldSelectRow row: Int) -> Bool { - print("Should Select Row") let currentRowType = finalArray[row] return !(currentRowType == .timezoneHeader || currentRowType == .cityHeader) } func tableView(_: NSTableView, selectionIndexesForProposedSelection proposedSelectionIndexes: IndexSet) -> IndexSet { -// print("Selection Indexes for Proposed Selection: \(proposedSelectionIndexes.first!)") return proposedSelectionIndexes }