@ -18,50 +18,39 @@ struct PreferencesConstants {
static let hotKeyPathIdentifier = " values.globalPing "
static let hotKeyPathIdentifier = " values.globalPing "
}
}
class TableHeaderViewCell : NSTableHeaderCell {
class PreferencesViewController : ParentViewController {
var backgroundColour : NSColor = NSColor . black {
didSet {
backgroundColor = backgroundColour
}
}
override init ( textCell : String ) {
@IBOutlet private var placeholderLabel : NSTextField !
super . init ( textCell : textCell )
@IBOutlet private var timezoneTableView : NSTableView !
let attributedParagraphStyle = NSMutableParagraphStyle ( )
@IBOutlet private var availableTimezoneTableView : NSTableView !
attributedParagraphStyle . alignment = . left
@IBOutlet private var timezonePanel : Panelr !
attributedStringValue = NSAttributedString ( string : textCell ,
@IBOutlet private var progressIndicator : NSProgressIndicator !
attributes : [ . foregroundColor : Themer . shared ( ) . mainTextColor ( ) ,
@IBOutlet private var addButton : NSButton !
. font : NSFont ( name : " Avenir " , size : 14 ) ! ,
@IBOutlet private var recorderControl : SRRecorderControl !
. paragraphStyle : attributedParagraphStyle ] )
@IBOutlet private var closeButton : NSButton !
backgroundColor = Themer . shared ( ) . textBackgroundColor ( )
}
required init ( coder _ : NSCoder ) {
@IBOutlet private var timezoneSortButton : NSButton !
fatalError ( " init(coder:) has not been implemented " )
@IBOutlet private var timezoneNameSortButton : NSButton !
}
@IBOutlet private var labelSortButton : NSButton !
@IBOutlet private var deleteButton : NSButton !
@IBOutlet private var addTimezoneButton : NSButton !
override func draw ( withFrame cellFrame : NSRect , in controlView : NSView ) {
@IBOutlet private var searchField : NSSearchField !
super . draw ( withFrame : cellFrame , in : controlView )
@IBOutlet private var messageLabel : NSTextField !
if ! controlView . isHidden {
backgroundColor ? . setFill ( )
cellFrame . fill ( )
drawInterior ( withFrame : cellFrame , in : controlView )
}
}
override func drawInterior ( withFrame cellFrame : NSRect , in controlView : NSView ) {
@IBOutlet private var tableview : NSView !
if ! controlView . isHidden {
@IBOutlet private var additionalSortOptions : NSView !
if let avenirFont = NSFont ( name : " Avenir " , size : 14 ) {
@IBOutlet var startAtLoginLabel : NSTextField !
font = avenirFont
}
@IBOutlet var startupCheckbox : NSButton !
textColor = NSColor . white
let rect = titleRect ( forBounds : cellFrame )
// S o r t i n g
attributedStringValue . draw ( in : rect )
private var arePlacesSortedInAscendingOrder = false
}
private var arePlacesSortedInAscendingTimezoneOrder = false
}
private var isTimezoneSortOptionSelected = false
}
private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
class PreferencesViewController : ParentViewController {
private var isActivityInProgress = false {
private var isActivityInProgress = false {
didSet {
didSet {
OperationQueue . main . addOperation {
OperationQueue . main . addOperation {
@ -76,6 +65,11 @@ class PreferencesViewController: ParentViewController {
return DataStore . shared ( ) . timezones ( )
return DataStore . shared ( ) . timezones ( )
}
}
private var themeDidChangeNotification : NSObjectProtocol ?
// S e l e c t e d T i m e z o n e s D a t a S o u r c e
private var selectionsDataSource : PreferencesDataSource !
// S e a r c h R e s u l t s D a t a S o u r c e H a n d l e r
private var searchResultsDataSource : SearchDataSource !
private lazy var startupManager = StartupManager ( )
private lazy var startupManager = StartupManager ( )
private var dataTask : URLSessionDataTask ? = . none
private var dataTask : URLSessionDataTask ? = . none
@ -94,43 +88,7 @@ class PreferencesViewController: ParentViewController {
return apiKey
return apiKey
} ( )
} ( )
// S o r t i n g
private var arePlacesSortedInAscendingOrder = false
private var arePlacesSortedInAscendingTimezoneOrder = false
private var isTimezoneSortOptionSelected = false
private var isTimezoneNameSortOptionSelected = false
private var isLabelOptionSelected = false
@IBOutlet private var placeholderLabel : NSTextField !
@IBOutlet private var timezoneTableView : NSTableView !
@IBOutlet private var availableTimezoneTableView : NSTableView !
@IBOutlet private var timezonePanel : Panelr !
@IBOutlet private var progressIndicator : NSProgressIndicator !
@IBOutlet private var addButton : NSButton !
@IBOutlet private var recorderControl : SRRecorderControl !
@IBOutlet private var closeButton : NSButton !
@IBOutlet private var timezoneSortButton : NSButton !
@IBOutlet private var timezoneNameSortButton : NSButton !
@IBOutlet private var labelSortButton : NSButton !
@IBOutlet private var deleteButton : NSButton !
@IBOutlet private var addTimezoneButton : NSButton !
@IBOutlet private var searchField : NSSearchField !
@IBOutlet private var messageLabel : NSTextField !
@IBOutlet private var tableview : NSView !
@IBOutlet private var additionalSortOptions : NSView !
@IBOutlet var startAtLoginLabel : NSTextField !
@IBOutlet var startupCheckbox : NSButton !
private var themeDidChangeNotification : NSObjectProtocol ?
// S e l e c t e d T i m e z o n e s D a t a S o u r c e
private var selectionsDataSource : PreferencesDataSource !
// S e a r c h R e s u l t s D a t a S o u r c e H a n d l e r
private var searchResultsDataSource : SearchDataSource !
override func viewDidLoad ( ) {
override func viewDidLoad ( ) {
super . viewDidLoad ( )
super . viewDidLoad ( )
@ -481,22 +439,30 @@ extension PreferencesViewController {
return
return
}
}
guard let data = response else {
guard let data = response , let searchResults = data . decode ( ) else {
assertionFailure ( " Data was unexpectedly nil " )
assertionFailure ( " Data was unexpectedly nil " )
return
return
}
}
let searchResults = data . decode ( )
// l e t s e a r c h R e s u l t s = d a t a . d e c o d e ( )
if searchResults ? . status = = " ZERO_RESULTS " {
if searchResults . status = = ResultStatus . zeroResults {
Logger . info ( " Zero Results returned " )
self . findLocalSearchResultsForTimezones ( )
self . findLocalSearchResultsForTimezones ( )
self . placeholderLabel . placeholderString = self . searchResultsDataSource . timezoneFilteredArray . isEmpty ? " No results! 😔 Try entering the exact name. " : CLEmptyString
self . placeholderLabel . placeholderString = self . searchResultsDataSource . timezoneFilteredArray . isEmpty ? " No results! 😔 Try entering the exact name. " : CLEmptyString
self . reloadSearchResults ( )
self . reloadSearchResults ( )
self . isActivityInProgress = false
self . isActivityInProgress = false
return
return
} else if searchResults . status = = ResultStatus . requestDenied && searchResults . results . isEmpty {
Logger . info ( " Request denied! " )
self . findLocalSearchResultsForTimezones ( )
self . placeholderLabel . placeholderString = self . searchResultsDataSource . timezoneFilteredArray . isEmpty ? " Update Clocker to get a faster experience 😃 " : CLEmptyString
self . reloadSearchResults ( )
self . isActivityInProgress = false
return
}
}
self . appendResultsToFilteredArray ( searchResults ! . results )
self . appendResultsToFilteredArray ( searchResults . results )
self . findLocalSearchResultsForTimezones ( )
self . findLocalSearchResultsForTimezones ( )
self . prepareUIForPresentingResults ( )
self . prepareUIForPresentingResults ( )
}
}
@ -522,12 +488,7 @@ extension PreferencesViewController {
}
}
private func presentError ( _ errorMessage : String ) {
private func presentError ( _ errorMessage : String ) {
if errorMessage = = PreferencesConstants . offlineErrorMessage {
placeholderLabel . placeholderString = errorMessage = = PreferencesConstants . offlineErrorMessage ? PreferencesConstants . noInternetConnectivityError : PreferencesConstants . tryAgainMessage
placeholderLabel . placeholderString = PreferencesConstants . noInternetConnectivityError
} else {
placeholderLabel . placeholderString = PreferencesConstants . tryAgainMessage
}
isActivityInProgress = false
isActivityInProgress = false
}
}
@ -642,7 +603,6 @@ extension PreferencesViewController {
// M a r k i f t h e t i m e z o n e i s s a m e a s l o c a l t i m e z o n e
// M a r k i f t h e t i m e z o n e i s s a m e a s l o c a l t i m e z o n e
let timezoneObject = TimezoneData ( with : newTimeZone )
let timezoneObject = TimezoneData ( with : newTimeZone )
timezoneObject . isSystemTimezone = timezoneObject . timezone ( ) = = NSTimeZone . system . identifier
let operationsObject = TimezoneDataOperations ( with : timezoneObject )
let operationsObject = TimezoneDataOperations ( with : timezoneObject )
operationsObject . saveObject ( )
operationsObject . saveObject ( )
@ -670,7 +630,7 @@ extension PreferencesViewController {
return false
return false
}
}
if let status = unwrapped [ " status " ] as ? String , status = = " ZERO_RESULTS " {
if let status = unwrapped [ " status " ] as ? String , status = = ResultStatus . zeroResults {
setErrorPlaceholders ( )
setErrorPlaceholders ( )
return true
return true
}
}