|
@@ -39,6 +39,9 @@ extension UIAlertController {
|
|
|
let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in
|
|
|
guard let fileNameFolder = alertController.textFields?.first?.text else { return }
|
|
|
if markE2ee {
|
|
|
+ if NCNetworking.shared.isOffline {
|
|
|
+ return NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_offline_not_allowed_"))
|
|
|
+ }
|
|
|
Task {
|
|
|
let createFolderResults = await NCNetworking.shared.createFolder(serverUrlFileName: serverUrl + "/" + fileNameFolder, account: session.account)
|
|
|
if createFolderResults.error == .success {
|
|
@@ -51,17 +54,28 @@ extension UIAlertController {
|
|
|
}
|
|
|
}
|
|
|
} else if isDirectoryEncrypted {
|
|
|
+ if NCNetworking.shared.isOffline {
|
|
|
+ return NCContentPresenter().showInfo(error: NKError(errorCode: NCGlobal.shared.errorInternalError, errorDescription: "_offline_not_allowed_"))
|
|
|
+ }
|
|
|
+ #if !EXTENSION
|
|
|
Task {
|
|
|
await NCNetworkingE2EECreateFolder().createFolder(fileName: fileNameFolder, serverUrl: serverUrl, withPush: true, sceneIdentifier: sceneIdentifier, session: session)
|
|
|
}
|
|
|
+ #endif
|
|
|
} else {
|
|
|
- NCNetworking.shared.createFolder(fileName: fileNameFolder, serverUrl: serverUrl, overwrite: false, withPush: true, sceneIdentifier: sceneIdentifier, session: session) { error in
|
|
|
- if let completion = completion {
|
|
|
- DispatchQueue.main.async { completion(error) }
|
|
|
- } else if error != .success {
|
|
|
- NCContentPresenter().showError(error: error)
|
|
|
- }
|
|
|
- }
|
|
|
+ let metadataForCreateFolder = NCManageDatabase.shared.createMetadata(fileName: fileNameFolder,
|
|
|
+ fileNameView: fileNameFolder,
|
|
|
+ ocId: NSUUID().uuidString,
|
|
|
+ serverUrl: serverUrl,
|
|
|
+ url: "",
|
|
|
+ contentType: "httpd/unix-directory",
|
|
|
+ directory: true,
|
|
|
+ session: session,
|
|
|
+ sceneIdentifier: sceneIdentifier)
|
|
|
+ metadataForCreateFolder.status = NCGlobal.shared.metadataStatusWaitCreateFolder
|
|
|
+ metadataForCreateFolder.sessionDate = Date()
|
|
|
+ NCManageDatabase.shared.addMetadata(metadataForCreateFolder)
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterCreateFolder, userInfo: ["ocId": metadataForCreateFolder.ocId, "serverUrl": metadataForCreateFolder.serverUrl, "account": metadataForCreateFolder.account, "withPush": true, "sceneIdentifier": sceneIdentifier as Any])
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -81,9 +95,28 @@ extension UIAlertController {
|
|
|
guard let text = alertController.textFields?.first?.text else { return }
|
|
|
let folderName = text.trimmingCharacters(in: .whitespaces)
|
|
|
|
|
|
+ let newExtension = text.fileExtension
|
|
|
+ let isFileHidden = FileNameValidator.shared.isFileHidden(text)
|
|
|
let textCheck = FileNameValidator.shared.checkFileName(folderName, account: session.account)
|
|
|
- okAction.isEnabled = textCheck?.error == nil && !folderName.isEmpty
|
|
|
- alertController.message = textCheck?.error.localizedDescription
|
|
|
+
|
|
|
+ okAction.isEnabled = !text.isEmpty && textCheck?.error == nil
|
|
|
+
|
|
|
+ var message = ""
|
|
|
+ var messageColor = UIColor.label
|
|
|
+
|
|
|
+ if let errorMessage = textCheck?.error.localizedDescription {
|
|
|
+ message = errorMessage
|
|
|
+ messageColor = .red
|
|
|
+ } else if isFileHidden {
|
|
|
+ message = NSLocalizedString("hidden_file_name_warning", comment: "")
|
|
|
+ }
|
|
|
+
|
|
|
+ let attributedString = NSAttributedString(string: message, attributes: [
|
|
|
+ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14),
|
|
|
+ NSAttributedString.Key.foregroundColor: messageColor
|
|
|
+ ])
|
|
|
+
|
|
|
+ alertController.setValue(attributedString, forKey: "attributedMessage")
|
|
|
}
|
|
|
|
|
|
alertController.addAction(cancelAction)
|
|
@@ -146,8 +179,8 @@ extension UIAlertController {
|
|
|
return alertController
|
|
|
}
|
|
|
|
|
|
- static func renameFile(fileName: String, account: String, completion: @escaping (_ newFileName: String) -> Void) -> UIAlertController {
|
|
|
- let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
|
|
|
+ static func renameFile(fileName: String, isDirectory: Bool = false, account: String, completion: @escaping (_ newFileName: String) -> Void) -> UIAlertController {
|
|
|
+ let alertController = UIAlertController(title: NSLocalizedString(isDirectory ? "_rename_folder_" : "_rename_file_", comment: ""), message: nil, preferredStyle: .alert)
|
|
|
|
|
|
let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in
|
|
|
guard let newFileName = alertController.textFields?.first?.text else { return }
|
|
@@ -164,6 +197,19 @@ extension UIAlertController {
|
|
|
textField.autocapitalizationType = .words
|
|
|
}
|
|
|
|
|
|
+ let oldExtension = fileName.fileExtension
|
|
|
+
|
|
|
+ let text = alertController.textFields?.first?.text ?? ""
|
|
|
+ let textCheck = FileNameValidator.shared.checkFileName(text, account: account)
|
|
|
+ var message = textCheck?.error.localizedDescription ?? ""
|
|
|
+ var messageColor = UIColor.red
|
|
|
+
|
|
|
+ let attributedString = NSAttributedString(string: message, attributes: [
|
|
|
+ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14),
|
|
|
+ NSAttributedString.Key.foregroundColor: messageColor
|
|
|
+ ])
|
|
|
+ alertController.setValue(attributedString, forKey: "attributedMessage")
|
|
|
+
|
|
|
|
|
|
NotificationCenter.default.addObserver(
|
|
|
forName: UITextField.textDidBeginEditingNotification,
|
|
@@ -182,10 +228,31 @@ extension UIAlertController {
|
|
|
object: alertController.textFields?.first,
|
|
|
queue: .main) { _ in
|
|
|
guard let text = alertController.textFields?.first?.text else { return }
|
|
|
+ let newExtension = text.fileExtension
|
|
|
|
|
|
let textCheck = FileNameValidator.shared.checkFileName(text, account: account)
|
|
|
- okAction.isEnabled = textCheck?.error == nil && !text.isEmpty
|
|
|
- alertController.message = textCheck?.error.localizedDescription
|
|
|
+ let isFileHidden = FileNameValidator.shared.isFileHidden(text)
|
|
|
+
|
|
|
+ okAction.isEnabled = !text.isEmpty && textCheck?.error == nil
|
|
|
+
|
|
|
+ message = ""
|
|
|
+ messageColor = UIColor.label
|
|
|
+
|
|
|
+ if let errorMessage = textCheck?.error.localizedDescription {
|
|
|
+ message = errorMessage
|
|
|
+ messageColor = .red
|
|
|
+ } else if isFileHidden {
|
|
|
+ message = NSLocalizedString("hidden_file_name_warning", comment: "")
|
|
|
+ } else if newExtension != oldExtension {
|
|
|
+ message = NSLocalizedString("_file_name_new_extension_", comment: "")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ let attributedString = NSAttributedString(string: message, attributes: [
|
|
|
+ NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14),
|
|
|
+ NSAttributedString.Key.foregroundColor: messageColor
|
|
|
+ ])
|
|
|
+ alertController.setValue(attributedString, forKey: "attributedMessage")
|
|
|
}
|
|
|
|
|
|
alertController.addAction(cancelAction)
|
|
@@ -193,12 +260,8 @@ extension UIAlertController {
|
|
|
return alertController
|
|
|
}
|
|
|
|
|
|
- static func renameFile(metadata: tableMetadata) -> UIAlertController {
|
|
|
- let alertController = UIAlertController(title: NSLocalizedString("_rename_", comment: ""), message: nil, preferredStyle: .alert)
|
|
|
-
|
|
|
- let okAction = UIAlertAction(title: NSLocalizedString("_save_", comment: ""), style: .default, handler: { _ in
|
|
|
- guard let fileNameNew = alertController.textFields?.first?.text else { return }
|
|
|
-
|
|
|
+ static func renameFile(metadata: tableMetadata, completion: @escaping (_ newFileName: String) -> Void = { _ in }) -> UIAlertController {
|
|
|
+ renameFile(fileName: metadata.fileNameView, isDirectory: metadata.isDirectory, account: metadata.account) { fileNameNew in
|
|
|
|
|
|
if NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", metadata.account, metadata.serverUrl, fileNameNew)) != nil {
|
|
|
NCContentPresenter().showError(error: NKError(errorCode: 0, errorDescription: "_rename_already_exists_"))
|
|
@@ -208,50 +271,15 @@ extension UIAlertController {
|
|
|
NCNetworking.shared.renameMetadata(metadata, fileNameNew: fileNameNew)
|
|
|
|
|
|
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadDataSource, userInfo: ["serverUrl": metadata.serverUrl])
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
- okAction.isEnabled = false
|
|
|
- let cancelAction = UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel)
|
|
|
|
|
|
- alertController.addTextField { textField in
|
|
|
- textField.text = metadata.fileNameView
|
|
|
- textField.autocapitalizationType = .words
|
|
|
+ completion(fileNameNew)
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(
|
|
|
- forName: UITextField.textDidBeginEditingNotification,
|
|
|
- object: alertController.textFields?.first,
|
|
|
- queue: .main) { _ in
|
|
|
- guard let textField = alertController.textFields?.first else { return }
|
|
|
-
|
|
|
- if let start = textField.position(from: textField.beginningOfDocument, offset: 0),
|
|
|
- let end = textField.position(from: start, offset: textField.text?.withRemovedFileExtension.count ?? 0) {
|
|
|
- textField.selectedTextRange = textField.textRange(from: start, to: end)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- NotificationCenter.default.addObserver(
|
|
|
- forName: UITextField.textDidChangeNotification,
|
|
|
- object: alertController.textFields?.first,
|
|
|
- queue: .main) { _ in
|
|
|
- guard let text = alertController.textFields?.first?.text else { return }
|
|
|
-
|
|
|
- let textCheck = FileNameValidator.shared.checkFileName(text, account: NCManageDatabase.shared.getActiveTableAccount()?.account)
|
|
|
- okAction.isEnabled = textCheck?.error == nil && !text.isEmpty
|
|
|
- alertController.message = textCheck?.error.localizedDescription
|
|
|
- }
|
|
|
-
|
|
|
- alertController.addAction(cancelAction)
|
|
|
- alertController.addAction(okAction)
|
|
|
- return alertController
|
|
|
}
|
|
|
|
|
|
- static func warning(title: String? = nil, message: String? = nil) -> UIAlertController {
|
|
|
+ static func warning(title: String? = nil, message: String? = nil, completion: @escaping () -> Void = {}) -> UIAlertController {
|
|
|
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
|
|
|
|
- let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default)
|
|
|
+ let okAction = UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default) { _ in completion() }
|
|
|
|
|
|
alertController.addAction(okAction)
|
|
|
|