Browse Source

Better naming.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
f3e08e46d3
  1. 26
      Clocker/Preferences/General/PreferencesDataSource.swift
  2. 23
      Clocker/Preferences/General/PreferencesViewController.swift
  3. 1
      Clocker/Preferences/Menu Bar/StatusItemHandler.swift

26
Clocker/Preferences/General/PreferencesDataSource.swift

@ -12,12 +12,12 @@ struct PreferencesDataSourceConstants {
} }
protocol PreferenceSelectionUpdates: AnyObject { protocol PreferenceSelectionUpdates: AnyObject {
func markAsFavorite(_ dataObject: TimezoneData) func preferenceSelectionDataSourceMarkAsFavorite(_ dataObject: TimezoneData)
func unfavourite(_ dataObject: TimezoneData) func preferenceSelectionDataSourceUnfavourite(_ dataObject: TimezoneData)
func refreshTimezoneTable() func preferenceSelectionDataSourceRefreshTimezoneTable()
func refreshMainTableView() func preferenceSelectionDataSourceRefreshMainTableView()
func tableViewSelectionDidChange(_ status: Bool) func preferenceSelectionDataSourceTableViewSelectionDidChange(_ status: Bool)
func table(didClick tableColumn: NSTableColumn) func preferenceSelectionDataSourceTable(didClick tableColumn: NSTableColumn)
} }
class PreferencesDataSource: NSObject { class PreferencesDataSource: NSObject {
@ -35,7 +35,7 @@ class PreferencesDataSource: NSObject {
extension PreferencesDataSource: NSTableViewDelegate { extension PreferencesDataSource: NSTableViewDelegate {
func tableViewSelectionDidChange(_ notification: Notification) { func tableViewSelectionDidChange(_ notification: Notification) {
if let tableView = notification.object as? NSTableView { if let tableView = notification.object as? NSTableView {
updateDelegate?.tableViewSelectionDidChange(tableView.selectedRow == -1) updateDelegate?.preferenceSelectionDataSourceTableViewSelectionDidChange(tableView.selectedRow == -1)
} }
} }
@ -79,7 +79,7 @@ extension PreferencesDataSource: NSTableViewDelegate {
tableView.reloadData() tableView.reloadData()
updateDelegate?.refreshMainTableView() updateDelegate?.preferenceSelectionDataSourceRefreshMainTableView()
tableView.deselectRow(tableView.selectedRow) tableView.deselectRow(tableView.selectedRow)
@ -91,7 +91,7 @@ extension PreferencesDataSource: NSTableViewDelegate {
} }
func tableView(_: NSTableView, didClick tableColumn: NSTableColumn) { func tableView(_: NSTableView, didClick tableColumn: NSTableColumn) {
updateDelegate?.table(didClick: tableColumn) updateDelegate?.preferenceSelectionDataSourceTable(didClick: tableColumn)
} }
} }
@ -146,13 +146,13 @@ extension PreferencesDataSource: NSTableViewDataSource {
dataObject.isFavourite = isFavouriteValue.intValue dataObject.isFavourite = isFavouriteValue.intValue
insert(timezone: dataObject, at: row) insert(timezone: dataObject, at: row)
dataObject.isFavourite == 1 ? dataObject.isFavourite == 1 ?
updateDelegate?.markAsFavorite(dataObject) : updateDelegate?.preferenceSelectionDataSourceMarkAsFavorite(dataObject) :
updateDelegate?.unfavourite(dataObject) updateDelegate?.preferenceSelectionDataSourceUnfavourite(dataObject)
updateStatusItem() updateStatusItem()
updateDelegate?.refreshTimezoneTable() updateDelegate?.preferenceSelectionDataSourceRefreshTimezoneTable()
} }
updateDelegate?.refreshMainTableView() updateDelegate?.preferenceSelectionDataSourceRefreshMainTableView()
} }
private func setNewLabel(_ label: String, for dataObject: TimezoneData, at row: Int) { private func setNewLabel(_ label: String, for dataObject: TimezoneData, at row: Int) {

23
Clocker/Preferences/General/PreferencesViewController.swift

@ -98,6 +98,14 @@ class PreferencesViewController: ParentViewController {
name: NSNotification.Name.customLabelChanged, name: NSNotification.Name.customLabelChanged,
object: nil) object: nil)
NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification,
object: self,
queue: OperationQueue.main) { [weak self] _ in
if let sSelf = self {
sSelf.refreshTimezoneTableView()
}
}
refreshTimezoneTableView() refreshTimezoneTableView()
setup() setup()
@ -483,8 +491,7 @@ extension PreferencesViewController {
let words = searchString.components(separatedBy: CharacterSet.whitespacesAndNewlines) let words = searchString.components(separatedBy: CharacterSet.whitespacesAndNewlines)
searchString = words.joined(separator: CLEmptyString) searchString = words.joined(separator: CLEmptyString)
let url = "https://maps.googleapis.com/maps/api/geocode/json?address=\(searchString)&key=\(geocodingKey)&language=\(userPreferredLanguage)" return "https://maps.googleapis.com/maps/api/geocode/json?address=\(searchString)&key=\(geocodingKey)&language=\(userPreferredLanguage)"
return url
} }
private func presentError(_ errorMessage: String) { private func presentError(_ errorMessage: String) {
@ -977,27 +984,27 @@ extension PreferencesViewController {
} }
extension PreferencesViewController: PreferenceSelectionUpdates { extension PreferencesViewController: PreferenceSelectionUpdates {
func markAsFavorite(_ dataObject: TimezoneData) { func preferenceSelectionDataSourceMarkAsFavorite(_ dataObject: TimezoneData) {
_markAsFavorite(dataObject) _markAsFavorite(dataObject)
} }
func unfavourite(_ dataObject: TimezoneData) { func preferenceSelectionDataSourceUnfavourite(_ dataObject: TimezoneData) {
_unfavourite(dataObject) _unfavourite(dataObject)
} }
func refreshTimezoneTable() { func preferenceSelectionDataSourceRefreshTimezoneTable() {
refreshTimezoneTableView() refreshTimezoneTableView()
} }
func refreshMainTableView() { func preferenceSelectionDataSourceRefreshMainTableView() {
refreshMainTable() refreshMainTable()
} }
func tableViewSelectionDidChange(_ status: Bool) { func preferenceSelectionDataSourceTableViewSelectionDidChange(_ status: Bool) {
deleteButton.isEnabled = !status deleteButton.isEnabled = !status
} }
func table(didClick tableColumn: NSTableColumn) { func preferenceSelectionDataSourceTable(didClick tableColumn: NSTableColumn) {
if tableColumn.identifier.rawValue == "favouriteTimezone" { if tableColumn.identifier.rawValue == "favouriteTimezone" {
return return
} }

1
Clocker/Preferences/Menu Bar/StatusItemHandler.swift

@ -138,7 +138,6 @@ class StatusItemHandler: NSObject {
parentView = nil parentView = nil
let menubarTimezones = DataStore.shared().menubarTimezones() ?? [] let menubarTimezones = DataStore.shared().menubarTimezones() ?? []
if menubarTimezones.isEmpty { if menubarTimezones.isEmpty {
currentState = .icon currentState = .icon
return return

Loading…
Cancel
Save