Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */; };
AFCE353727E4ED7B00FEA6C2 /* NCShareCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */; };
AFCE353927E5DE0500FEA6C2 /* Shareable.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFCE353827E5DE0400FEA6C2 /* Shareable.swift */; };
B516E8DC2EF026F2005E049B /* NCViewer+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = B516E8DB2EF026F2005E049B /* NCViewer+Menu.swift */; };
D575039F27146F93008DC9DC /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extension.swift */; };
D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
F310B1EF2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = F310B1EE2BA862F1001C42F5 /* NCViewerMedia+VisionKit.swift */; };
F321DA8A2B71205A00DDA0E6 /* NCTrashSelectTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F321DA892B71205A00DDA0E6 /* NCTrashSelectTabBar.swift */; };
Expand Down Expand Up @@ -1221,6 +1223,7 @@
AFCE353427E4ED5900FEA6C2 /* DateFormatter+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extension.swift"; sourceTree = "<group>"; };
AFCE353627E4ED7B00FEA6C2 /* NCShareCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCShareCells.swift; sourceTree = "<group>"; };
AFCE353827E5DE0400FEA6C2 /* Shareable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Shareable.swift; sourceTree = "<group>"; };
B516E8DB2EF026F2005E049B /* NCViewer+Menu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCViewer+Menu.swift"; sourceTree = "<group>"; };
C0046CDA2A17B98400D87C9D /* NextcloudUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
C04E2F202A17BB4D001BAD85 /* NextcloudIntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudIntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1983,6 +1986,7 @@
371B5A2F23D0B04B00FAFAE9 /* Menu */ = {
isa = PBXGroup;
children = (
B516E8DB2EF026F2005E049B /* NCViewer+Menu.swift */,
F376A3732E5CC5FF0067EE25 /* ContextMenuActions.swift */,
F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */,
F78C6FDD296D677300C952C3 /* NCContextMenu.swift */,
Expand Down Expand Up @@ -4503,6 +4507,7 @@
F7D4BF402CA2E8D800A5E746 /* TOPasscodeButtonLabel.m in Sources */,
F70898692EDDB51700EF85BD /* NCSelectOpen+SelectDelegate.swift in Sources */,
F7D4BF412CA2E8D800A5E746 /* TOPasscodeViewControllerAnimatedTransitioning.m in Sources */,
B516E8DC2EF026F2005E049B /* NCViewer+Menu.swift in Sources */,
F7D4BF422CA2E8D800A5E746 /* TOPasscodeSettingsViewController.m in Sources */,
F7D4BF432CA2E8D800A5E746 /* TOPasscodeCircleImage.m in Sources */,
F78026102E9CFA3700B63436 /* NCTransfersView.swift in Sources */,
Expand Down
216 changes: 216 additions & 0 deletions iOSClient/Menu/NCViewer+Menu.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
//
// NCViewer.swift
// Nextcloud
//
// Created by Marino Faggiana on 07/02/2020.
// Copyright © 2020 Marino Faggiana All rights reserved.
//
// Author Marino Faggiana <[email protected]>
//
// This program 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
// (at your option) any later version.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
//

import UIKit
import FloatingPanel
import NextcloudKit

extension NCViewer {
func toggleMenu(controller: NCMainTabBarController?, metadata: tableMetadata, webView: Bool, imageIcon: UIImage?, indexPath: IndexPath = IndexPath()) {
guard let metadata = self.database.getMetadataFromOcId(metadata.ocId),
let controller else { return }
var actions = [NCMenuAction]()
let localFile = self.database.getTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))
let isOffline = localFile?.offline == true

//
// VIEW IN FOLDER
//
if !webView {
actions.append(
NCMenuAction(
title: NSLocalizedString("_view_in_folder_", comment: ""),
icon: utility.loadImage(named: "arrow.forward.square", colors: [NCBrandColor.shared.iconColor]),
action: { _ in
NCActionCenter.shared.openFileViewInFolder(serverUrl: metadata.serverUrl, fileNameBlink: metadata.fileName, fileNameOpen: nil, sceneIdentifier: controller.sceneIdentifier)
}
)
)
}

//
// FAVORITE
// Workaround: PROPPATCH doesn't work
// https://github.com/nextcloud/files_lock/issues/68
if !metadata.lock, !metadata.isDirectoryE2EE{
actions.append(
NCMenuAction(
title: metadata.favorite ? NSLocalizedString("_remove_favorites_", comment: "") : NSLocalizedString("_add_favorites_", comment: ""),
icon: utility.loadImage(named: "star.fill", colors: [NCBrandColor.shared.yellowFavorite]),
action: { _ in
NCNetworking.shared.favoriteMetadata(metadata) { error in
if error != .success {
NCContentPresenter().showError(error: error)
}
}
}
)
)
}

//
// OFFLINE
//
if !webView, metadata.canSetAsAvailableOffline {
actions.append(.setAvailableOfflineAction(selectedMetadatas: [metadata], isAnyOffline: isOffline, viewController: controller))
}

//
// SHARE
//
if !webView, metadata.canShare {
actions.append(.share(selectedMetadatas: [metadata], controller: controller))
}

//
// PRINT
//
if !webView, metadata.isPrintable {
actions.append(
NCMenuAction(
title: NSLocalizedString("_print_", comment: ""),
icon: utility.loadImage(named: "printer", colors: [NCBrandColor.shared.iconColor]),
action: { _ in
if self.utilityFileSystem.fileProviderStorageExists(metadata) {
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile, userInfo: ["ocId": metadata.ocId, "selector": NCGlobal.shared.selectorPrint, "error": NKError(), "account": metadata.account, "ocIdTransfer": metadata.ocIdTransfer])
} else {
NCNetworking.shared.downloadQueue.addOperation(NCOperationDownload(metadata: metadata, selector: NCGlobal.shared.selectorPrint))
}
}
)
)
}

//
// SAVE CAMERA ROLL
//
if !webView, metadata.isSavebleInCameraRoll {
actions.append(.saveMediaAction(selectedMediaMetadatas: [metadata], controller: controller))
}


//
// RENAME
//
if !webView, metadata.isRenameable, !metadata.isDirectoryE2EE {
actions.append(
NCMenuAction(
title: NSLocalizedString("_rename_", comment: ""),
icon: utility.loadImage(named: "rename", colors: [NCBrandColor.shared.iconColor]),
action: { _ in

if let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile {

vcRename.metadata = metadata
vcRename.disableChangeExt = true
vcRename.imagePreview = imageIcon
vcRename.indexPath = indexPath

let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)

controller.present(popup, animated: true)
}
}
)
)
}

