Browse Source

Cleaning up.

pull/92/head
Abhishek Banthia 6 years ago
parent
commit
c752cd5afc
  1. 67
      Clocker/Preferences/General/PreferencesViewController.swift

67
Clocker/Preferences/General/PreferencesViewController.swift

@ -423,33 +423,24 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
}
if let edit = object as? String {
let formattedValue = edit.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines)
if selectedTimeZones.count > row {
Logger.log(object: [
"Old Label": dataObject.customLabel ?? "Error",
"New Label": formattedValue
],
for: "Custom Label Changed")
dataObject.setLabel(formattedValue)
insert(timezone: dataObject, at: row)
updateMenubarTitles()
} else {
Logger.log(object: [
"MethodName": "SetObjectValue",
"Selected Timezone Count": selectedTimeZones.count,
"Current Row": row
],
for: "Error in selected row count")
}
setNewLabel(edit, for: dataObject, at: row)
} else if let isFavouriteValue = object as? NSNumber {
dataObject.isFavourite = isFavouriteValue.intValue
insert(timezone: dataObject, at: row)
dataObject.isFavourite == 1 ?
markAsFavorite(dataObject) :
unfavourite(dataObject)
updateStatusItem()
refreshTimezoneTableView()
}
refreshMainTable()
}
if dataObject.isFavourite == 1, let menubarTitles = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] {
private func markAsFavorite(_ dataObject: TimezoneData) {
guard let menubarTitles = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] else {
return
}
var mutableArray = menubarTitles
let archivedObject = NSKeyedArchiver.archivedData(withRootObject: dataObject)
@ -468,8 +459,9 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
if mutableArray.count > 1 {
showAlertIfMoreThanOneTimezoneHasBeenAddedToTheMenubar()
}
}
} else {
private func unfavourite(_ dataObject: TimezoneData) {
guard let menubarTimers = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data] else {
assertionFailure("Menubar timers is unexpectedly nil")
return
@ -482,7 +474,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
guard let current = NSKeyedUnarchiver.unarchiveObject(with: $0) as? TimezoneData else {
return false
}
return current != dataObject
return current.isEqual(dataObject) == false
}
UserDefaults.standard.set(filteredMenubars, forKey: CLMenubarFavorites)
@ -496,12 +488,29 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
}
}
updateStatusItem()
private func setNewLabel(_ label: String, for dataObject: TimezoneData, at row: Int) {
let formattedValue = label.trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines)
refreshTimezoneTableView()
}
if selectedTimeZones.count > row {
Logger.log(object: [
"Old Label": dataObject.customLabel ?? "Error",
"New Label": formattedValue
],
for: "Custom Label Changed")
refreshMainTable()
dataObject.setLabel(formattedValue)
insert(timezone: dataObject, at: row)
updateMenubarTitles()
} else {
Logger.log(object: [
"MethodName": "SetObjectValue",
"Selected Timezone Count": selectedTimeZones.count,
"Current Row": row
],
for: "Error in selected row count")
}
}
private func showAlertIfMoreThanOneTimezoneHasBeenAddedToTheMenubar() {

Loading…
Cancel
Save