diff --git a/AppKitExtras/Sources/AppKitExtras/AppKitExtras.swift b/AppKitExtras/Sources/AppKitExtras/AppKitExtras.swift deleted file mode 100644 index 08b22b80f..000000000 --- a/AppKitExtras/Sources/AppKitExtras/AppKitExtras.swift +++ /dev/null @@ -1,2 +0,0 @@ -// The Swift Programming Language -// https://docs.swift.org/swift-book diff --git a/AppKitExtras/Sources/AppKitExtras/NSAppearance+RSCore.swift b/AppKitExtras/Sources/AppKitExtras/NSAppearance+RSCore.swift index fd2ed73de..3ad3d1f6e 100644 --- a/AppKitExtras/Sources/AppKitExtras/NSAppearance+RSCore.swift +++ b/AppKitExtras/Sources/AppKitExtras/NSAppearance+RSCore.swift @@ -11,7 +11,6 @@ import AppKit extension NSAppearance { - @objc(rsIsDarkMode) public var isDarkMode: Bool { if #available(macOS 10.14, *) { return self.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua diff --git a/AppKitExtras/Sources/AppKitExtras/NSOutlineView+RSCore.swift b/AppKitExtras/Sources/AppKitExtras/NSOutlineView+RSCore.swift index a16152fba..c84ebe336 100755 --- a/AppKitExtras/Sources/AppKitExtras/NSOutlineView+RSCore.swift +++ b/AppKitExtras/Sources/AppKitExtras/NSOutlineView+RSCore.swift @@ -164,20 +164,5 @@ public extension NSOutlineView { let isSelectable = delegate?.outlineView?(self, shouldSelectItem: item) ?? true return isSelectable } - - func selectItemAndScrollToVisible(_ item: Any) { - - guard canSelectItem(item) else { - return - } - - let rowToSelect = row(forItem: item) - guard rowToSelect != -1 else { - return - } - - selectRowAndScrollToVisible(rowToSelect) - } } #endif - diff --git a/AppKitExtras/Sources/AppKitExtras/NSView+RSCore.swift b/AppKitExtras/Sources/AppKitExtras/NSView+RSCore.swift index 5ea65ccd6..086648d5d 100644 --- a/AppKitExtras/Sources/AppKitExtras/NSView+RSCore.swift +++ b/AppKitExtras/Sources/AppKitExtras/NSView+RSCore.swift @@ -19,7 +19,6 @@ extension NSView { img.addRepresentation(rep) return img } - } public extension NSView { @@ -44,56 +43,5 @@ public extension NSView { self.frame = rect } } - - /// A boolean indicating whether the view is or is descended from the first responder. - var isOrIsDescendedFromFirstResponder: Bool { - guard let firstResponder = self.window?.firstResponder as? NSView else { - return false - } - - return self.isDescendant(of: firstResponder) - } - - /// A boolean indicating whether the view should draw as active. - var shouldDrawAsActive: Bool { - return (self.window?.isMainWindow ?? false) && self.isOrIsDescendedFromFirstResponder - } - - /// Vertically centers a rectangle in the view's bounds. - /// - Parameter rect: The rectangle to center. - /// - Returns: A new rectangle, vertically centered in the view's bounds. - func verticallyCenteredRect(_ rect: NSRect) -> NSRect { - return rect.centeredVertically(in: self.bounds) - } - - /// Horizontally centers a rectangle in the view's bounds. - /// - Parameter rect: The rectangle to center. - /// - Returns: A new rectangle, horizontally centered in the view's bounds. - func horizontallyCenteredRect(_ rect: NSRect) -> NSRect { - return rect.centeredHorizontally(in: self.bounds) - } - - /// Centers a rectangle in the view's bounds. - /// - Parameter rect: The rectangle to center. - /// - Returns: A new rectangle, both horizontally and vertically centered in the view's bounds. - func centeredRect(_ rect: NSRect) -> NSRect { - return rect.centered(in: self.bounds) - } - - /// The view's enclosing table view, if any. - var enclosingTableView: NSTableView? { - var nomad = self.superview - - while nomad != nil { - if let nomad = nomad as? NSTableView { - return nomad - } - - nomad = nomad!.superview - } - - return nil - } - } #endif diff --git a/AppKitExtras/Sources/AppKitExtras/NSWorkspace+RSCore.swift b/AppKitExtras/Sources/AppKitExtras/NSWorkspace+RSCore.swift deleted file mode 100644 index 4c594d6de..000000000 --- a/AppKitExtras/Sources/AppKitExtras/NSWorkspace+RSCore.swift +++ /dev/null @@ -1,77 +0,0 @@ -// -// NSWorkspace+RSCore.swift -// RSCore -// -// Created by Brent Simmons on 9/3/18. -// Copyright © 2018 Ranchero Software, LLC. All rights reserved. -// -#if os(macOS) -import AppKit - -public extension NSWorkspace { - - /// Get the file path to the default app for a given scheme such as "feed:" - func defaultApp(forURLScheme scheme: String) -> String? { - guard let url = URL(string: scheme) else { - return nil - } - return urlForApplication(toOpen: url)?.path - } - - /// Get the bundle ID for the default app for a given scheme such as "feed:" - func defaultAppBundleID(forURLScheme scheme: String) -> String? { - guard let path = defaultApp(forURLScheme: scheme) else { - return nil - } - return bundleID(for: path) - } - - /// Set the file path that should be the default app for a given scheme such as "feed:" - /// It really just uses the bundle ID for the app, so there’s no guarantee that the actual path will be respected later. - /// (In other words, you can’t specify one app over another if they have the same bundle ID.) - @discardableResult - func setDefaultApp(forURLScheme scheme: String, to path: String) -> Bool { - guard let bundleID = bundleID(for: path) else { - return false - } - return setDefaultAppBundleID(forURLScheme: scheme, to: bundleID) - } - - /// Set the bundle ID for the app that should be default for a given scheme such as "feed:" - @discardableResult - func setDefaultAppBundleID(forURLScheme scheme: String, to bundleID: String) -> Bool { - return LSSetDefaultHandlerForURLScheme(scheme as CFString, bundleID as CFString) == noErr - } - - /// Get the file paths to apps that can handle a given scheme such as "feed:" - func apps(forURLScheme scheme: String) -> Set { - guard let url = URL(string: scheme) else { - return Set() - } - guard let appURLs = LSCopyApplicationURLsForURL(url as CFURL, .viewer)?.takeRetainedValue() as [AnyObject]? else { - return Set() - } - let appPaths = appURLs.compactMap { (item) -> String? in - guard let url = item as? URL else { - return nil - } - return url.path - } - return Set(appPaths) - } - - /// Get the bundle IDs for apps that can handle a given scheme such as "feed:" - func bundleIDsForApps(forURLScheme scheme: String) -> Set { - let appPaths = apps(forURLScheme: scheme) - let bundleIDs = appPaths.compactMap { (path) -> String? in - return bundleID(for: path) - } - return Set(bundleIDs) - } - - /// Get the bundle ID for an app at a path. - func bundleID(for path: String) -> String? { - return Bundle(path: path)?.bundleIdentifier - } -} -#endif diff --git a/AppKitExtras/Sources/AppKitExtras/RSDarkModeAdaptingToolbarButton.swift b/AppKitExtras/Sources/AppKitExtras/RSDarkModeAdaptingToolbarButton.swift deleted file mode 100644 index be10f3bea..000000000 --- a/AppKitExtras/Sources/AppKitExtras/RSDarkModeAdaptingToolbarButton.swift +++ /dev/null @@ -1,41 +0,0 @@ -// -// RSDarkModeAdaptingToolbarButton.swift -// RSCore -// -// Created by Daniel Jalkut on 8/28/18. -// Copyright © 2018 Ranchero Software, LLC. All rights reserved. -// -#if os(macOS) -import AppKit - -class RSDarkModeAdaptingToolbarButton: NSButton { - // Clients probably should not bother using this class unless they want - // to force the template in dark mode, but if you are using this in a more - // general context where you want to control and/or override it on a - // case-by-case basis, set this to false to avoid the templating behavior. - public var forceTemplateInDarkMode: Bool = true - var originalImageTemplateState: Bool = false - - public convenience init(image: NSImage, target: Any?, action: Selector?, forceTemplateInDarkMode: Bool = false) { - self.init(image: image, target: target, action: action) - self.forceTemplateInDarkMode = forceTemplateInDarkMode - } - - override func layout() { - // Always re-set the NSImage template state based on the current dark mode setting - if #available(macOS 10.14, *) { - if self.forceTemplateInDarkMode, let targetImage = self.image { - var newTemplateState: Bool = self.originalImageTemplateState - - if self.effectiveAppearance.isDarkMode { - newTemplateState = true - } - - targetImage.isTemplate = newTemplateState - } - } - - super.layout() - } -} -#endif