From 21f262e953bffccfeb46b31ca28bc2f7b6ebb86a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 17 Feb 2018 12:01:14 -0800 Subject: [PATCH] Make mark-as-starred menu item work; make it validate; change its name as needed. --- Commands/MarkCommandValidationStatus.swift | 22 +++++++++++++++++++ Evergreen.xcodeproj/project.pbxproj | 4 ++++ Evergreen/Base.lproj/Main.storyboard | 10 ++++++--- .../MainWindow/MainWindowController.swift | 8 ++++++- .../Timeline/TimelineViewController.swift | 13 ----------- 5 files changed, 40 insertions(+), 17 deletions(-) create mode 100644 Commands/MarkCommandValidationStatus.swift diff --git a/Commands/MarkCommandValidationStatus.swift b/Commands/MarkCommandValidationStatus.swift new file mode 100644 index 000000000..510f55f77 --- /dev/null +++ b/Commands/MarkCommandValidationStatus.swift @@ -0,0 +1,22 @@ +// +// MarkCommandValidationStatus.swift +// Evergreen +// +// Created by Brent Simmons on 2/17/18. +// Copyright © 2018 Ranchero Software. All rights reserved. +// + +import Foundation + +enum MarkCommandValidationStatus { + + case canMark, canUnmark, canDoNothing + + static func statusFor(_ articles: ArticleArray, _ canMarkTest: ((ArticleArray) -> Bool)) -> MarkCommandValidationStatus { + + if articles.isEmpty { + return .canDoNothing + } + return canMarkTest(articles) ? .canMark : .canUnmark + } +} diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 644e771f9..5a81b036b 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -16,6 +16,7 @@ 840D61962029031D009BC708 /* Evergreen_iOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840D61952029031D009BC708 /* Evergreen_iOSTests.swift */; }; 840D61A12029031E009BC708 /* Evergreen_iOSUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840D61A02029031E009BC708 /* Evergreen_iOSUITests.swift */; }; 8414AD251FCF5A1E00955102 /* TimelineHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8414AD241FCF5A1E00955102 /* TimelineHeaderView.swift */; }; + 84162A152038C12C00035290 /* MarkCommandValidationStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84162A142038C12C00035290 /* MarkCommandValidationStatus.swift */; }; 841ABA4E20145E7300980E11 /* NothingInspectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841ABA4D20145E7300980E11 /* NothingInspectorViewController.swift */; }; 841ABA5E20145E9200980E11 /* FolderInspectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841ABA5D20145E9200980E11 /* FolderInspectorViewController.swift */; }; 841ABA6020145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841ABA5F20145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift */; }; @@ -532,6 +533,7 @@ 840D61A02029031E009BC708 /* Evergreen_iOSUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Evergreen_iOSUITests.swift; sourceTree = ""; }; 840D61A22029031E009BC708 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8414AD241FCF5A1E00955102 /* TimelineHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineHeaderView.swift; sourceTree = ""; }; + 84162A142038C12C00035290 /* MarkCommandValidationStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkCommandValidationStatus.swift; sourceTree = ""; }; 841ABA4D20145E7300980E11 /* NothingInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NothingInspectorViewController.swift; sourceTree = ""; }; 841ABA5D20145E9200980E11 /* FolderInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderInspectorViewController.swift; sourceTree = ""; }; 841ABA5F20145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuiltinSmartFeedInspectorViewController.swift; sourceTree = ""; }; @@ -899,6 +901,7 @@ isa = PBXGroup; children = ( 84702AA31FA27AC0006B8943 /* MarkStatusCommand.swift */, + 84162A142038C12C00035290 /* MarkCommandValidationStatus.swift */, 84B99C9C1FAE83C600ECDEDB /* DeleteFromSidebarCommand.swift */, 84A1500220048D660046AD9A /* SendToCommand.swift */, 84A14FF220048CA70046AD9A /* SendToMicroBlogCommand.swift */, @@ -1918,6 +1921,7 @@ 849A97651ED9EB96007D329B /* SidebarTreeControllerDelegate.swift in Sources */, 849A97671ED9EB96007D329B /* UnreadCountView.swift in Sources */, 8426118A1FCB67AA0086A189 /* FeedIconDownloader.swift in Sources */, + 84162A152038C12C00035290 /* MarkCommandValidationStatus.swift in Sources */, 84E95D241FB1087500552D99 /* ArticlePasteboardWriter.swift in Sources */, 849A975B1ED9EB0D007D329B /* ArticleUtilities.swift in Sources */, 84DAEE301F86CAFE0058304B /* OPMLImporter.swift in Sources */, diff --git a/Evergreen/Base.lproj/Main.storyboard b/Evergreen/Base.lproj/Main.storyboard index b34254e0c..288fddd82 100644 --- a/Evergreen/Base.lproj/Main.storyboard +++ b/Evergreen/Base.lproj/Main.storyboard @@ -1,7 +1,7 @@ - + - + @@ -426,7 +426,11 @@ - + + + + + diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index f26a1133e..1d2751054 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -205,13 +205,19 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { result = false } + let commandName = starring ? NSLocalizedString("Mark as Starred", comment: "Command") : NSLocalizedString("Mark as Unstarred", comment: "Command") + if let toolbarItem = item as? NSToolbarItem { - toolbarItem.toolTip = starring ? NSLocalizedString("Mark as Starred", comment: "Command") : NSLocalizedString("Mark as Unstarred", comment: "Command") + toolbarItem.toolTip = commandName if let button = toolbarItem.view as? NSButton { button.image = NSImage(named: starring ? .star : .unstar) } } + if let menuItem = item as? NSMenuItem { + menuItem.title = commandName + } + return result } diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index ea3bd1e7c..248443c2e 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -12,19 +12,6 @@ import RSTextDrawing import Data import Account -enum MarkCommandValidationStatus { - - case canMark, canUnmark, canDoNothing - - static func statusFor(_ articles: ArticleArray, _ canMarkTest: ((ArticleArray) -> Bool)) -> MarkCommandValidationStatus { - - if articles.isEmpty { - return .canDoNothing - } - return canMarkTest(articles) ? .canMark : .canUnmark - } -} - class TimelineViewController: NSViewController, UndoableCommandRunner { @IBOutlet var tableView: TimelineTableView!