From 6536dbf2a5bcf119f6ff34564e536c6968f2d073 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 27 Sep 2019 06:38:43 -0500 Subject: [PATCH] Use correct account method for adding folders --- Frameworks/Account/Account.swift | 2 +- .../AddFolder/AddFolderWindowController.swift | 10 +++++++++- Mac/Scriptability/Folder+Scriptability.swift | 19 ++++++++++++++----- .../xcschemes/NetNewsWire.xcscheme | 10 ++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index d0aed6493..d0f787da3 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -426,7 +426,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } @discardableResult - public func ensureFolder(with name: String) -> Folder? { + func ensureFolder(with name: String) -> Folder? { // TODO: support subfolders, maybe, some day if name.isEmpty { diff --git a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift index d5fdbfcbb..f643afe74 100644 --- a/Mac/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Mac/MainWindow/AddFolder/AddFolderWindowController.swift @@ -72,7 +72,15 @@ class AddFolderWindowController : NSWindowController { return } - account.ensureFolder(with: folderName) + account.addFolder(folderName) { result in + switch result { + case .success: + break + case .failure(let error): + NSApplication.shared.presentError(error) + } + } + } // MARK: Actions diff --git a/Mac/Scriptability/Folder+Scriptability.swift b/Mac/Scriptability/Folder+Scriptability.swift index 8f522513c..7990d8384 100644 --- a/Mac/Scriptability/Folder+Scriptability.swift +++ b/Mac/Scriptability/Folder+Scriptability.swift @@ -76,11 +76,20 @@ class ScriptableFolder: NSObject, UniqueIdScriptingObject, ScriptingObjectContai print("support for folders within folders is NYI"); return nil } - let scriptableAccount = ScriptableAccount(account) - if let newFolder = account.ensureFolder(with:name) { - let scriptableFolder = ScriptableFolder(newFolder, container:scriptableAccount) - return(scriptableFolder.objectSpecifier) - } + + command.suspendExecution() + + account.addFolder(name) { result in + switch result { + case .success(let folder): + let scriptableAccount = ScriptableAccount(account) + let scriptableFolder = ScriptableFolder(folder, container:scriptableAccount) + command.resumeExecution(withResult:scriptableFolder.objectSpecifier) + case .failure: + command.resumeExecution(withResult:nil) + } + } + return nil } diff --git a/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme b/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme index 86db91441..a9a1ce816 100644 --- a/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme +++ b/NetNewsWire.xcodeproj/xcshareddata/xcschemes/NetNewsWire.xcscheme @@ -28,6 +28,16 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + +