Remove unused code in AppKitExtras.

This commit is contained in:
Brent Simmons 2024-03-20 21:51:20 -07:00
parent 21ca4fe0aa
commit c911a3b257
6 changed files with 0 additions and 188 deletions

View File

@ -1,2 +0,0 @@
// The Swift Programming Language
// https://docs.swift.org/swift-book

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 theres no guarantee that the actual path will be respected later.
/// (In other words, you cant 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<String> {
guard let url = URL(string: scheme) else {
return Set<String>()
}
guard let appURLs = LSCopyApplicationURLsForURL(url as CFURL, .viewer)?.takeRetainedValue() as [AnyObject]? else {
return Set<String>()
}
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<String> {
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

View File

@ -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