From 2383ecd480da4f532d96d7ce437310290563aa8b Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 18 Oct 2017 19:46:35 -0700 Subject: [PATCH] =?UTF-8?q?Implement=20ensureFolder=20=E2=80=94=20it=20act?= =?UTF-8?q?ually=20creates=20and=20adds=20a=20folder=20and=20makes=20sure?= =?UTF-8?q?=20account=20is=20saved=20to=20disk.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddFolder/AddFolderWindowController.swift | 2 +- Frameworks/Account/Account.swift | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift b/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift index bafe63423..108fe7fa4 100644 --- a/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift +++ b/Evergreen/MainWindow/AddFolder/AddFolderWindowController.swift @@ -68,7 +68,7 @@ class AddFolderWindowController : NSWindowController { return } - let _ = account.ensureFolder(with: folderName) + account.ensureFolder(with: folderName) } // MARK: Actions diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index efd613342..492cf0ff3 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -174,10 +174,25 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, noteStatusesForArticlesDidChange(updatedArticles) } - + + @discardableResult public func ensureFolder(with name: String) -> Folder? { - - return nil //TODO + + // TODO: support subfolders, maybe, some day + + if name.isEmpty { + return nil + } + + if let folder = existingFolder(with: name) { + return folder + } + + let folder = Folder(account: self, name: name) + children += [folder] + dirty = true + + return folder } public func canAddFeed(_ feed: Feed, to folder: Folder?) -> Bool { @@ -287,7 +302,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, // Update the unread count if it’s a direct child. // If the object is owned by this account, then mark dirty — // since unread counts are saved to disk along with other feed info. - + if let object = note.object { if objectIsChild(object as AnyObject) {