//
// COPY - MOVE
//
if !webView, metadata.isCopyableMovable {
actions.append(.moveOrCopyAction(selectedMetadatas: [metadata], controller: controller))
}

// COPY IN PASTEBOARD
//
if !webView, metadata.isCopyableInPasteboard, !metadata.isDirectoryE2EE {
actions.append(.copyAction(fileSelect: [metadata.ocId], controller: controller))
}

//
// PDF
//
if metadata.isPDF {
actions.append(
NCMenuAction(
title: NSLocalizedString("_search_", comment: ""),
icon: utility.loadImage(named: "search", colors: [NCBrandColor.shared.iconColor]),
action: { _ in
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuSearchTextPDF)
}
)
)

actions.append(
NCMenuAction(
title: NSLocalizedString("_go_to_page_", comment: ""),
icon: utility.loadImage(named: "go-to-page", colors: [NCBrandColor.shared.iconColor]),
action: { _ in
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterMenuGotToPageInPDF)
}
)
)
}

//
// MODIFY WITH QUICK LOOK
//
if !webView, metadata.isModifiableWithQuickLook {
actions.append(
NCMenuAction(
title: NSLocalizedString("_modify_", comment: ""),
icon: utility.loadImage(named: "pencil.tip.crop.circle", colors: [NCBrandColor.shared.iconColor]),
action: { _ in
if self.utilityFileSystem.fileProviderStorageExists(metadata) {
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterDownloadedFile,
object: nil,
userInfo: ["ocId": metadata.ocId,
"ocIdTransfer": metadata.ocIdTransfer,
"session": metadata.session,
"selector": NCGlobal.shared.selectorLoadFileQuickLook,
"error": NKError(),
"account": metadata.account],
second: 0.5)
} else {
guard let metadata = self.database.setMetadatasSessionInWaitDownload(metadatas: [metadata],
session: NCNetworking.shared.sessionDownload,
selector: NCGlobal.shared.selectorLoadFileQuickLook,
sceneIdentifier: controller.sceneIdentifier) else { return }
NCNetworking.shared.download(metadata: metadata, withNotificationProgressTask: true)
}
}
)
)
}

//
// DELETE
//
if !webView, metadata.isDeletable {
actions.append(.deleteAction(selectedMetadatas: [metadata], metadataFolder: nil, controller: controller))
}

controller.presentMenu(with: actions)
}
}