Browse Source

Consolidating constants.

pull/92/head
Abhishek 5 years ago
parent
commit
bab3e418d2
  1. 4
      Clocker/AppDelegate.swift
  2. 13
      Clocker/Preferences/General/PreferencesDataSource.swift
  3. 10
      Clocker/Preferences/General/PreferencesViewController.swift

4
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?) { 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() let hotKeyCenter = PTHotKeyCenter.shared()
// Unregister old hot key // Unregister old hot key
@ -213,7 +213,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
private func assignShortcut() { private func assignShortcut() {
NSUserDefaultsController.shared.addObserver(self, NSUserDefaultsController.shared.addObserver(self,
forKeyPath: "values.globalPing", forKeyPath: PreferencesConstants.hotKeyPathIdentifier,
options: [.initial, .new], options: [.initial, .new],
context: nil) context: nil)
} }

13
Clocker/Preferences/General/PreferencesDataSource.swift

@ -2,6 +2,13 @@
import Cocoa import Cocoa
struct PreferencesDataSourceConstants {
static let timezoneNameIdentifier = "formattedAddress"
static let customLabelIdentifier = "label"
static let availableTimezoneIdentifier = "availableTimezones"
static let favoriteTimezoneIdentifier = "favouriteTimezone"
}
protocol PreferenceSelectionUpdates: AnyObject { protocol PreferenceSelectionUpdates: AnyObject {
func markAsFavorite(_ dataObject: TimezoneData) func markAsFavorite(_ dataObject: TimezoneData)
func unfavourite(_ dataObject: TimezoneData) func unfavourite(_ dataObject: TimezoneData)
@ -99,15 +106,15 @@ extension PreferencesDataSource: NSTableViewDataSource {
selectedDataSource = model selectedDataSource = model
} }
if tableColumn?.identifier.rawValue == PreferencesConstants.timezoneNameIdentifier { if tableColumn?.identifier.rawValue == PreferencesDataSourceConstants.timezoneNameIdentifier {
return handleTimezoneNameIdentifier(selectedDataSource) return handleTimezoneNameIdentifier(selectedDataSource)
} }
if tableColumn?.identifier.rawValue == PreferencesConstants.customLabelIdentifier { if tableColumn?.identifier.rawValue == PreferencesDataSourceConstants.customLabelIdentifier {
return selectedDataSource?.customLabel ?? "Error" return selectedDataSource?.customLabel ?? "Error"
} }
if tableColumn?.identifier.rawValue == "favouriteTimezone" { if tableColumn?.identifier.rawValue == PreferencesDataSourceConstants.favoriteTimezoneIdentifier {
return selectedDataSource?.isFavourite ?? 0 return selectedDataSource?.isFavourite ?? 0
} }

10
Clocker/Preferences/General/PreferencesViewController.swift

@ -3,15 +3,13 @@
import Cocoa import Cocoa
struct PreferencesConstants { struct PreferencesConstants {
static let timezoneNameIdentifier = "formattedAddress"
static let customLabelIdentifier = "label"
static let availableTimezoneIdentifier = "availableTimezones"
static let noTimezoneSelectedErrorMessage = "Please select a timezone!" static let noTimezoneSelectedErrorMessage = "Please select a timezone!"
static let maxTimezonesErrorMessage = "Maximum 100 timezones allowed!" static let maxTimezonesErrorMessage = "Maximum 100 timezones allowed!"
static let maxCharactersAllowed = "Only 50 characters allowed!" static let maxCharactersAllowed = "Only 50 characters allowed!"
static let noInternetConnectivityError = "You're offline, maybe?" static let noInternetConnectivityError = "You're offline, maybe?"
static let tryAgainMessage = "Try again, maybe?" static let tryAgainMessage = "Try again, maybe?"
static let offlineErrorMessage = "The Internet connection appears to be offline." static let offlineErrorMessage = "The Internet connection appears to be offline."
static let hotKeyPathIdentifier = "values.globalPing"
} }
enum RowType { enum RowType {
@ -299,14 +297,14 @@ class PreferencesViewController: ParentViewController {
recorderControl.bind(NSBindingName.value, recorderControl.bind(NSBindingName.value,
to: defaults, to: defaults,
withKeyPath: "values.globalPing", withKeyPath: PreferencesConstants.hotKeyPathIdentifier,
options: nil) options: nil)
recorderControl.delegate = self recorderControl.delegate = self
} }
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context _: UnsafeMutableRawPointer?) { 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 hotKeyCenter = PTHotKeyCenter.shared()
let oldHotKey = hotKeyCenter?.hotKey(withIdentifier: path) let oldHotKey = hotKeyCenter?.hotKey(withIdentifier: path)
hotKeyCenter?.unregisterHotKey(oldHotKey) hotKeyCenter?.unregisterHotKey(oldHotKey)
@ -367,13 +365,11 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
} }
func tableView(_: NSTableView, shouldSelectRow row: Int) -> Bool { func tableView(_: NSTableView, shouldSelectRow row: Int) -> Bool {
print("Should Select Row")
let currentRowType = finalArray[row] let currentRowType = finalArray[row]
return !(currentRowType == .timezoneHeader || currentRowType == .cityHeader) return !(currentRowType == .timezoneHeader || currentRowType == .cityHeader)
} }
func tableView(_: NSTableView, selectionIndexesForProposedSelection proposedSelectionIndexes: IndexSet) -> IndexSet { func tableView(_: NSTableView, selectionIndexesForProposedSelection proposedSelectionIndexes: IndexSet) -> IndexSet {
// print("Selection Indexes for Proposed Selection: \(proposedSelectionIndexes.first!)")
return proposedSelectionIndexes return proposedSelectionIndexes
} }

Loading…
Cancel
Save