From 30673976bedc82833642fccccaeeb49858c7e013 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 28 Feb 2024 16:36:15 +0800 Subject: [PATCH] Temporarily change copy share link button image after clicking Signed-off-by: Claudio Cambra --- .../ShareTableItemView.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableItemView.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableItemView.swift index f4af970bdc..375038617c 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableItemView.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderUIExt/ShareTableItemView.swift @@ -13,6 +13,9 @@ class ShareTableItemView: NSTableCellView { @IBOutlet private weak var label: NSTextField! @IBOutlet private weak var copyLinkButton: NSButton! @IBOutlet private weak var optionsButton: NSButton! + private var originalCopyImage: NSImage? + private var copiedButtonImage: NSImage? + private var tempButtonTimer: Timer? var share: NKShare? { didSet { @@ -38,5 +41,25 @@ class ShareTableItemView: NSTableCellView { 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 + } } }