From 9d39ae2de491ef3d9b67714261f500a967f8b79d Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 17 Feb 2018 18:19:25 -0800 Subject: [PATCH] Create and use AppImages.swift for widely-referenced images. --- Evergreen.xcodeproj/project.pbxproj | 4 ++++ Evergreen/AppDelegate.swift | 6 ----- Evergreen/AppImages.swift | 23 +++++++++++++++++++ .../FeedList/FeedListViewController.swift | 2 +- .../FeedInspectorViewController.swift | 2 +- .../MainWindow/MainWindowController.swift | 6 +---- .../Sidebar/SidebarViewController.swift | 2 +- .../Timeline/Cell/TimelineTableCellView.swift | 2 +- 8 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 Evergreen/AppImages.swift diff --git a/Evergreen.xcodeproj/project.pbxproj b/Evergreen.xcodeproj/project.pbxproj index 54caa1797..abab8eb9c 100644 --- a/Evergreen.xcodeproj/project.pbxproj +++ b/Evergreen.xcodeproj/project.pbxproj @@ -99,6 +99,7 @@ 849C64681ED37A5D003D8FC0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 849C64671ED37A5D003D8FC0 /* Assets.xcassets */; }; 849C646B1ED37A5D003D8FC0 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 849C64691ED37A5D003D8FC0 /* Main.storyboard */; }; 849C64761ED37A5D003D8FC0 /* EvergreenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849C64751ED37A5D003D8FC0 /* EvergreenTests.swift */; }; + 849EE70F203919360082A1EA /* AppImages.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849EE70E203919360082A1EA /* AppImages.swift */; }; 84A14FF320048CA70046AD9A /* SendToMicroBlogCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A14FF220048CA70046AD9A /* SendToMicroBlogCommand.swift */; }; 84A1500320048D660046AD9A /* SendToCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A1500220048D660046AD9A /* SendToCommand.swift */; }; 84A1500520048DDF0046AD9A /* SendToMarsEditCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A1500420048DDF0046AD9A /* SendToMarsEditCommand.swift */; }; @@ -621,6 +622,7 @@ 849C64711ED37A5D003D8FC0 /* EvergreenTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EvergreenTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 849C64751ED37A5D003D8FC0 /* EvergreenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EvergreenTests.swift; sourceTree = ""; }; 849C64771ED37A5D003D8FC0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 849EE70E203919360082A1EA /* AppImages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppImages.swift; path = Evergreen/AppImages.swift; sourceTree = ""; }; 84A14FF220048CA70046AD9A /* SendToMicroBlogCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendToMicroBlogCommand.swift; sourceTree = ""; }; 84A1500220048D660046AD9A /* SendToCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendToCommand.swift; sourceTree = ""; }; 84A1500420048DDF0046AD9A /* SendToMarsEditCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendToMarsEditCommand.swift; sourceTree = ""; }; @@ -1098,6 +1100,7 @@ 849C64631ED37A5D003D8FC0 /* AppDelegate.swift */, 84E46C7C1F75EF7B005ECFB3 /* AppDefaults.swift */, 842E45CD1ED8C308000A8B52 /* AppNotifications.swift */, + 849EE70E203919360082A1EA /* AppImages.swift */, 84DAEE311F870B390058304B /* DockBadge.swift */, 842E45DC1ED8C54B000A8B52 /* Browser.swift */, 84702AB31FA27AE8006B8943 /* Commands */, @@ -1949,6 +1952,7 @@ 845EE7B11FC2366500854A1F /* StarredFeedDelegate.swift in Sources */, 848F6AE51FC29CFB002D422E /* FaviconDownloader.swift in Sources */, 849A97981ED9EFAA007D329B /* Node-Extensions.swift in Sources */, + 849EE70F203919360082A1EA /* AppImages.swift in Sources */, 849A97531ED9EAC0007D329B /* AddFeedController.swift in Sources */, 84AAF2BF202CF684004A0BC4 /* TimelineContextualMenuDelegate.swift in Sources */, 849A97831ED9EC63007D329B /* SidebarStatusBarView.swift in Sources */, diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index a61486e9e..13e70cf76 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -31,12 +31,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, @IBOutlet var sortByOldestArticleOnTopMenuItem: NSMenuItem! @IBOutlet var sortByNewestArticleOnTopMenuItem: NSMenuItem! - lazy var genericFeedImage: NSImage? = { - let path = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" - let image = NSImage(contentsOfFile: path) - return image - }() - lazy var sendToCommands: [SendToCommand] = { return [SendToMicroBlogCommand(), SendToMarsEditCommand()] }() diff --git a/Evergreen/AppImages.swift b/Evergreen/AppImages.swift new file mode 100644 index 000000000..6b08ab7b7 --- /dev/null +++ b/Evergreen/AppImages.swift @@ -0,0 +1,23 @@ +// +// AppImages.swift +// Evergreen +// +// Created by Brent Simmons on 2/17/18. +// Copyright © 2018 Ranchero Software. All rights reserved. +// + +import AppKit + +extension NSImage.Name { + static let star = NSImage.Name(rawValue: "star") + static let unstar = NSImage.Name(rawValue: "unstar") +} + +struct AppImages { + + static var genericFeedImage: NSImage? = { + let path = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/BookmarkIcon.icns" + let image = NSImage(contentsOfFile: path) + return image + }() +} diff --git a/Evergreen/FeedList/FeedListViewController.swift b/Evergreen/FeedList/FeedListViewController.swift index e5c5d0928..b925e01f5 100644 --- a/Evergreen/FeedList/FeedListViewController.swift +++ b/Evergreen/FeedList/FeedListViewController.swift @@ -159,7 +159,7 @@ private extension FeedListViewController { if let image = appDelegate.faviconDownloader.favicon(withHomePageURL: feed.homePageURL) { return image } - return appDelegate.genericFeedImage + return AppImages.genericFeedImage } return nil } diff --git a/Evergreen/Inspector/FeedInspectorViewController.swift b/Evergreen/Inspector/FeedInspectorViewController.swift index 4214bda61..b112fb4bd 100644 --- a/Evergreen/Inspector/FeedInspectorViewController.swift +++ b/Evergreen/Inspector/FeedInspectorViewController.swift @@ -112,7 +112,7 @@ private extension FeedInspectorViewController { return } - imageView?.image = appDelegate.genericFeedImage + imageView?.image = AppImages.genericFeedImage } func updateName() { diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index a44851aef..73b260216 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -13,10 +13,6 @@ import RSCore private let kWindowFrameKey = "MainWindow" -extension NSImage.Name { - static let star = NSImage.Name(rawValue: "star") - static let unstar = NSImage.Name(rawValue: "unstar") -} class MainWindowController : NSWindowController, NSUserInterfaceValidations { @@ -417,7 +413,7 @@ extension MainWindowController: NSSharingServicePickerDelegate { return nil } - let image = sendToCommand.image ?? appDelegate.genericFeedImage ?? NSImage() + let image = sendToCommand.image ?? AppImages.genericFeedImage ?? NSImage() return NSSharingService(title: sendToCommand.title, image: image, alternateImage: nil) { sendToCommand.sendObject(object, selectedText: nil) } diff --git a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift index 390aefe48..c2ed2247f 100644 --- a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift +++ b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift @@ -576,7 +576,7 @@ extension Feed: SmallIconProvider { if let image = appDelegate.faviconDownloader.favicon(for: self) { return image } - return appDelegate.genericFeedImage + return AppImages.genericFeedImage } } diff --git a/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift b/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift index 336dda0d7..23500c854 100644 --- a/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift +++ b/Evergreen/MainWindow/Timeline/Cell/TimelineTableCellView.swift @@ -21,7 +21,7 @@ class TimelineTableCellView: NSTableCellView { imageView.imageScaling = .scaleProportionallyDown imageView.animates = false imageView.imageAlignment = .alignCenter - imageView.image = appDelegate.genericFeedImage + imageView.image = AppImages.genericFeedImage return imageView }()