2024-02-27 19:19:25 +03:00
|
|
|
//
|
|
|
|
// ShareTableItemView.swift
|
|
|
|
// FileProviderUIExt
|
|
|
|
//
|
|
|
|
// Created by Claudio Cambra on 28/2/24.
|
|
|
|
//
|
|
|
|
|
2024-02-27 19:20:05 +03:00
|
|
|
import AppKit
|
2024-02-28 11:01:01 +03:00
|
|
|
import NextcloudKit
|
2024-02-27 19:20:05 +03:00
|
|
|
|
|
|
|
class ShareTableItemView: NSTableCellView {
|
2024-02-28 11:01:01 +03:00
|
|
|
@IBOutlet private weak var typeImageView: NSImageView!
|
|
|
|
@IBOutlet private weak var label: NSTextField!
|
|
|
|
@IBOutlet private weak var copyLinkButton: NSButton!
|
|
|
|
@IBOutlet private weak var optionsButton: NSButton!
|
2024-02-28 11:47:48 +03:00
|
|
|
@IBOutlet private weak var popover: NSPopover!
|
|
|
|
@IBOutlet private weak var popoverContentViewController: NSViewController!
|
2024-02-28 11:36:15 +03:00
|
|
|
private var originalCopyImage: NSImage?
|
|
|
|
private var copiedButtonImage: NSImage?
|
|
|
|
private var tempButtonTimer: Timer?
|
2024-02-28 11:01:01 +03:00
|
|
|
|
|
|
|
var share: NKShare? {
|
|
|
|
didSet {
|
|
|
|
guard let share = share else {
|
|
|
|
prepareForReuse()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
typeImageView.image = share.typeImage
|
|
|
|
label.stringValue = share.displayString
|
|
|
|
copyLinkButton.isHidden = share.shareType != NKShare.ShareType.publicLink.rawValue
|
|
|
|
}
|
|
|
|
}
|
2024-02-28 09:54:57 +03:00
|
|
|
|
|
|
|
override func prepareForReuse() {
|
|
|
|
typeImageView.image = nil
|
|
|
|
label.stringValue = ""
|
|
|
|
copyLinkButton.isHidden = false
|
|
|
|
super.prepareForReuse()
|
|
|
|
}
|
2024-02-28 11:35:57 +03:00
|
|
|
|
|
|
|
@IBAction func copyShareLink(sender: Any) {
|
|
|
|
guard let share = share else { return }
|
|
|
|
let pasteboard = NSPasteboard.general
|
|
|
|
pasteboard.declareTypes([.string], owner: nil)
|
|
|
|
pasteboard.setString(share.url, forType: .string)
|
2024-02-28 11:36:15 +03:00
|
|
|
|
|
|
|
guard tempButtonTimer == nil else { return }
|
|
|
|
|
|
|
|
originalCopyImage = copyLinkButton.image
|
|
|
|
copiedButtonImage = NSImage(
|
|
|
|
systemSymbolName: "checkmark.circle.fill",
|
|
|
|
accessibilityDescription: "Public link has been copied icon"
|
|
|
|
)
|
|
|
|
var config = NSImage.SymbolConfiguration(scale: .medium)
|
|
|
|
if #available(macOS 12.0, *) {
|
|
|
|
config = config.applying(.init(hierarchicalColor: .systemGreen))
|
|
|
|
}
|
|
|
|
copiedButtonImage = copiedButtonImage?.withSymbolConfiguration(config)
|
|
|
|
copyLinkButton.image = copiedButtonImage
|
|
|
|
tempButtonTimer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { timer in
|
|
|
|
self.copyLinkButton.image = self.originalCopyImage
|
|
|
|
self.copiedButtonImage = nil
|
|
|
|
self.tempButtonTimer?.invalidate()
|
|
|
|
self.tempButtonTimer = nil
|
|
|
|
}
|
2024-02-28 11:35:57 +03:00
|
|
|
}
|
2024-02-27 19:20:05 +03:00
|
|
|
}
|