NCViewerRichWorkspace.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // NCViewerRichWorkspace.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 14/01/2020.
  6. // Copyright © 2020 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. import NCCommunication
  25. @objc class NCViewerRichWorkspace: UIViewController {
  26. @IBOutlet weak var viewRichWorkspace: NCViewRichWorkspace!
  27. @IBOutlet weak var editItem: UIBarButtonItem!
  28. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  29. @objc public var richWorkspace: String = ""
  30. @objc public var serverUrl: String = ""
  31. @objc public var titleCloseItem: String = ""
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. let closeItem = UIBarButtonItem(title: titleCloseItem, style: .plain, target: self, action: #selector(closeItemTapped(_:)))
  35. self.navigationItem.leftBarButtonItem = closeItem
  36. editItem.image = UIImage(named: "actionSheetModify")
  37. viewRichWorkspace.setRichWorkspaceText(richWorkspace, gradient: false)
  38. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  39. changeTheming()
  40. }
  41. @objc func changeTheming() {
  42. appDelegate.changeTheming(self, tableView: nil, collectionView: nil, form: false)
  43. }
  44. @objc func closeItemTapped(_ sender: UIBarButtonItem) {
  45. self.dismiss(animated: false, completion: nil)
  46. }
  47. @IBAction func editItemAction(_ sender: Any) {
  48. if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileNameView LIKE[c] %@", appDelegate.activeAccount, serverUrl, k_fileNameRichWorkspace.lowercased())) {
  49. if metadata.url == "" {
  50. NCUtility.sharedInstance.startActivityIndicator(view: self.view, bottom: 0)
  51. let fileNamePath = CCUtility.returnFileNamePath(fromFileName: metadata.fileName, serverUrl: metadata.serverUrl, activeUrl: appDelegate.activeUrl)!
  52. NCCommunication.sharedInstance.NCTextOpenFile(urlString: appDelegate.activeUrl, fileNamePath: fileNamePath, editor: "text", account: appDelegate.activeAccount) { (account, url, errorCode, errorMessage) in
  53. NCUtility.sharedInstance.stopActivityIndicator()
  54. if errorCode == 0 && account == self.appDelegate.activeAccount {
  55. if let viewerNextcloudText = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerNextcloudText") as? NCViewerNextcloudText {
  56. viewerNextcloudText.url = url!
  57. viewerNextcloudText.metadata = metadata
  58. self.present(viewerNextcloudText, animated: true, completion: nil)
  59. }
  60. } else if errorCode != 0 {
  61. NCContentPresenter.shared.messageNotification("_error_", description: errorMessage, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: errorCode)
  62. }
  63. }
  64. } else {
  65. if let viewerNextcloudText = UIStoryboard.init(name: "NCViewerRichWorkspace", bundle: nil).instantiateViewController(withIdentifier: "NCViewerNextcloudText") as? NCViewerNextcloudText {
  66. viewerNextcloudText.url = metadata.url
  67. viewerNextcloudText.metadata = metadata
  68. self.present(viewerNextcloudText, animated: true, completion: nil)
  69. }
  70. }
  71. }
  72. }
  73. }