From 1b49e65830f867e3d61c5890e64d549030e689e0 Mon Sep 17 00:00:00 2001 From: Balazs Perlaki-Horvath Date: Sat, 12 Apr 2025 14:52:19 +0200 Subject: [PATCH] Move ZimFileContextMenu to a new class, add warning on dependencies injected --- Views/Library/Library.swift | 18 ++++------------ Views/Library/ZimFileContextMenu.swift | 29 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 Views/Library/ZimFileContextMenu.swift diff --git a/Views/Library/Library.swift b/Views/Library/Library.swift index fbe737a7..8ee3217f 100644 --- a/Views/Library/Library.swift +++ b/Views/Library/Library.swift @@ -151,7 +151,10 @@ struct DetailSidePanel: View { } }.frame(width: 275).background(.ultraThinMaterial) } - }.environmentObject(selection) + } + // !important, otherwise the wrapped contentView + // won't get the selection dependency + .environmentObject(selection) } } @@ -189,19 +192,6 @@ struct MultiZimFilesOpenedContext: View { } #endif -struct ZimFileContextMenu: View { - let zimFile: ZimFile - - var body: some View { - if zimFile.fileURLBookmark != nil, !zimFile.isMissing { - Section { ArticleActions(zimFileID: zimFile.fileID) } - } - if let downloadURL = zimFile.downloadURL { - Section { CopyPasteMenu(downloadURL: downloadURL) } - } - } -} - /// On macOS, makes the content view clickable, to select a single ZIM file /// On iOS, converts the modified view to a NavigationLink that goes to the zim file detail. struct LibraryZimFileContext: View { diff --git a/Views/Library/ZimFileContextMenu.swift b/Views/Library/ZimFileContextMenu.swift new file mode 100644 index 00000000..8924bdc7 --- /dev/null +++ b/Views/Library/ZimFileContextMenu.swift @@ -0,0 +1,29 @@ +// 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/. + +import SwiftUI + +struct ZimFileContextMenu: View { + let zimFile: ZimFile + + var body: some View { + if zimFile.fileURLBookmark != nil, !zimFile.isMissing { + Section { ArticleActions(zimFileID: zimFile.fileID) } + } + if let downloadURL = zimFile.downloadURL { + Section { CopyPasteMenu(downloadURL: downloadURL) } + } + } +}