@ -18,50 +18,39 @@ struct PreferencesConstants {
static let hotKeyPathIdentifier = " values.globalPing "
}
class TableHeaderViewCell : NSTableHeaderCell {
var backgroundColour : NSColor = NSColor . black {
didSet {
backgroundColor = backgroundColour
}
}
class PreferencesViewController : ParentViewController {
override init ( textCell : String ) {
super . init ( textCell : textCell )
let attributedParagraphStyle = NSMutableParagraphStyle ( )
attributedParagraphStyle . alignment = . left
attributedStringValue = NSAttributedString ( string : textCell ,
attributes : [ . foregroundColor : Themer . shared ( ) . mainTextColor ( ) ,
. font : NSFont ( name : " Avenir " , size : 14 ) ! ,
. paragraphStyle : attributedParagraphStyle ] )
backgroundColor = Themer . shared ( ) . textBackgroundColor ( )
}
@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 !
required init ( coder _ : NSCoder ) {
fatalError ( " init(coder:) has not been implemented " )
}
@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 !
override func draw ( withFrame cellFrame : NSRect , in controlView : NSView ) {
super . draw ( withFrame : cellFrame , in : controlView )
if ! controlView . isHidden {
backgroundColor ? . setFill ( )
cellFrame . fill ( )
drawInterior ( withFrame : cellFrame , in : controlView )
}
}
@IBOutlet private var searchField : NSSearchField !
@IBOutlet private var messageLabel : NSTextField !
override func drawInterior ( withFrame cellFrame : NSRect , in controlView : NSView ) {
if ! controlView . isHidden {
if let avenirFont = NSFont ( name : " Avenir " , size : 14 ) {
font = avenirFont
}
textColor = NSColor . white
let rect = titleRect ( forBounds : cellFrame )
attributedStringValue . draw ( in : rect )
}
}
}
@IBOutlet private var tableview : NSView !
@IBOutlet private var additionalSortOptions : NSView !
@IBOutlet var startAtLoginLabel : NSTextField !
@IBOutlet var startupCheckbox : NSButton !
// 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
class PreferencesViewController : ParentViewController {
private var isActivityInProgress = false {
didSet {
OperationQueue . main . addOperation {
@ -76,6 +65,11 @@ class PreferencesViewController: ParentViewController {
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 var dataTask : URLSessionDataTask ? = . none
@ -94,43 +88,7 @@ class PreferencesViewController: ParentViewController {
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 ( ) {
super . viewDidLoad ( )
@ -481,22 +439,30 @@ extension PreferencesViewController {
return
}
guard let data = response else {
guard let data = response , let searchResults = data . decode ( ) else {
assertionFailure ( " Data was unexpectedly nil " )
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 . placeholderLabel . placeholderString = self . searchResultsDataSource . timezoneFilteredArray . isEmpty ? " No results! 😔 Try entering the exact name. " : CLEmptyString
self . reloadSearchResults ( )
self . isActivityInProgress = false
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 . prepareUIForPresentingResults ( )
}
@ -522,12 +488,7 @@ extension PreferencesViewController {
}
private func presentError ( _ errorMessage : String ) {
if errorMessage = = PreferencesConstants . offlineErrorMessage {
placeholderLabel . placeholderString = PreferencesConstants . noInternetConnectivityError
} else {
placeholderLabel . placeholderString = PreferencesConstants . tryAgainMessage
}
placeholderLabel . placeholderString = errorMessage = = PreferencesConstants . offlineErrorMessage ? PreferencesConstants . noInternetConnectivityError : PreferencesConstants . tryAgainMessage
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
let timezoneObject = TimezoneData ( with : newTimeZone )
timezoneObject . isSystemTimezone = timezoneObject . timezone ( ) = = NSTimeZone . system . identifier
let operationsObject = TimezoneDataOperations ( with : timezoneObject )
operationsObject . saveObject ( )
@ -670,7 +630,7 @@ extension PreferencesViewController {
return false
}
if let status = unwrapped [ " status " ] as ? String , status = = " ZERO_RESULTS " {
if let status = unwrapped [ " status " ] as ? String , status = = ResultStatus . zeroResults {
setErrorPlaceholders ( )
return true
}