Change the Inspectors to use the correct API's so that the sync services get updated. Fixes #2661

This commit is contained in:
Maurice Parker 2020-12-09 17:09:28 -06:00
parent 08e772cbd1
commit 336f40db7f
2 changed files with 45 additions and 21 deletions

View File

@ -27,6 +27,7 @@ final class FolderInspectorViewController: NSViewController, Inspector {
let isFallbackInspector = false
var objects: [Any]? {
didSet {
renameFolderIfNecessary()
updateFolder()
}
}
@ -43,16 +44,17 @@ final class FolderInspectorViewController: NSViewController, Inspector {
// MARK: NSViewController
override func viewDidLoad() {
updateUI()
NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil)
}
override func viewDidDisappear() {
renameFolderIfNecessary()
}
// MARK: Notifications
@objc func displayNameDidChange(_ note: Notification) {
guard let updatedFolder = note.object as? Folder, updatedFolder == folder else {
return
}
@ -63,19 +65,9 @@ final class FolderInspectorViewController: NSViewController, Inspector {
extension FolderInspectorViewController: NSTextFieldDelegate {
func controlTextDidEndEditing(_ obj: Notification) {
guard let folder = folder, let nameTextField = nameTextField else {
return
}
folder.rename(to: nameTextField.stringValue) { result in
switch result {
case .success:
break
case .failure(let error):
NSApplication.shared.presentError(error)
}
}
renameFolderIfNecessary()
}
}
private extension FolderInspectorViewController {
@ -106,4 +98,20 @@ private extension FolderInspectorViewController {
}
windowTitle = folder?.nameForDisplay ?? NSLocalizedString("Folder Inspector", comment: "Folder Inspector window title")
}
func renameFolderIfNecessary() {
guard let folder = folder,
let account = folder.account,
let nameTextField = nameTextField,
folder.nameForDisplay != nameTextField.stringValue else {
return
}
account.renameFolder(folder, to: nameTextField.stringValue) { [weak self] result in
if case .failure(let error) = result {
self?.presentError(error)
}
}
}
}

View File

@ -35,6 +35,7 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
let isFallbackInspector = false
var objects: [Any]? {
didSet {
renameWebFeedIfNecessary()
updateFeed()
}
}
@ -55,6 +56,10 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
updateNotificationSettings()
}
override func viewDidDisappear() {
renameWebFeedIfNecessary()
}
// MARK: Actions
@IBAction func isNotifyAboutNewArticlesChanged(_ sender: Any) {
guard userNotificationSettings != nil else {
@ -108,12 +113,8 @@ final class WebFeedInspectorViewController: NSViewController, Inspector {
extension WebFeedInspectorViewController: NSTextFieldDelegate {
func controlTextDidChange(_ note: Notification) {
guard let feed = feed, let nameTextField = nameTextField else {
return
}
feed.editedName = nameTextField.stringValue
windowTitle = feed.editedName ?? NSLocalizedString("Feed Inspector", comment: "Feed Inspector window title")
func controlTextDidEndEditing(_ note: Notification) {
renameWebFeedIfNecessary()
}
}
@ -208,4 +209,19 @@ private extension WebFeedInspectorViewController {
}
}
func renameWebFeedIfNecessary() {
guard let feed = feed,
let account = feed.account,
let nameTextField = nameTextField,
feed.nameForDisplay != nameTextField.stringValue else {
return
}
account.renameWebFeed(feed, to: nameTextField.stringValue) { [weak self] result in
if case .failure(let error) = result {
self?.presentError(error)
}
}
}
}