diff --git a/Views/BrowserTab.swift b/Views/BrowserTab.swift index 2b14a98e..b6fbf29e 100644 --- a/Views/BrowserTab.swift +++ b/Views/BrowserTab.swift @@ -44,6 +44,11 @@ struct BrowserTab: View { goForward: { [weak browser] in browser?.webView.goForward() }) + if let url = browser.url { + CopyPasteMenu(url: url) + .keyboardShortcut("c", modifiers: [.command, .shift]) + + } } #elseif os(iOS) ToolbarItemGroup(placement: .navigationBarLeading) { diff --git a/Views/BuildingBlocks/CopyPasteMenu.swift b/Views/BuildingBlocks/CopyPasteMenu.swift index fe5cc061..57185294 100644 --- a/Views/BuildingBlocks/CopyPasteMenu.swift +++ b/Views/BuildingBlocks/CopyPasteMenu.swift @@ -18,15 +18,15 @@ import UniformTypeIdentifiers struct CopyPasteMenu: View { - let downloadURL: URL + let url: URL var body: some View { Button { #if os(macOS) NSPasteboard.general.clearContents() - NSPasteboard.general.setString(downloadURL.absoluteString, forType: .string) + NSPasteboard.general.setString(url.absoluteString, forType: .string) #elseif os(iOS) - UIPasteboard.general.setValue(downloadURL.absoluteString, forPasteboardType: UTType.url.identifier) + UIPasteboard.general.setValue(url.absoluteString, forPasteboardType: UTType.url.identifier) #endif } label: { Label(LocalString.library_zim_file_context_copy_url, systemImage: "doc.on.doc") diff --git a/Views/Library/ZimFileContextMenu.swift b/Views/Library/ZimFileContextMenu.swift index 8924bdc7..05def96c 100644 --- a/Views/Library/ZimFileContextMenu.swift +++ b/Views/Library/ZimFileContextMenu.swift @@ -23,7 +23,7 @@ struct ZimFileContextMenu: View { Section { ArticleActions(zimFileID: zimFile.fileID) } } if let downloadURL = zimFile.downloadURL { - Section { CopyPasteMenu(downloadURL: downloadURL) } + Section { CopyPasteMenu(url: downloadURL) } } } } diff --git a/Views/ViewModifiers/CopyURLContext.swift b/Views/ViewModifiers/CopyURLContext.swift new file mode 100644 index 00000000..a564e641 --- /dev/null +++ b/Views/ViewModifiers/CopyURLContext.swift @@ -0,0 +1,34 @@ +// This file is part of Kiwix for iOS & macOS. +// +// Kiwix is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// any later version. +// +// Kiwix is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Kiwix; If not, see https://www.gnu.org/licenses/. + +#if os(macOS) +import SwiftUI + +struct CopyURLContext: ViewModifier { + + @State var url: URL? + + func body(content: Content) -> some View { + if let url { + content.contextMenu { + CopyPasteMenu(url: url) + } + } else { + content + } + } +} + +#endif