MainAssembly // Refactor wherever using UniformTypeIdentifiers.
This commit is contained in:
parent
55dcdc8ce0
commit
46d4e7bdb3
|
@ -338,3 +338,13 @@ public extension NSApplication {
|
|||
UserDefaults.standard.object(forKey: "AppleAccentColor") != nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Pasteboard Type Extension.
|
||||
|
||||
public extension NSPasteboard.PasteboardType {
|
||||
static let kUTTypeFileURL = Self(rawValue: "public.file-url") // import UniformTypeIdentifiers
|
||||
static let kUTTypeData = Self(rawValue: "public.data") // import UniformTypeIdentifiers
|
||||
static let kUTTypeAppBundle = Self(rawValue: "com.apple.application-bundle") // import UniformTypeIdentifiers
|
||||
static let kUTTypeUTF8PlainText = Self(rawValue: "public.utf8-plain-text")
|
||||
static let kNSFilenamesPboardType = Self(rawValue: "NSFilenamesPboardType")
|
||||
}
|
||||
|
|
|
@ -460,12 +460,33 @@ public extension NSMenuItem {
|
|||
|
||||
var allowedTypes: [String] = ["txt"]
|
||||
|
||||
public init() {
|
||||
public convenience init(
|
||||
_ givenTitle: String? = nil,
|
||||
target: AnyObject? = nil,
|
||||
action: Selector? = nil,
|
||||
postDrag: ((URL) -> Void)? = nil
|
||||
) {
|
||||
self.init(
|
||||
verbatim: givenTitle?.localized,
|
||||
target: target,
|
||||
action: action,
|
||||
postDrag: postDrag
|
||||
)
|
||||
}
|
||||
|
||||
public init(
|
||||
verbatim givenTitle: String? = nil,
|
||||
target: AnyObject? = nil,
|
||||
action: Selector? = nil,
|
||||
postDrag: ((URL) -> Void)? = nil
|
||||
) {
|
||||
super.init(frame: .zero)
|
||||
bezelStyle = .rounded
|
||||
title = "DRAG FILE TO HERE"
|
||||
registerForDraggedTypes([.init(rawValue: kUTTypeFileURL as String)])
|
||||
target = self
|
||||
title = givenTitle ?? "DRAG FILE TO HERE"
|
||||
registerForDraggedTypes([.kUTTypeFileURL])
|
||||
self.target = target ?? self
|
||||
self.action = action
|
||||
postDragHandler = postDrag ?? postDragHandler
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
|
@ -478,7 +499,7 @@ public extension NSMenuItem {
|
|||
|
||||
fileprivate func checkExtension(_ drag: NSDraggingInfo) -> Bool {
|
||||
guard let pasteboard = drag.draggingPasteboard.propertyList(
|
||||
forType: NSPasteboard.PasteboardType(rawValue: "NSFilenamesPboardType")
|
||||
forType: NSPasteboard.PasteboardType.kNSFilenamesPboardType
|
||||
) as? [String], let path = pasteboard.first else {
|
||||
return false
|
||||
}
|
||||
|
@ -494,7 +515,7 @@ public extension NSMenuItem {
|
|||
|
||||
override public func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
|
||||
guard let pasteboard = sender.draggingPasteboard.propertyList(
|
||||
forType: NSPasteboard.PasteboardType(rawValue: "NSFilenamesPboardType")
|
||||
forType: NSPasteboard.PasteboardType.kNSFilenamesPboardType
|
||||
) as? [String], let path = pasteboard.first else {
|
||||
print("failure")
|
||||
return false
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import AppKit
|
||||
import Foundation
|
||||
import Shared
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
public class VwrClientListMgr: NSViewController {
|
||||
let windowWidth: CGFloat = 770
|
||||
|
@ -80,7 +79,7 @@ public class VwrClientListMgr: NSViewController {
|
|||
tblClients.intercellSpacing = CGSize(width: 17, height: 0)
|
||||
tblClients.rowHeight = 24
|
||||
tblClients.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||
tblClients.registerForDraggedTypes([.init(rawValue: kUTTypeFileURL as String)])
|
||||
tblClients.registerForDraggedTypes([.kUTTypeFileURL])
|
||||
tblClients.dataSource = self
|
||||
tblClients.action = #selector(onItemClicked(_:))
|
||||
tblClients.target = self
|
||||
|
@ -153,7 +152,7 @@ extension VwrClientListMgr {
|
|||
neta info: NSDraggingInfo, onError: @escaping () -> Void?, handler: (([URL]) -> Void)? = nil
|
||||
) {
|
||||
let board = info.draggingPasteboard
|
||||
let type = NSPasteboard.PasteboardType(rawValue: kUTTypeApplicationBundle as String)
|
||||
let type = NSPasteboard.PasteboardType.kUTTypeAppBundle
|
||||
let options: [NSPasteboard.ReadingOptionKey: Any] = [
|
||||
.urlReadingFileURLsOnly: true,
|
||||
.urlReadingContentsConformToTypes: [type],
|
||||
|
|
|
@ -11,7 +11,6 @@ import CocoaExtension
|
|||
import Shared
|
||||
import SwiftExtension
|
||||
import SwiftUI
|
||||
import UniformTypeIdentifiers
|
||||
|
||||
@available(macOS 13, *)
|
||||
public struct VwrSettingsPaneDictionary: View {
|
||||
|
|
Loading…
Reference in New Issue