From f9b3eeb4d7e236ef88e50f728648cb9ee90cafb9 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 29 Oct 2017 11:14:10 -0700 Subject: [PATCH] Switch macOS deployment target to 10.13. Get MarkAllReadCommand working as an undoable command. --- Commands/MarkAllReadCommand.swift | 10 +++++++++- Evergreen.xcodeproj/project.pbxproj | 2 +- Evergreen/Data/ArticleUtilities.swift | 17 +++++++++++----- .../Timeline/TimelineViewController.swift | 9 +++------ Frameworks/Account/Account.swift | 9 ++++++--- .../Account/Account.xcodeproj/project.pbxproj | 4 ++-- Frameworks/DB5/DB5.xcodeproj/project.pbxproj | 4 ++-- .../Data/Data.xcodeproj/project.pbxproj | 4 ++-- .../Database.xcodeproj/project.pbxproj | 4 ++-- .../RSCore/RSCore.xcodeproj/project.pbxproj | 4 ++-- Frameworks/RSCore/RSCore/NSEvent+RSCore.m | 8 ++++---- .../RSCore/RSCore/UndoableCommand.swift | 20 +++++++++++++++++++ .../RSDatabase.xcodeproj/project.pbxproj | 4 ++-- .../RSFeedFinder.xcodeproj/project.pbxproj | 4 ++-- .../RSParser.xcodeproj/project.pbxproj | 4 ++-- .../RSTextDrawing.xcodeproj/project.pbxproj | 4 ++-- .../RSTree/RSTree.xcodeproj/project.pbxproj | 4 ++-- .../RSWeb/RSWeb.xcodeproj/project.pbxproj | 4 ++-- 18 files changed, 77 insertions(+), 42 deletions(-) diff --git a/Commands/MarkAllReadCommand.swift b/Commands/MarkAllReadCommand.swift index 3c00f3816..0dc05e11d 100644 --- a/Commands/MarkAllReadCommand.swift +++ b/Commands/MarkAllReadCommand.swift @@ -16,20 +16,28 @@ final class MarkAllReadCommand: UndoableCommand { let undoActionName = actionName let redoActionName = actionName let articles: Set
+ let undoManager: UndoManager - init(initialArticles: [Article]) { + init?(initialArticles: [Article], undoManager: UndoManager) { // Filter out articles already read. let unreadArticles = initialArticles.filter { !$0.status.read } + if unreadArticles.isEmpty { + return nil + } + self.articles = Set(unreadArticles) + self.undoManager = undoManager } func perform() { mark(read: true) + registerUndo() } func undo() { mark(read: false) + registerRedo() } func redo() { diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index d4c024066..dc27fdfa8 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -576,9 +576,9 @@ 849A97681ED9EBC8007D329B /* Timeline */ = { isa = PBXGroup; children = ( + 849A976B1ED9EBC8007D329B /* TimelineViewController.swift */, 849A97691ED9EBC8007D329B /* TimelineTableRowView.swift */, 849A976A1ED9EBC8007D329B /* TimelineTableView.swift */, - 849A976B1ED9EBC8007D329B /* TimelineViewController.swift */, 849A976F1ED9EC04007D329B /* Cell */, ); path = Timeline; diff --git a/Evergreen/Data/ArticleUtilities.swift b/Evergreen/Data/ArticleUtilities.swift index e97a8b3fd..67d0f1780 100644 --- a/Evergreen/Data/ArticleUtilities.swift +++ b/Evergreen/Data/ArticleUtilities.swift @@ -12,18 +12,25 @@ import Account // These handle multiple accounts. -func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) { +@discardableResult +func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? { let d: [String: Set
] = accountAndArticlesDictionary(articles) - + var updatedArticles = Set
() + for (accountID, accountArticles) in d { guard let account = AccountManager.shared.existingAccount(with: accountID) else { - return + continue } - - account.markArticles(accountArticles, statusKey: statusKey, flag: flag) + + if let accountUpdatedArticles = account.markArticles(accountArticles, statusKey: statusKey, flag: flag) { + updatedArticles.formUnion(accountUpdatedArticles) + } + } + + return updatedArticles } private func accountAndArticlesDictionary(_ articles: Set
) -> [String: Set
] { diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index f57481a64..fed7d89f3 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -118,14 +118,11 @@ class TimelineViewController: NSViewController, NSTableViewDelegate, NSTableView // MARK: - API func markAllAsRead() { - - if articles.isEmpty { + + guard let undoManager = undoManager, let markAllReadCommand = MarkAllReadCommand(initialArticles: articles, undoManager: undoManager) else { return } - - markArticles(Set(articles), statusKey: .read, flag: true) - - reloadCellsForArticles(articles) + markAllReadCommand.perform() } // MARK: - Actions diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index ba562f5e1..845077c08 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -165,16 +165,19 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } - public func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) { - + public func markArticles(_ articles: Set
, statusKey: ArticleStatus.Key, flag: Bool) -> Set
? { + + // Returns set of Articles whose statuses did change. + guard let updatedStatuses = database.mark(articles, statusKey: statusKey, flag: flag) else { - return + return nil } let updatedArticleIDs = updatedStatuses.articleIDs() let updatedArticles = Set(articles.filter{ updatedArticleIDs.contains($0.articleID) }) noteStatusesForArticlesDidChange(updatedArticles) + return updatedArticles } @discardableResult diff --git a/Frameworks/Account/Account.xcodeproj/project.pbxproj b/Frameworks/Account/Account.xcodeproj/project.pbxproj index dbe7276b8..27bc0b7fb 100644 --- a/Frameworks/Account/Account.xcodeproj/project.pbxproj +++ b/Frameworks/Account/Account.xcodeproj/project.pbxproj @@ -508,7 +508,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -562,7 +562,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/Frameworks/DB5/DB5.xcodeproj/project.pbxproj b/Frameworks/DB5/DB5.xcodeproj/project.pbxproj index cfa0f8465..620774939 100644 --- a/Frameworks/DB5/DB5.xcodeproj/project.pbxproj +++ b/Frameworks/DB5/DB5.xcodeproj/project.pbxproj @@ -263,7 +263,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -304,7 +304,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; diff --git a/Frameworks/Data/Data.xcodeproj/project.pbxproj b/Frameworks/Data/Data.xcodeproj/project.pbxproj index 8b56279d6..64c079032 100644 --- a/Frameworks/Data/Data.xcodeproj/project.pbxproj +++ b/Frameworks/Data/Data.xcodeproj/project.pbxproj @@ -364,7 +364,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -413,7 +413,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/Frameworks/Database/Database.xcodeproj/project.pbxproj b/Frameworks/Database/Database.xcodeproj/project.pbxproj index 1f0da93c2..0f41482a7 100644 --- a/Frameworks/Database/Database.xcodeproj/project.pbxproj +++ b/Frameworks/Database/Database.xcodeproj/project.pbxproj @@ -562,7 +562,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -611,7 +611,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj b/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj index 4302ff351..342e08c6e 100755 --- a/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj +++ b/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj @@ -855,7 +855,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; RUN_CLANG_STATIC_ANALYZER = YES; @@ -923,7 +923,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx; diff --git a/Frameworks/RSCore/RSCore/NSEvent+RSCore.m b/Frameworks/RSCore/RSCore/NSEvent+RSCore.m index 9972abc48..de80e7eb5 100755 --- a/Frameworks/RSCore/RSCore/NSEvent+RSCore.m +++ b/Frameworks/RSCore/RSCore/NSEvent+RSCore.m @@ -19,10 +19,10 @@ unichar kDeleteKeyCode = 127; NSEventModifierFlags flags = self.modifierFlags; - *shiftKeyDown = ((flags & NSShiftKeyMask) != 0); - *optionKeyDown = ((flags & NSAlternateKeyMask) != 0); - *commandKeyDown = ((flags & NSCommandKeyMask) != 0); - *controlKeyDown = ((flags & NSControlKeyMask) != 0); + *shiftKeyDown = ((flags & NSEventModifierFlagShift) != 0); + *optionKeyDown = ((flags & NSEventModifierFlagOption) != 0); + *commandKeyDown = ((flags & NSEventModifierFlagCommand) != 0); + *controlKeyDown = ((flags & NSEventModifierFlagControl) != 0); } diff --git a/Frameworks/RSCore/RSCore/UndoableCommand.swift b/Frameworks/RSCore/RSCore/UndoableCommand.swift index 624d0952c..e926c4a5e 100644 --- a/Frameworks/RSCore/RSCore/UndoableCommand.swift +++ b/Frameworks/RSCore/RSCore/UndoableCommand.swift @@ -12,8 +12,28 @@ public protocol UndoableCommand: class { var undoActionName: String { get } var redoActionName: String { get } + var undoManager: UndoManager { get } func perform() func undo() func redo() } + +extension UndoableCommand { + + public func registerUndo() { + + undoManager.setActionName(undoActionName) + undoManager.registerUndo(withTarget: self) { (target) in + self.undo() + } + } + + public func registerRedo() { + + undoManager.setActionName(redoActionName) + undoManager.registerUndo(withTarget: self) { (target) in + self.redo() + } + } +} diff --git a/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj b/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj index a42a99dfe..48afdf898 100755 --- a/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj +++ b/Frameworks/RSDatabase/RSDatabase.xcodeproj/project.pbxproj @@ -520,7 +520,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -564,7 +564,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_SWIFT3_OBJC_INFERENCE = Off; diff --git a/Frameworks/RSFeedFinder/RSFeedFinder.xcodeproj/project.pbxproj b/Frameworks/RSFeedFinder/RSFeedFinder.xcodeproj/project.pbxproj index 54e32cbb0..e60c59321 100644 --- a/Frameworks/RSFeedFinder/RSFeedFinder.xcodeproj/project.pbxproj +++ b/Frameworks/RSFeedFinder/RSFeedFinder.xcodeproj/project.pbxproj @@ -308,7 +308,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -352,7 +352,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj b/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj index 27fa65303..e22121b1f 100644 --- a/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj +++ b/Frameworks/RSParser/RSParser.xcodeproj/project.pbxproj @@ -677,7 +677,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; RUN_CLANG_STATIC_ANALYZER = YES; @@ -758,7 +758,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx; diff --git a/Frameworks/RSTextDrawing/RSTextDrawing.xcodeproj/project.pbxproj b/Frameworks/RSTextDrawing/RSTextDrawing.xcodeproj/project.pbxproj index c5ebe02ff..fc3e62658 100644 --- a/Frameworks/RSTextDrawing/RSTextDrawing.xcodeproj/project.pbxproj +++ b/Frameworks/RSTextDrawing/RSTextDrawing.xcodeproj/project.pbxproj @@ -297,7 +297,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -339,7 +339,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; diff --git a/Frameworks/RSTree/RSTree.xcodeproj/project.pbxproj b/Frameworks/RSTree/RSTree.xcodeproj/project.pbxproj index 9250fa974..380aa5864 100644 --- a/Frameworks/RSTree/RSTree.xcodeproj/project.pbxproj +++ b/Frameworks/RSTree/RSTree.xcodeproj/project.pbxproj @@ -270,7 +270,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -316,7 +316,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; diff --git a/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj b/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj index cb3c96b2a..85ad09c77 100755 --- a/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj +++ b/Frameworks/RSWeb/RSWeb.xcodeproj/project.pbxproj @@ -456,7 +456,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; RUN_CLANG_STATIC_ANALYZER = YES; @@ -529,7 +529,7 @@ GCC_WARN_UNUSED_LABEL = YES; GCC_WARN_UNUSED_PARAMETER = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.12; + MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; RUN_CLANG_STATIC_ANALYZER = YES; SDKROOT = macosx;