From f3e08e46d3704c9d24057dc6d9c0326ee0eb6f93 Mon Sep 17 00:00:00 2001 From: Abhishek Banthia <8280282+n0shake@users.noreply.github.com> Date: Sat, 19 Mar 2022 20:47:37 -0400 Subject: [PATCH] Better naming. --- .../General/PreferencesDataSource.swift | 26 +++++++++---------- .../General/PreferencesViewController.swift | 23 ++++++++++------ .../Menu Bar/StatusItemHandler.swift | 1 - 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/Clocker/Preferences/General/PreferencesDataSource.swift b/Clocker/Preferences/General/PreferencesDataSource.swift index ac702fe..27527ba 100644 --- a/Clocker/Preferences/General/PreferencesDataSource.swift +++ b/Clocker/Preferences/General/PreferencesDataSource.swift @@ -12,12 +12,12 @@ struct PreferencesDataSourceConstants { } protocol PreferenceSelectionUpdates: AnyObject { - func markAsFavorite(_ dataObject: TimezoneData) - func unfavourite(_ dataObject: TimezoneData) - func refreshTimezoneTable() - func refreshMainTableView() - func tableViewSelectionDidChange(_ status: Bool) - func table(didClick tableColumn: NSTableColumn) + func preferenceSelectionDataSourceMarkAsFavorite(_ dataObject: TimezoneData) + func preferenceSelectionDataSourceUnfavourite(_ dataObject: TimezoneData) + func preferenceSelectionDataSourceRefreshTimezoneTable() + func preferenceSelectionDataSourceRefreshMainTableView() + func preferenceSelectionDataSourceTableViewSelectionDidChange(_ status: Bool) + func preferenceSelectionDataSourceTable(didClick tableColumn: NSTableColumn) } class PreferencesDataSource: NSObject { @@ -35,7 +35,7 @@ class PreferencesDataSource: NSObject { extension PreferencesDataSource: NSTableViewDelegate { func tableViewSelectionDidChange(_ notification: Notification) { 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() - updateDelegate?.refreshMainTableView() + updateDelegate?.preferenceSelectionDataSourceRefreshMainTableView() tableView.deselectRow(tableView.selectedRow) @@ -91,7 +91,7 @@ extension PreferencesDataSource: NSTableViewDelegate { } 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 insert(timezone: dataObject, at: row) dataObject.isFavourite == 1 ? - updateDelegate?.markAsFavorite(dataObject) : - updateDelegate?.unfavourite(dataObject) + updateDelegate?.preferenceSelectionDataSourceMarkAsFavorite(dataObject) : + updateDelegate?.preferenceSelectionDataSourceUnfavourite(dataObject) updateStatusItem() - updateDelegate?.refreshTimezoneTable() + updateDelegate?.preferenceSelectionDataSourceRefreshTimezoneTable() } - updateDelegate?.refreshMainTableView() + updateDelegate?.preferenceSelectionDataSourceRefreshMainTableView() } private func setNewLabel(_ label: String, for dataObject: TimezoneData, at row: Int) { diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index 422c407..e2a30a0 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -97,6 +97,14 @@ class PreferencesViewController: ParentViewController { selector: #selector(refreshTimezoneTableView), name: NSNotification.Name.customLabelChanged, object: nil) + + NotificationCenter.default.addObserver(forName: NSUbiquitousKeyValueStore.didChangeExternallyNotification, + object: self, + queue: OperationQueue.main) { [weak self] _ in + if let sSelf = self { + sSelf.refreshTimezoneTableView() + } + } refreshTimezoneTableView() @@ -483,8 +491,7 @@ extension PreferencesViewController { let words = searchString.components(separatedBy: CharacterSet.whitespacesAndNewlines) searchString = words.joined(separator: CLEmptyString) - let url = "https://maps.googleapis.com/maps/api/geocode/json?address=\(searchString)&key=\(geocodingKey)&language=\(userPreferredLanguage)" - return url + return "https://maps.googleapis.com/maps/api/geocode/json?address=\(searchString)&key=\(geocodingKey)&language=\(userPreferredLanguage)" } private func presentError(_ errorMessage: String) { @@ -977,27 +984,27 @@ extension PreferencesViewController { } extension PreferencesViewController: PreferenceSelectionUpdates { - func markAsFavorite(_ dataObject: TimezoneData) { + func preferenceSelectionDataSourceMarkAsFavorite(_ dataObject: TimezoneData) { _markAsFavorite(dataObject) } - func unfavourite(_ dataObject: TimezoneData) { + func preferenceSelectionDataSourceUnfavourite(_ dataObject: TimezoneData) { _unfavourite(dataObject) } - func refreshTimezoneTable() { + func preferenceSelectionDataSourceRefreshTimezoneTable() { refreshTimezoneTableView() } - func refreshMainTableView() { + func preferenceSelectionDataSourceRefreshMainTableView() { refreshMainTable() } - func tableViewSelectionDidChange(_ status: Bool) { + func preferenceSelectionDataSourceTableViewSelectionDidChange(_ status: Bool) { deleteButton.isEnabled = !status } - func table(didClick tableColumn: NSTableColumn) { + func preferenceSelectionDataSourceTable(didClick tableColumn: NSTableColumn) { if tableColumn.identifier.rawValue == "favouriteTimezone" { return } diff --git a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift index b26ba91..dcdcc70 100644 --- a/Clocker/Preferences/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Preferences/Menu Bar/StatusItemHandler.swift @@ -138,7 +138,6 @@ class StatusItemHandler: NSObject { parentView = nil let menubarTimezones = DataStore.shared().menubarTimezones() ?? [] - if menubarTimezones.isEmpty { currentState = .icon return