diff --git a/Appcasts/evergreen-beta.xml b/Appcasts/evergreen-beta.xml index 55c52998b..5af72ee22 100755 --- a/Appcasts/evergreen-beta.xml +++ b/Appcasts/evergreen-beta.xml @@ -6,6 +6,27 @@ Most recent Evergreen changes with links to updates. en + + Evergreen 1.0d34 + Icons +

Updated app icon — tree redrawn to make branches wider and have definition.

+

Updated next unread icon to fit better.

+

(Icons are by Brad Ellis.)

+ +

Inspector

+

Window > Info, or cmd-I, opens the Inspector. You can change the names of feeds and folders. You can get the home page URL and feed URL of a feed (which is pretty important when filing a bug for a feed).

+ +

Misc.

+

Reload the timeline when a feed updates (when feed is selected, or when a folder containing the feed is selected).

+ + ]]>
+ Tue, 23 Jan 2018 22:00:00 -0800 + + 10.13 +
+ Evergreen 1.0d33 "; }; + 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 = ""; }; 842611891FCB67AA0086A189 /* FeedIconDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedIconDownloader.swift; sourceTree = ""; }; 8426119D1FCB6ED40086A189 /* HTMLMetadataDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLMetadataDownloader.swift; sourceTree = ""; }; 8426119F1FCB72600086A189 /* FeaturedImageDownloader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturedImageDownloader.swift; sourceTree = ""; }; @@ -486,6 +495,7 @@ 846E77161F6EF5D000A165E2 /* Database.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Database.xcodeproj; path = Frameworks/Database/Database.xcodeproj; sourceTree = ""; }; 846E77301F6EF5D600A165E2 /* Account.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Account.xcodeproj; path = Frameworks/Account/Account.xcodeproj; sourceTree = ""; }; 84702AA31FA27AC0006B8943 /* MarkReadOrUnreadCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkReadOrUnreadCommand.swift; sourceTree = ""; }; + 8472058020142E8900AD578B /* FeedInspectorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedInspectorViewController.swift; sourceTree = ""; }; 847752FE2008879500D93690 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; 848F6AE41FC29CFA002D422E /* FaviconDownloader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FaviconDownloader.swift; sourceTree = ""; }; 849A97421ED9EAA9007D329B /* AddFolderWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddFolderWindowController.swift; sourceTree = ""; }; @@ -553,6 +563,8 @@ 84B99C6A1FAE370B00ECDEDB /* FeedListFeed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListFeed.swift; sourceTree = ""; }; 84B99C9C1FAE83C600ECDEDB /* DeleteFromSidebarCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteFromSidebarCommand.swift; sourceTree = ""; }; 84BB4B611F1174D400858766 /* Data.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Data.xcodeproj; path = Frameworks/Data/Data.xcodeproj; sourceTree = ""; }; + 84BBB12B20142A4700F054F5 /* Inspector.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Inspector.storyboard; sourceTree = ""; }; + 84BBB12C20142A4700F054F5 /* InspectorWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InspectorWindowController.swift; sourceTree = ""; }; 84C12A141FF5B0080009A267 /* FeedList.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = FeedList.storyboard; sourceTree = ""; }; 84CBDDAE1FD3674C005A61AA /* Technotes */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Technotes; sourceTree = ""; }; 84CC08051FF5D2E000C0C0ED /* FeedListSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListSplitViewController.swift; sourceTree = ""; }; @@ -931,6 +943,7 @@ 842E45DC1ED8C54B000A8B52 /* Browser.swift */, 84702AB31FA27AE8006B8943 /* Commands */, 842E45E11ED8C681000A8B52 /* MainWindow */, + 84BBB12A20142A4700F054F5 /* Inspector */, 842E45E01ED8C587000A8B52 /* Preferences */, 849A97861ED9ECEF007D329B /* Article Styles */, 84A6B6921FB8D43C006754AC /* Dinosaurs */, @@ -1069,6 +1082,20 @@ name = Products; sourceTree = ""; }; + 84BBB12A20142A4700F054F5 /* Inspector */ = { + isa = PBXGroup; + children = ( + 84BBB12B20142A4700F054F5 /* Inspector.storyboard */, + 84BBB12C20142A4700F054F5 /* InspectorWindowController.swift */, + 8472058020142E8900AD578B /* FeedInspectorViewController.swift */, + 841ABA5D20145E9200980E11 /* FolderInspectorViewController.swift */, + 841ABA5F20145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift */, + 841ABA4D20145E7300980E11 /* NothingInspectorViewController.swift */, + ); + name = Inspector; + path = Evergreen/Inspector; + sourceTree = ""; + }; 84DAEE201F86CAE00058304B /* Importers */ = { isa = PBXGroup; children = ( @@ -1510,6 +1537,7 @@ 849A97B21ED9FA69007D329B /* MainWindow.storyboard in Resources */, 849A979C1ED9EFEB007D329B /* styleSheet.css in Resources */, 849A97A61ED9F94D007D329B /* Preferences.storyboard in Resources */, + 84BBB12D20142A4700F054F5 /* Inspector.storyboard in Resources */, D5D1751220020B980047B29D /* Evergreen.sdef in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1547,8 +1575,10 @@ 84F204E01FAACBB30076E152 /* ArticleArray.swift in Sources */, 849C64641ED37A5D003D8FC0 /* AppDelegate.swift in Sources */, 84513F901FAA63950023A1A9 /* FeedListControlsView.swift in Sources */, + 84BBB12E20142A4700F054F5 /* InspectorWindowController.swift in Sources */, 84E46C7D1F75EF7B005ECFB3 /* AppDefaults.swift in Sources */, D5907D972004B7EB005947E5 /* Account+Scriptability.swift in Sources */, + 841ABA4E20145E7300980E11 /* NothingInspectorViewController.swift in Sources */, 842E45CE1ED8C308000A8B52 /* AppNotifications.swift in Sources */, 844B5B5B1FEA00FB00C7C76A /* TimelineKeyboardDelegate.swift in Sources */, 84DAEE321F870B390058304B /* DockBadge.swift in Sources */, @@ -1585,6 +1615,7 @@ D5907DB22004BB37005947E5 /* ScriptingObjectContainer.swift in Sources */, 849A978A1ED9ECEF007D329B /* ArticleStylesManager.swift in Sources */, 849A97791ED9EC04007D329B /* TimelineStringUtilities.swift in Sources */, + 8472058120142E8900AD578B /* FeedInspectorViewController.swift in Sources */, 84F204CE1FAACB660076E152 /* FeedListViewController.swift in Sources */, 845A29241FC9255E007B49E3 /* SidebarCellAppearance.swift in Sources */, 845EE7B11FC2366500854A1F /* StarredFeedDelegate.swift in Sources */, @@ -1593,6 +1624,7 @@ 849A97531ED9EAC0007D329B /* AddFeedController.swift in Sources */, 849A97831ED9EC63007D329B /* SidebarStatusBarView.swift in Sources */, 84F2D5381FC22FCC00998D64 /* TodayFeedDelegate.swift in Sources */, + 841ABA5E20145E9200980E11 /* FolderInspectorViewController.swift in Sources */, 845213231FCA5B11003B6E93 /* ImageDownloader.swift in Sources */, 849A97431ED9EAA9007D329B /* AddFolderWindowController.swift in Sources */, 844B5B671FEA18E300C7C76A /* MainWIndowKeyboardHandler.swift in Sources */, @@ -1603,6 +1635,7 @@ 849A978D1ED9EE4D007D329B /* FeedListWindowController.swift in Sources */, 849A97771ED9EC04007D329B /* TimelineCellData.swift in Sources */, 84B99C6B1FAE370B00ECDEDB /* FeedListFeed.swift in Sources */, + 841ABA6020145EC100980E11 /* BuiltinSmartFeedInspectorViewController.swift in Sources */, D5F4EDB5200744A700B9E363 /* ScriptingObject.swift in Sources */, D5F4EDB920074D7C00B9E363 /* Folder+Scriptability.swift in Sources */, 842611A01FCB72600086A189 /* FeaturedImageDownloader.swift in Sources */, diff --git a/Evergreen/AppDelegate.swift b/Evergreen/AppDelegate.swift index 50ee09538..3dc928be9 100644 --- a/Evergreen/AppDelegate.swift +++ b/Evergreen/AppDelegate.swift @@ -69,6 +69,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, dockBadge.appDelegate = self NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(sidebarSelectionDidChange(_:)), name: .SidebarSelectionDidChange, object: nil) + appDelegate = self } @@ -136,6 +138,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, self.unreadCount = AccountManager.shared.unreadCount } + if InspectorWindowController.shouldOpenAtStartup { + self.toggleInspectorWindow(self) + } + #if RELEASE DispatchQueue.main.async { self.refreshAll(self) @@ -157,6 +163,13 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, RSMultiLineRenderer.emptyCache() TimelineCellData.emptyCache() timelineEmptyCaches() + + saveState() + } + + func applicationWillTerminate(_ notification: Notification) { + + saveState() } // MARK: GetURL Apple Event @@ -195,6 +208,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, let _ = faviconDownloader.favicon(for: feed) } + @objc func sidebarSelectionDidChange(_ note: Notification) { + + guard let inspectorWindowController = inspectorWindowController, inspectorWindowController.isOpen else { + return + } + inspectorWindowController.objects = objectsForInspector() + } + // MARK: Main Window func windowControllerWithName(_ storyboardName: String) -> NSWindowController { @@ -303,13 +324,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidations, @IBAction func toggleInspectorWindow(_ sender: Any?) { if inspectorWindowController == nil { - inspectorWindowController = InspectorWindowController() + inspectorWindowController = (windowControllerWithName("Inspector") as! InspectorWindowController) } if inspectorWindowController!.isOpen { inspectorWindowController!.window!.performClose(self) } else { + inspectorWindowController!.objects = objectsForInspector() inspectorWindowController!.showWindow(self) } } @@ -425,4 +447,19 @@ private extension AppDelegate { return windowControllerWithName("MainWindow") } + + func objectsForInspector() -> [Any]? { + + guard let window = NSApplication.shared.mainWindow, let windowController = window.windowController as? MainWindowController else { + return nil + } + return windowController.selectedObjectsInSidebar() + } + + func saveState() { + + if let inspectorWindowController = inspectorWindowController { + inspectorWindowController.saveState() + } + } } diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128.png index 861e26006..af56f3974 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png index 693f0988a..014f92987 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_128x128@2x.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16.png index de81e6395..f5a67efd6 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png index dd0fa842e..ecd7bcbd5 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_16x16@2x.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256.png index 693f0988a..be96d897e 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png index 13466e831..8d4a92e54 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_256x256@2x.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32.png index bbaf780ab..69d6e1813 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png index 4a1506b79..e8a136781 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_32x32@2x.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512.png index 13466e831..39787af50 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512.png differ diff --git a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png index ed53df0c8..efa1d2084 100644 Binary files a/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png and b/Evergreen/Assets.xcassets/AppIcon.appiconset/icon_512x512@2x.png differ diff --git a/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread.png b/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread.png index 123967957..3d05912df 100644 Binary files a/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread.png and b/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread.png differ diff --git a/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread@2x.png b/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread@2x.png index 763d1fb0e..f6568fc24 100644 Binary files a/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread@2x.png and b/Evergreen/Assets.xcassets/nextUnread.imageset/nextUnread@2x.png differ diff --git a/Evergreen/Info.plist b/Evergreen/Info.plist index 2289d6e49..955ced730 100644 --- a/Evergreen/Info.plist +++ b/Evergreen/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0d33 + 1.0d34 CFBundleVersion 522 LSMinimumSystemVersion diff --git a/Evergreen/Inspector/BuiltinSmartFeedInspectorViewController.swift b/Evergreen/Inspector/BuiltinSmartFeedInspectorViewController.swift new file mode 100644 index 000000000..68f7d4773 --- /dev/null +++ b/Evergreen/Inspector/BuiltinSmartFeedInspectorViewController.swift @@ -0,0 +1,66 @@ +// +// BuiltinSmartFeedInspectorViewController.swift +// Evergreen +// +// Created by Brent Simmons on 1/20/18. +// Copyright © 2018 Ranchero Software. All rights reserved. +// + +import AppKit + +final class BuiltinSmartFeedInspectorViewController: NSViewController, Inspector { + + @IBOutlet var nameTextField: NSTextField? + + private var smartFeed: PseudoFeed? { + didSet { + updateUI() + } + } + + // MARK: Inspector + + let isFallbackInspector = false + var objects: [Any]? { + didSet { + updateSmartFeed() + } + } + + func canInspect(_ objects: [Any]) -> Bool { + + guard let _ = singleSmartFeed(from: objects) else { + return false + } + return true + } + + // MARK: NSViewController + + override func viewDidLoad() { + + updateUI() + } +} + +private extension BuiltinSmartFeedInspectorViewController { + + func singleSmartFeed(from objects: [Any]?) -> PseudoFeed? { + + guard let objects = objects, objects.count == 1, let singleSmartFeed = objects.first as? PseudoFeed else { + return nil + } + + return singleSmartFeed + } + + func updateSmartFeed() { + + smartFeed = singleSmartFeed(from: objects) + } + + func updateUI() { + + nameTextField?.stringValue = smartFeed?.nameForDisplay ?? "" + } +} diff --git a/Evergreen/Inspector/FeedInspectorViewController.swift b/Evergreen/Inspector/FeedInspectorViewController.swift new file mode 100644 index 000000000..de5ebe612 --- /dev/null +++ b/Evergreen/Inspector/FeedInspectorViewController.swift @@ -0,0 +1,139 @@ +// +// FeedInspectorViewController.swift +// Evergreen +// +// Created by Brent Simmons on 1/20/18. +// Copyright © 2018 Ranchero Software. All rights reserved. +// + +import AppKit +import Data +import DB5 + +final class FeedInspectorViewController: NSViewController, Inspector { + + @IBOutlet var imageView: NSImageView? + @IBOutlet var nameTextField: NSTextField? + @IBOutlet var homePageURLTextField: NSTextField? + @IBOutlet var urlTextField: NSTextField? + + private var feed: Feed? { + didSet { + if feed != oldValue { + updateUI() + } + } + } + + // MARK: Inspector + + let isFallbackInspector = false + var objects: [Any]? { + didSet { + updateFeed() + } + } + + func canInspect(_ objects: [Any]) -> Bool { + + return objects.count == 1 && objects.first is Feed + } + + // MARK: NSViewController + + override func viewDidLoad() { + + imageView!.wantsLayer = true + let cornerRadius = appDelegate.currentTheme.float(forKey: "MainWindow.Timeline.cell.avatarCornerRadius") + imageView!.layer?.cornerRadius = cornerRadius + + updateUI() + + NotificationCenter.default.addObserver(self, selector: #selector(imageDidBecomeAvailable(_:)), name: .ImageDidBecomeAvailable, object: nil) + } + + // MARK: Notifications + + @objc func imageDidBecomeAvailable(_ note: Notification) { + + updateImage() + } +} + +extension FeedInspectorViewController: NSTextFieldDelegate { + + override func controlTextDidChange(_ note: Notification) { + + guard let feed = feed, let nameTextField = nameTextField else { + return + } + feed.editedName = nameTextField.stringValue + } +} + +private extension FeedInspectorViewController { + + func updateFeed() { + + guard let objects = objects, objects.count == 1, let singleFeed = objects.first as? Feed else { + feed = nil + return + } + feed = singleFeed + } + + func updateUI() { + + updateImage() + updateName() + updateHomePageURL() + updateFeedURL() + + view.needsLayout = true + } + + func updateImage() { + + guard let feed = feed else { + imageView?.image = nil + return + } + + if let feedIcon = appDelegate.feedIconDownloader.icon(for: feed) { + imageView?.image = feedIcon + return + } + + if let favicon = appDelegate.faviconDownloader.favicon(for: feed) { + if favicon.size.height < 16.0 && favicon.size.width < 16.0 { + favicon.size = NSSize(width: 16, height: 16) + } + imageView?.image = favicon + return + } + + imageView?.image = nil + } + + func updateName() { + + guard let nameTextField = nameTextField else { + return + } + + let name = feed?.editedName ?? feed?.name ?? "" + if nameTextField.stringValue != name { + nameTextField.stringValue = name + } + } + + func updateHomePageURL() { + + homePageURLTextField?.stringValue = feed?.homePageURL ?? "" + } + + func updateFeedURL() { + + urlTextField?.stringValue = feed?.url ?? "" + } +} diff --git a/Evergreen/Inspector/FolderInspectorViewController.swift b/Evergreen/Inspector/FolderInspectorViewController.swift new file mode 100644 index 000000000..4df9961d2 --- /dev/null +++ b/Evergreen/Inspector/FolderInspectorViewController.swift @@ -0,0 +1,100 @@ +// +// FolderInspectorViewController.swift +// Evergreen +// +// Created by Brent Simmons on 1/20/18. +// Copyright © 2018 Ranchero Software. All rights reserved. +// + +import AppKit +import Account +import RSCore + +final class FolderInspectorViewController: NSViewController, Inspector { + + @IBOutlet var nameTextField: NSTextField? + + private var folder: Folder? { + didSet { + if folder != oldValue { + updateUI() + } + } + } + + // MARK: Inspector + + let isFallbackInspector = false + var objects: [Any]? { + didSet { + updateFolder() + } + } + + func canInspect(_ objects: [Any]) -> Bool { + + guard let _ = singleFolder(from: objects) else { + return false + } + return true + } + + // MARK: NSViewController + + override func viewDidLoad() { + + updateUI() + + NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) + } + + // MARK: Notifications + + @objc func displayNameDidChange(_ note: Notification) { + + guard let updatedFolder = note.object as? Folder, updatedFolder == folder else { + return + } + updateUI() + } +} + +extension FolderInspectorViewController: NSTextFieldDelegate { + + override func controlTextDidChange(_ note: Notification) { + + guard let folder = folder, let nameTextField = nameTextField else { + return + } + folder.name = nameTextField.stringValue + } +} + +private extension FolderInspectorViewController { + + func singleFolder(from objects: [Any]?) -> Folder? { + + guard let objects = objects, objects.count == 1, let singleFolder = objects.first as? Folder else { + return nil + } + + return singleFolder + } + + func updateFolder() { + + folder = singleFolder(from: objects) + } + + func updateUI() { + + guard let nameTextField = nameTextField else { + return + } + + let name = folder?.nameForDisplay ?? "" + if nameTextField.stringValue != name { + nameTextField.stringValue = name + } + } +} diff --git a/Evergreen/Inspector/Inspector.storyboard b/Evergreen/Inspector/Inspector.storyboard new file mode 100644 index 000000000..9704efc13 --- /dev/null +++ b/Evergreen/Inspector/Inspector.storyboard @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Feed +Name +Field + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Folder +Name +Field + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Evergreen/Inspector/InspectorWindowController.swift b/Evergreen/Inspector/InspectorWindowController.swift new file mode 100644 index 000000000..28588447d --- /dev/null +++ b/Evergreen/Inspector/InspectorWindowController.swift @@ -0,0 +1,139 @@ +// +// InspectorWindowController.swift +// Evergreen +// +// Created by Brent Simmons on 1/20/18. +// Copyright © 2018 Ranchero Software. All rights reserved. +// + +import AppKit + +protocol Inspector: class { + + var objects: [Any]? { get set } + var isFallbackInspector: Bool { get } // Can handle nothing-to-inspect or unexpected type of objects. + + func canInspect(_ objects: [Any]) -> Bool +} + +typealias InspectorViewController = Inspector & NSViewController + + +final class InspectorWindowController: NSWindowController { + + class var shouldOpenAtStartup: Bool { + return UserDefaults.standard.bool(forKey: DefaultsKey.windowIsOpen) + } + + var objects: [Any]? { + didSet { + let _ = window + currentInspector = inspector(for: objects) + } + } + + var isOpen: Bool { + get { + return isWindowLoaded && window!.isVisible + } + } + + private var inspectors: [InspectorViewController]! + + private var currentInspector: InspectorViewController! { + didSet { + currentInspector.objects = objects + for inspector in inspectors { + if inspector !== currentInspector { + inspector.objects = nil + } + } + show(currentInspector) + } + } + + private struct DefaultsKey { + static let windowIsOpen = "FloatingInspectorIsOpen" + static let windowOrigin = "FloatingInspectorOrigin" + } + + override func windowDidLoad() { + + let nothingInspector = window?.contentViewController as! InspectorViewController + + let storyboard = NSStoryboard(name: NSStoryboard.Name(rawValue: "Inspector"), bundle: nil) + let feedInspector = inspector("Feed", storyboard) + let folderInspector = inspector("Folder", storyboard) + let builtinSmartFeedInspector = inspector("BuiltinSmartFeed", storyboard) + + inspectors = [feedInspector, folderInspector, builtinSmartFeedInspector, nothingInspector] + currentInspector = nothingInspector + + if let savedOrigin = originFromDefaults() { + window?.setFlippedOriginAdjustingForScreen(savedOrigin) + } + else { + window?.flippedOrigin = NSPoint(x: 256, y: 256) + } + } + + func inspector(for objects: [Any]?) -> InspectorViewController { + + var fallbackInspector: InspectorViewController? = nil + + for inspector in inspectors { + if inspector.isFallbackInspector { + fallbackInspector = inspector + } + else if let objects = objects, inspector.canInspect(objects) { + return inspector + } + } + + return fallbackInspector! + } + + func saveState() { + + UserDefaults.standard.set(isOpen, forKey: DefaultsKey.windowIsOpen) + if isOpen, let window = window, let flippedOrigin = window.flippedOrigin { + UserDefaults.standard.set(NSStringFromPoint(flippedOrigin), forKey: DefaultsKey.windowOrigin) + } + } +} + +private extension InspectorWindowController { + + func inspector(_ identifier: String, _ storyboard: NSStoryboard) -> InspectorViewController { + + return storyboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: identifier)) as! InspectorViewController + } + + func show(_ inspector: InspectorViewController) { + + guard let window = window else { + return + } + + let flippedOrigin = window.flippedOrigin + + if window.contentViewController != inspector { + window.contentViewController = inspector + window.makeFirstResponder(nil) + } + + window.layoutIfNeeded() + if let flippedOrigin = flippedOrigin { + window.setFlippedOriginAdjustingForScreen(flippedOrigin) + } + } + + func originFromDefaults() -> NSPoint? { + + guard let originString = UserDefaults.standard.string(forKey: DefaultsKey.windowOrigin) else { + return nil + } + let point = NSPointFromString(originString) + return point == NSPoint.zero ? nil : point + } +} diff --git a/Evergreen/Inspector/NothingInspectorViewController.swift b/Evergreen/Inspector/NothingInspectorViewController.swift new file mode 100644 index 000000000..6885d00a0 --- /dev/null +++ b/Evergreen/Inspector/NothingInspectorViewController.swift @@ -0,0 +1,47 @@ +// +// NothingInspectorViewController.swift +// Evergreen +// +// Created by Brent Simmons on 1/20/18. +// Copyright © 2018 Ranchero Software. All rights reserved. +// + +import AppKit + +final class NothingInspectorViewController: NSViewController, Inspector { + + @IBOutlet var nothingTextField: NSTextField? + @IBOutlet var multipleTextField: NSTextField? + + let isFallbackInspector = true + var objects: [Any]? { + didSet { + updateTextFields() + } + } + + func canInspect(_ objects: [Any]) -> Bool { + + return true + } + + override func viewDidLoad() { + + updateTextFields() + } +} + +private extension NothingInspectorViewController { + + func updateTextFields() { + + if let objects = objects, objects.count > 1 { + nothingTextField?.isHidden = true + multipleTextField?.isHidden = false + } + else { + nothingTextField?.isHidden = false + multipleTextField?.isHidden = true + } + } +} diff --git a/Evergreen/MainWindow/MainWindowController.swift b/Evergreen/MainWindow/MainWindowController.swift index f314812d5..5fb8cc31c 100644 --- a/Evergreen/MainWindow/MainWindowController.swift +++ b/Evergreen/MainWindow/MainWindowController.swift @@ -63,7 +63,14 @@ class MainWindowController : NSWindowController, NSUserInterfaceValidations { self.updateWindowTitle() } } - + + // MARK: Sidebar + + func selectedObjectsInSidebar() -> [AnyObject]? { + + return sidebarViewController?.selectedObjects + } + // MARK: Notifications @objc func applicationWillTerminate(_ note: Notification) { diff --git a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift index 090b0ce0f..a2d735746 100644 --- a/Evergreen/MainWindow/Sidebar/SidebarViewController.swift +++ b/Evergreen/MainWindow/Sidebar/SidebarViewController.swift @@ -23,6 +23,10 @@ import RSCore private var animatingChanges = false private var sidebarCellAppearance: SidebarCellAppearance! + var selectedObjects: [AnyObject] { + return selectedNodes.representedObjects() + } + //MARK: NSViewController override func viewDidLoad() { @@ -39,6 +43,7 @@ import RSCore NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(faviconDidBecomeAvailable(_:)), name: .FaviconDidBecomeAvailable, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) outlineView.reloadData() @@ -97,6 +102,14 @@ import RSCore configureCellsForRepresentedObject(feed) } + @objc func displayNameDidChange(_ note: Notification) { + + guard let object = note.object else { + return + } + configureCellsForRepresentedObject(object as AnyObject) + } + // MARK: Actions @IBAction func delete(_ sender: AnyObject?) { diff --git a/Evergreen/MainWindow/Timeline/TimelineViewController.swift b/Evergreen/MainWindow/Timeline/TimelineViewController.swift index 1234c6072..d4b712d90 100644 --- a/Evergreen/MainWindow/Timeline/TimelineViewController.swift +++ b/Evergreen/MainWindow/Timeline/TimelineViewController.swift @@ -642,7 +642,12 @@ private extension TimelineViewController { } let fetchedArticles = fetchUnsortedArticles(for: representedObjects) - let sortedArticles = Array(fetchedArticles).sortedByDate() + updateArticles(with: fetchedArticles) + } + + func updateArticles(with unsortedArticles: Set
) { + + let sortedArticles = Array(unsortedArticles).sortedByDate() if articles != sortedArticles { articles = sortedArticles } @@ -667,20 +672,27 @@ private extension TimelineViewController { func fetchAndMergeArticles() { + guard let representedObjects = representedObjects else { + return + } + let selectedArticleIDs = selectedArticles.articleIDs() + var unsortedArticles = fetchUnsortedArticles(for: representedObjects) + unsortedArticles.formUnion(Set(articles)) + updateArticles(with: unsortedArticles) selectArticles(selectedArticleIDs) } func selectArticles(_ articleIDs: [String]) { -// let indexesToSelect = indexesOf(articleIDs) -// if indexesToSelect.isEmpty { -// tableView.deselectAll(self) -// return -// } -// tableView.selectRowIndexes(indexesToSelect, byExtendingSelection: false) + let indexesToSelect = articles.indexesForArticleIDs(Set(articleIDs)) + if indexesToSelect.isEmpty { + tableView.deselectAll(self) + return + } + tableView.selectRowIndexes(indexesToSelect, byExtendingSelection: false) } func invalidateFetchAndMergeArticlesTimer() { diff --git a/Frameworks/Account/Account.swift b/Frameworks/Account/Account.swift index badef1d21..b5abd4bf1 100644 --- a/Frameworks/Account/Account.swift +++ b/Frameworks/Account/Account.swift @@ -129,12 +129,11 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, self.database = Database(databaseFilePath: databaseFilePath, accountID: accountID) NotificationCenter.default.addObserver(self, selector: #selector(downloadProgressDidChange(_:)), name: .DownloadProgressDidChange, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(unreadCountDidChange(_:)), name: .UnreadCountDidChange, object: nil) - - NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(batchUpdateDidPerform(_:)), name: .BatchUpdateDidPerform, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(feedSettingDidChange(_:)), name: .FeedSettingDidChange, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(displayNameDidChange(_:)), name: .DisplayNameDidChange, object: nil) pullObjectsFromDisk() @@ -438,6 +437,16 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, } } + @objc func displayNameDidChange(_ note: Notification) { + + if let feed = note.object as? Feed, let feedAccount = feed.account, feedAccount === self { + dirty = true + } + if let folder = note.object as? Folder, let folderAccount = folder.account, folderAccount === self { + dirty = true + } + } + // MARK: - Equatable public class func ==(lhs: Account, rhs: Account) -> Bool { diff --git a/Frameworks/Account/Container.swift b/Frameworks/Account/Container.swift index 31bf9d810..344e785a7 100644 --- a/Frameworks/Account/Container.swift +++ b/Frameworks/Account/Container.swift @@ -11,7 +11,7 @@ import Foundation import RSCore import Data -extension NSNotification.Name { +extension Notification.Name { public static let ChildrenDidChange = Notification.Name("ChildrenDidChange") } diff --git a/Frameworks/Account/Folder.swift b/Frameworks/Account/Folder.swift index fbdd67883..f454eb2e9 100644 --- a/Frameworks/Account/Folder.swift +++ b/Frameworks/Account/Folder.swift @@ -14,7 +14,13 @@ public final class Folder: DisplayNameProvider, Container, UnreadCountProvider, public weak var account: Account? public var children = [AnyObject]() - public private(set) var name: String? + + public var name: String? { + didSet { + postDisplayNameDidChangeNotification() + } + } + static let untitledName = NSLocalizedString("Untitled ƒ", comment: "Folder name") public let folderID: Int // not saved: per-run only static var incrementingID = 0 diff --git a/Frameworks/Data/Feed.swift b/Frameworks/Data/Feed.swift index 750d01c6a..c634537e3 100644 --- a/Frameworks/Data/Feed.swift +++ b/Frameworks/Data/Feed.swift @@ -20,7 +20,13 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { public var faviconURL: String? public var name: String? public var authors: Set? - public var editedName: String? + + public var editedName: String? { + didSet { + postDisplayNameDidChangeNotification() + } + } + public var conditionalGetInfo: HTTPConditionalGetInfo? public var contentHash: String? public let hashValue: Int @@ -29,7 +35,13 @@ public final class Feed: DisplayNameProvider, UnreadCountProvider, Hashable { public var nameForDisplay: String { get { - return (editedName ?? name) ?? NSLocalizedString("Untitled", comment: "Feed name") + if let s = editedName, !s.isEmpty { + return s + } + if let s = name, !s.isEmpty { + return s + } + return NSLocalizedString("Untitled", comment: "Feed name") } } diff --git a/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj b/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj index 4f8276b12..e6522dba7 100755 --- a/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj +++ b/Frameworks/RSCore/RSCore.xcodeproj/project.pbxproj @@ -157,11 +157,6 @@ 84CFF56D1AC3D20A00CEA6C8 /* NSImage+RSCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 84CFF56B1AC3D20A00CEA6C8 /* NSImage+RSCore.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84CFF56E1AC3D20A00CEA6C8 /* NSImage+RSCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 84CFF56C1AC3D20A00CEA6C8 /* NSImage+RSCore.m */; }; 84E34DA61F9FA1070077082F /* UndoableCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E34DA51F9FA1070077082F /* UndoableCommand.swift */; }; - 84E72E151FBD647500B873C1 /* InspectorItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E72E101FBD647500B873C1 /* InspectorItem.swift */; }; - 84E72E161FBD647500B873C1 /* InspectorItemContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E72E111FBD647500B873C1 /* InspectorItemContainerView.swift */; }; - 84E72E171FBD647500B873C1 /* InspectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E72E121FBD647500B873C1 /* InspectorView.swift */; }; - 84E72E181FBD647500B873C1 /* InspectorWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84E72E131FBD647500B873C1 /* InspectorWindow.xib */; }; - 84E72E191FBD647500B873C1 /* InspectorWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E72E141FBD647500B873C1 /* InspectorWindowController.swift */; }; 84F20F831F16BA6200D8E682 /* PropertyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F20F821F16BA6200D8E682 /* PropertyList.swift */; }; 84FE9FC31C00453900081CE9 /* NSStoryboard+RSCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 84FE9FC11C00453900081CE9 /* NSStoryboard+RSCore.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84FE9FC41C00453900081CE9 /* NSStoryboard+RSCore.m in Sources */ = {isa = PBXBuildFile; fileRef = 84FE9FC21C00453900081CE9 /* NSStoryboard+RSCore.m */; }; @@ -279,11 +274,6 @@ 84CFF56B1AC3D20A00CEA6C8 /* NSImage+RSCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSImage+RSCore.h"; sourceTree = ""; }; 84CFF56C1AC3D20A00CEA6C8 /* NSImage+RSCore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSImage+RSCore.m"; sourceTree = ""; }; 84E34DA51F9FA1070077082F /* UndoableCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UndoableCommand.swift; path = RSCore/UndoableCommand.swift; sourceTree = ""; }; - 84E72E101FBD647500B873C1 /* InspectorItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InspectorItem.swift; sourceTree = ""; }; - 84E72E111FBD647500B873C1 /* InspectorItemContainerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InspectorItemContainerView.swift; sourceTree = ""; }; - 84E72E121FBD647500B873C1 /* InspectorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InspectorView.swift; sourceTree = ""; }; - 84E72E131FBD647500B873C1 /* InspectorWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InspectorWindow.xib; sourceTree = ""; }; - 84E72E141FBD647500B873C1 /* InspectorWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InspectorWindowController.swift; sourceTree = ""; }; 84F20F821F16BA6200D8E682 /* PropertyList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyList.swift; sourceTree = ""; }; 84FE9FC11C00453900081CE9 /* NSStoryboard+RSCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStoryboard+RSCore.h"; sourceTree = ""; }; 84FE9FC21C00453900081CE9 /* NSStoryboard+RSCore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSStoryboard+RSCore.m"; sourceTree = ""; }; @@ -363,7 +353,6 @@ 844B5B561FE9D36000C7C76A /* Keyboard.swift */, 84CFF5241AC3C8A200CEA6C8 /* Foundation */, 84CFF5551AC3CF4A00CEA6C8 /* AppKit */, - 84E72E0F1FBD647500B873C1 /* Inspector */, 84CFF5661AC3D13F00CEA6C8 /* Images */, 84CFF4F81AC3C69700CEA6C8 /* Info.plist */, 84CFF5031AC3C69700CEA6C8 /* RSCoreTests */, @@ -494,19 +483,6 @@ path = RSCore; sourceTree = ""; }; - 84E72E0F1FBD647500B873C1 /* Inspector */ = { - isa = PBXGroup; - children = ( - 84E72E131FBD647500B873C1 /* InspectorWindow.xib */, - 84E72E141FBD647500B873C1 /* InspectorWindowController.swift */, - 84E72E121FBD647500B873C1 /* InspectorView.swift */, - 84E72E111FBD647500B873C1 /* InspectorItemContainerView.swift */, - 84E72E101FBD647500B873C1 /* InspectorItem.swift */, - ); - name = Inspector; - path = RSCore/Inspector; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -697,7 +673,6 @@ files = ( 84C687301FBAA30800345C9E /* LogWindow.xib in Resources */, 8479213C1FBA426B004AD08C /* WebViewWindow.xib in Resources */, - 84E72E181FBD647500B873C1 /* InspectorWindow.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -760,7 +735,6 @@ 849BF8BA1C9130150071D1DA /* DiskSaver.swift in Sources */, 84FE9FC41C00453900081CE9 /* NSStoryboard+RSCore.m in Sources */, 84CFF5341AC3CB6800CEA6C8 /* NSDictionary+RSCore.m in Sources */, - 84E72E161FBD647500B873C1 /* InspectorItemContainerView.swift in Sources */, 84CFF54C1AC3CDAC00CEA6C8 /* NSString+RSCore.m in Sources */, 84CFF5171AC3C73000CEA6C8 /* RSConstants.m in Sources */, 8432B1881DACA2060057D6DF /* NSWindow-Extensions.swift in Sources */, @@ -788,7 +762,6 @@ 84CFF5301AC3CB1900CEA6C8 /* NSDate+RSCore.m in Sources */, 84CFF5281AC3C9A200CEA6C8 /* NSArray+RSCore.m in Sources */, 84C632A1200D30F1007BEEAA /* NSAppleEventDescriptor+RSCore.m in Sources */, - 84E72E171FBD647500B873C1 /* InspectorView.swift in Sources */, 84CFF5591AC3CF9100CEA6C8 /* NSView+RSCore.m in Sources */, 84CFF56A1AC3D1B000CEA6C8 /* RSScaling.m in Sources */, 84FEB4AC1D19D7F4004727E5 /* Date+Extensions.swift in Sources */, @@ -803,11 +776,9 @@ 844C915C1B65753E0051FC1B /* RSPlist.m in Sources */, 84CFF5231AC3C89D00CEA6C8 /* NSObject+RSCore.m in Sources */, 8414CBA71C95F2EA00333C12 /* Set+Extensions.swift in Sources */, - 84E72E191FBD647500B873C1 /* InspectorWindowController.swift in Sources */, 84B99C9A1FAE650100ECDEDB /* OPMLRepresentable.swift in Sources */, 84E34DA61F9FA1070077082F /* UndoableCommand.swift in Sources */, 844F91D61D90D86100820C48 /* RSTransparentContainerView.m in Sources */, - 84E72E151FBD647500B873C1 /* InspectorItem.swift in Sources */, 84CFF56E1AC3D20A00CEA6C8 /* NSImage+RSCore.m in Sources */, 8453F7DF1BDF337800B1C8ED /* RSMacroProcessor.m in Sources */, 842E45CC1ED623C7000A8B52 /* UniqueIdentifier.swift in Sources */, diff --git a/Frameworks/RSCore/RSCore/DisplayNameProvider.swift b/Frameworks/RSCore/RSCore/DisplayNameProvider.swift index 35853931e..832b3ef15 100644 --- a/Frameworks/RSCore/RSCore/DisplayNameProvider.swift +++ b/Frameworks/RSCore/RSCore/DisplayNameProvider.swift @@ -8,8 +8,21 @@ import Foundation +extension Notification.Name { + + public static let DisplayNameDidChange = Notification.Name("DisplayNameDidChange") +} + + public protocol DisplayNameProvider { var nameForDisplay: String { get } } +public extension DisplayNameProvider { + + func postDisplayNameDidChangeNotification() { + + NotificationCenter.default.post(name: .DisplayNameDidChange, object: self, userInfo: nil) + } +} diff --git a/Frameworks/RSCore/RSCore/Inspector/InspectorItem.swift b/Frameworks/RSCore/RSCore/Inspector/InspectorItem.swift deleted file mode 100644 index a14d4a9ea..000000000 --- a/Frameworks/RSCore/RSCore/Inspector/InspectorItem.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// InspectorItem.swift -// Evergreen -// -// Created by Brent Simmons on 11/15/17. -// Copyright © 2017 Ranchero Software. All rights reserved. -// - -import Foundation - -protocol InspectorItem: class { - - var localizedTitle: String { get } - var view: NSView { get } - var inspectedObjects: [Any]? { get set } - var expanded: Bool { get set } - - func canInspect(_ objects: [Any]) -> Bool -} diff --git a/Frameworks/RSCore/RSCore/Inspector/InspectorItemContainerView.swift b/Frameworks/RSCore/RSCore/Inspector/InspectorItemContainerView.swift deleted file mode 100644 index 586d0a944..000000000 --- a/Frameworks/RSCore/RSCore/Inspector/InspectorItemContainerView.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// InspectorItemContainerView.swift -// Evergreen -// -// Created by Brent Simmons on 11/15/17. -// Copyright © 2017 Ranchero Software. All rights reserved. -// - -import Cocoa - - -class InspectorItemContainerView: NSView { - - override func draw(_ dirtyRect: NSRect) { - super.draw(dirtyRect) - - // Drawing code here. - } - -} diff --git a/Frameworks/RSCore/RSCore/Inspector/InspectorView.swift b/Frameworks/RSCore/RSCore/Inspector/InspectorView.swift deleted file mode 100644 index f289abdb2..000000000 --- a/Frameworks/RSCore/RSCore/Inspector/InspectorView.swift +++ /dev/null @@ -1,29 +0,0 @@ -// -// InspectorView.swift -// Evergreen -// -// Created by Brent Simmons on 11/15/17. -// Copyright © 2017 Ranchero Software. All rights reserved. -// - -import Cocoa - -// The content view for the window. -// -// InspectorWindow -// InspectorView -// InspectorItemContainerView -// NSView (inspector item) -// InspectorItemContainerView -// NSView (inspector item) -// etc. - -class InspectorView: NSView { - - override func draw(_ dirtyRect: NSRect) { - super.draw(dirtyRect) - - // Drawing code here. - } - -} diff --git a/Frameworks/RSCore/RSCore/Inspector/InspectorWindow.xib b/Frameworks/RSCore/RSCore/Inspector/InspectorWindow.xib deleted file mode 100644 index f9d5105db..000000000 --- a/Frameworks/RSCore/RSCore/Inspector/InspectorWindow.xib +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Frameworks/RSCore/RSCore/Inspector/InspectorWindowController.swift b/Frameworks/RSCore/RSCore/Inspector/InspectorWindowController.swift deleted file mode 100644 index 5ea9b33fa..000000000 --- a/Frameworks/RSCore/RSCore/Inspector/InspectorWindowController.swift +++ /dev/null @@ -1,23 +0,0 @@ -// -// InspectorWindowController.swift -// Evergreen -// -// Created by Brent Simmons on 11/15/17. -// Copyright © 2017 Ranchero Software. All rights reserved. -// - -import Cocoa - -public class InspectorWindowController: NSWindowController { - - public var isOpen: Bool { - get { - return isWindowLoaded && window!.isVisible - } - } - - public convenience init() { - - self.init(windowNibName: NSNib.Name(rawValue: "InspectorWindow")) - } -} diff --git a/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift b/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift index 400f00ddf..2a5dc898f 100755 --- a/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift +++ b/Frameworks/RSCore/RSCore/NSWindow-Extensions.swift @@ -45,4 +45,45 @@ public extension NSWindow { setFrame(frame, display: true) setFrameTopLeftPoint(frame.origin) } + + public var flippedOrigin: NSPoint? { + + // Screen coordinates start at lower-left. + // With this we can use upper-left, like sane people. + + get { + guard let screenFrame = screen?.frame else { + return nil + } + + let flippedPoint = NSPoint(x: frame.origin.x, y: screenFrame.maxY - frame.maxY) + return flippedPoint + } + set { + guard let screenFrame = screen?.frame else { + return + } + var point = newValue! + point.y = screenFrame.maxY - point.y + setFrameTopLeftPoint(point) + } + } + + public func setFlippedOriginAdjustingForScreen(_ point: NSPoint) { + + guard let screenFrame = screen?.frame else { + return + } + + let paddingFromEdge: CGFloat = 8.0 + var unflippedPoint = point + unflippedPoint.y = (screenFrame.maxY - point.y) - frame.height + if unflippedPoint.y < 0 { + unflippedPoint.y = paddingFromEdge + } + if unflippedPoint.x < 0 { + unflippedPoint.x = paddingFromEdge + } + setFrameOrigin(unflippedPoint) + } } diff --git a/Frameworks/RSTree/RSTree/Node.swift b/Frameworks/RSTree/RSTree/Node.swift index d0053f6ce..e91c56983 100644 --- a/Frameworks/RSTree/RSTree/Node.swift +++ b/Frameworks/RSTree/RSTree/Node.swift @@ -190,3 +190,11 @@ public func ==(lhs: Node, rhs: Node) -> Bool { return lhs === rhs } + +public extension Array where Element == Node { + + public func representedObjects() -> [AnyObject] { + + return self.map{ $0.representedObject } + } +} diff --git a/Technotes/CodingGuidelines.md b/Technotes/CodingGuidelines.md new file mode 100644 index 000000000..3d58962d7 --- /dev/null +++ b/Technotes/CodingGuidelines.md @@ -0,0 +1,161 @@ +# Coding Guidelines + +Evergreen’s coding values are, in order: + +* No data loss +* No crashes +* No other bugs +* Fast performance +* Developer productivity + +These are not in opposition to each other: they work together. + +The last one should be of particular interest: work often happens in small bursts, and anyone should be able to make progress on something in 15 minutes. + +While making a great app is more important than being productive, being productive is a hugely important part — often underestimated — of making a great app. + +### Problem solving + +You’ve seen how, in Auto Layout, there is a content compression resistance priority and a content hugging priority? + +That’s how we think about problems: the problem compression resistance priority is at max, and the problem hugging priority is also at max. + +In other words: solve the problem. Not less than the problem, but not more than the problem — don’t over-generalize. + +Similarly: always work at the highest level possible, but not higher and certainly not lower. + +### Language + +Write new code in Swift 4. + +The one exception to this is when dealing with C APIs, which are often much easier to deal with in Objective-C than in Swift. Still, though, this is rare, and is much more likely to be needed in a lower-level framework such as RSParser — it shouldn’t happen at the app level. + +Swift code should be “pure” Swift as much as possible: avoid `@objc` except when needed for working with AppKit and other APIs. + +Functions should tend to be small. One-liners are a-okay, especially when the function name explains intent more clearly than that one line. + +We mostly avoid Swift generics, since generics is an advanced feature that can be relatively hard to understand. We *do* use them, though, when appropriate. + +We use assertions and preconditions (assertions are hit only when running a debug build; preconditions will crash a release build). We also allow force-unwrapping of optionals as a shorthand for a precondition failure, though these should be used sparingly. + +Extensions, including private extensions, are used — though we take care not to extend Foundation and AppKit objects too much, lest we end up with our own Cocoa dialect. + +Things should be marked private as often as possible. APIs should be exactly what’s needed and not more. + +#### Code organization + +Properties go at the top, then functions. + +Then extensions for protocol conformances. Then a private extension for any private functions. + +Use `// MARK:` as appropriate. + +### Composition + +#### No subclasses + +Subclassing is inevitable — there’s no way out of subclassing things like `NSView` and `NSViewController`, because that’s how AppKit works. + +But in all the rest of Evergreen, frameworks included, you’d have a hard time finding a class that was designed to be subclassed. It’s rare enough that one would have to look pretty hard to find an example, if there is one at all. + +Consider this a hard rule: all Swift classes must be marked as `final`, and all Objective-C classes must be treated as if they were so marked. + +#### Protocols and delegates + +Protocols and delegates (which are also protocol-conforming) are preferred. + +Default implementations in protocols are allowed but ever-so-slightly discouraged. You’ll find several instances in the code, but this is done carefully — we don’t want this to be just another form of inheritance, where you find that you have to bounce back-and-forth between files to figure out what’s going on. + +There is one unfortunate case about protocols to note: in Swift you can’t create a Set of some protocol-conforming objects, and we use sets frequently. In those situations another solution — such as a thin object with a delegate — might be better. + +#### Small objects + +Giant objects with thousands of lines of code are to be avoided. Prefer multiple small objects. It’s easier to focus on a small problem, and small objects are easier to maintain and compose with other objects. + +That said, don’t break up a larger object arbitrarily just because it’s large. It may be the honest answer (and it may not be). There should be a logic and reason to the smaller objects. + +#### Code repetition + +This policy of no-subclasses can lead to some code repetition, or almost-repetition. In small doses, that’s fine, and is better than the alternatives — which tend to be complexifying. + +But in larger doses some redesign is needed. It is often the case that breaking up the problem into smaller objects (see above) can solve the repetition problem. + +### Model objects + +Model objects are plain old objects. We don’t use Core Data or any other system that requires subclassing. + +Immutable Swift structs are strongly preferred. They’re worth a little standing-on-your-head to get them — but only a little. Otherwise, use a mutable struct or reference-type object, depending on needs. + +### Frameworks + +#### Built-in + +Don’t fight the built-in frameworks and don’t try to hide them. Let’s not write our own Cocoa dialect. + +#### Ours + +Evergreen is layered into frameworks. There’s an app level and a bunch of frameworks below that. Each framework has its own reason for being. Dependencies between frameworks should be as minimal as possible, but those dependencies do exist. + +Some frameworks are not permitted to add dependencies, and should be treated as at the bottom of the cake: RSCore, RSWeb, RSDatabase, RSParser, RSTree, and DB5. This simplifies things for us, and makes it easier for us and other people to use these frameworks in other apps. + +### User Interface + +Stick to stock elements, since this tends to eliminate bugs and future churn. This isn’t always possible, of course, but any custom work should be the minimum possible. We’re in this for the long haul. + +Storyboards are preferred to xibs — except when the problem is xib-sized. + +Use DB5 where parameters (sizes, colors, etc.) are needed. + +Auto layout is used everywhere except in table and outline view cells, where performance is critical. + +Stack views are not allowed in table and outline view cells, but they can be useful elsewhere. However, care must be taken that performance (of window resizing, for instance) is not affected. When it is, don’t use a stack view. + +Use nil-targeted actions and the responder chain when appropriate. + +Use Cocoa bindings extremely rarely — for a checkbox in a preferences window, for instance. + +### Notifications and Bindings + +Key-Value Observing (KVO) is entirely forbidden. KVO is where the crashing bugs live. (The only possible exception to this is when an Apple API requires KVO, which is rare.) + +`NSArrayController` and similar are never used. Binding via code is also not done. + +Instead, we use NotificationCenter notifications, and we use Swift’s `didSet` method on accessors. + +All notifications must be posted on the main queue. + +### Threading + +Everything happens on the main thread. Period. + +Well, no, not exactly. *Almost* everything happens on the main thread. + +The exceptions are things that can be perfectly isolated, such as parsing an RSS feed or fetching from the database. We use `DispatchQueue` to run those in the background, often on a serial queue. + +Those things must run without locks — locks are almost completely unused in Evergreen. + +Any time a background task with a callback is finished, it must call back on the main queue (except for completely private cases, and then it must be noted in the code). + +If this policy leads to a design that blocks the main thread unacceptably, then that design must be re-thought. Ask for help if needed. + +### Cleanliness + +No code that triggers compiler errors or even warnings may be checked in. + +No code that writes to the console may be checked in — console spew is not allowed. + +### Profiling + +Use Instruments to look for leaks and to do profiling. Instruments is great at finding where the problems actually are, as opposed to where you think they are. + +No shipping version gets released without looking for memory leaks. + +### Version Control + +Every commit message should begin with a present-tense verb. + +### Last Thing + +Don’t show off. If your code looks like kindergarten code, then _good_. + +Points are granted for not trying to amass points. diff --git a/Technotes/README.md b/Technotes/README.md index db70507e6..f90fd0522 100644 --- a/Technotes/README.md +++ b/Technotes/README.md @@ -13,3 +13,7 @@ [Hidden Preferences](HiddenPrefs.md) [Questions Answered](QuestionsAnswered.md) + +## Contributing + +[Coding Guidelines](CodingGuidelines.md)