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
|
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"]
|
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)
|
super.init(frame: .zero)
|
||||||
bezelStyle = .rounded
|
bezelStyle = .rounded
|
||||||
title = "DRAG FILE TO HERE"
|
title = givenTitle ?? "DRAG FILE TO HERE"
|
||||||
registerForDraggedTypes([.init(rawValue: kUTTypeFileURL as String)])
|
registerForDraggedTypes([.kUTTypeFileURL])
|
||||||
target = self
|
self.target = target ?? self
|
||||||
|
self.action = action
|
||||||
|
postDragHandler = postDrag ?? postDragHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
|
@ -478,7 +499,7 @@ public extension NSMenuItem {
|
||||||
|
|
||||||
fileprivate func checkExtension(_ drag: NSDraggingInfo) -> Bool {
|
fileprivate func checkExtension(_ drag: NSDraggingInfo) -> Bool {
|
||||||
guard let pasteboard = drag.draggingPasteboard.propertyList(
|
guard let pasteboard = drag.draggingPasteboard.propertyList(
|
||||||
forType: NSPasteboard.PasteboardType(rawValue: "NSFilenamesPboardType")
|
forType: NSPasteboard.PasteboardType.kNSFilenamesPboardType
|
||||||
) as? [String], let path = pasteboard.first else {
|
) as? [String], let path = pasteboard.first else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -494,7 +515,7 @@ public extension NSMenuItem {
|
||||||
|
|
||||||
override public func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
|
override public func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
|
||||||
guard let pasteboard = sender.draggingPasteboard.propertyList(
|
guard let pasteboard = sender.draggingPasteboard.propertyList(
|
||||||
forType: NSPasteboard.PasteboardType(rawValue: "NSFilenamesPboardType")
|
forType: NSPasteboard.PasteboardType.kNSFilenamesPboardType
|
||||||
) as? [String], let path = pasteboard.first else {
|
) as? [String], let path = pasteboard.first else {
|
||||||
print("failure")
|
print("failure")
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
import AppKit
|
import AppKit
|
||||||
import Foundation
|
import Foundation
|
||||||
import Shared
|
import Shared
|
||||||
import UniformTypeIdentifiers
|
|
||||||
|
|
||||||
public class VwrClientListMgr: NSViewController {
|
public class VwrClientListMgr: NSViewController {
|
||||||
let windowWidth: CGFloat = 770
|
let windowWidth: CGFloat = 770
|
||||||
|
@ -80,7 +79,7 @@ public class VwrClientListMgr: NSViewController {
|
||||||
tblClients.intercellSpacing = CGSize(width: 17, height: 0)
|
tblClients.intercellSpacing = CGSize(width: 17, height: 0)
|
||||||
tblClients.rowHeight = 24
|
tblClients.rowHeight = 24
|
||||||
tblClients.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
tblClients.setContentHuggingPriority(.defaultHigh, for: .vertical)
|
||||||
tblClients.registerForDraggedTypes([.init(rawValue: kUTTypeFileURL as String)])
|
tblClients.registerForDraggedTypes([.kUTTypeFileURL])
|
||||||
tblClients.dataSource = self
|
tblClients.dataSource = self
|
||||||
tblClients.action = #selector(onItemClicked(_:))
|
tblClients.action = #selector(onItemClicked(_:))
|
||||||
tblClients.target = self
|
tblClients.target = self
|
||||||
|
@ -153,7 +152,7 @@ extension VwrClientListMgr {
|
||||||
neta info: NSDraggingInfo, onError: @escaping () -> Void?, handler: (([URL]) -> Void)? = nil
|
neta info: NSDraggingInfo, onError: @escaping () -> Void?, handler: (([URL]) -> Void)? = nil
|
||||||
) {
|
) {
|
||||||
let board = info.draggingPasteboard
|
let board = info.draggingPasteboard
|
||||||
let type = NSPasteboard.PasteboardType(rawValue: kUTTypeApplicationBundle as String)
|
let type = NSPasteboard.PasteboardType.kUTTypeAppBundle
|
||||||
let options: [NSPasteboard.ReadingOptionKey: Any] = [
|
let options: [NSPasteboard.ReadingOptionKey: Any] = [
|
||||||
.urlReadingFileURLsOnly: true,
|
.urlReadingFileURLsOnly: true,
|
||||||
.urlReadingContentsConformToTypes: [type],
|
.urlReadingContentsConformToTypes: [type],
|
||||||
|
|
|
@ -11,7 +11,6 @@ import CocoaExtension
|
||||||
import Shared
|
import Shared
|
||||||
import SwiftExtension
|
import SwiftExtension
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import UniformTypeIdentifiers
|
|
||||||
|
|
||||||
@available(macOS 13, *)
|
@available(macOS 13, *)
|
||||||
public struct VwrSettingsPaneDictionary: View {
|
public struct VwrSettingsPaneDictionary: View {
|
||||||
|
|
Loading…
Reference in New Issue