mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 15:06:08 +03:00
18862bed35
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
67 lines
2.3 KiB
Swift
67 lines
2.3 KiB
Swift
//
|
|
// ShareTableItemView.swift
|
|
// FileProviderUIExt
|
|
//
|
|
// Created by Claudio Cambra on 28/2/24.
|
|
//
|
|
|
|
import AppKit
|
|
import NextcloudKit
|
|
|
|
class ShareTableItemView: NSTableCellView {
|
|
@IBOutlet private weak var typeImageView: NSImageView!
|
|
@IBOutlet private weak var label: NSTextField!
|
|
@IBOutlet private weak var copyLinkButton: NSButton!
|
|
@IBOutlet private weak var optionsButton: NSButton!
|
|
@IBOutlet private weak var popover: NSPopover!
|
|
@IBOutlet private weak var popoverContentViewController: NSViewController!
|
|
private var originalCopyImage: NSImage?
|
|
private var copiedButtonImage: NSImage?
|
|
private var tempButtonTimer: Timer?
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
override func prepareForReuse() {
|
|
typeImageView.image = nil
|
|
label.stringValue = ""
|
|
copyLinkButton.isHidden = false
|
|
super.prepareForReuse()
|
|
}
|
|
|
|
@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)
|
|
|
|
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
|
|
}
|
|
}
|
|
}
|