mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-08-03 12:37:15 -04:00
Get the URL of the current page on macOS
This commit is contained in:
parent
ba6f34fc53
commit
1fa79ec5dd
@ -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) {
|
||||
|
@ -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")
|
||||
|
@ -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) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
Views/ViewModifiers/CopyURLContext.swift
Normal file
34
Views/ViewModifiers/CopyURLContext.swift
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user