NCText.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // NCText.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/07/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. import Foundation
  9. class NCText: UIViewController, UITextViewDelegate {
  10. @IBOutlet weak var cancelButton: UIBarButtonItem!
  11. @IBOutlet weak var nextButton: UIBarButtonItem!
  12. @IBOutlet weak var textView: UITextView!
  13. @IBOutlet weak var modifyButton: UIBarButtonItem!
  14. @IBOutlet weak var openInButton: UIBarButtonItem!
  15. @IBOutlet weak var shareButton: UIBarButtonItem!
  16. @IBOutlet weak var deleteButton: UIBarButtonItem!
  17. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  18. weak var delegate: CCMain?
  19. var fileName: String?
  20. var loadText: String? = ""
  21. var serverUrl: String = ""
  22. var titleMain: String = ""
  23. override func viewDidLoad() {
  24. super.viewDidLoad()
  25. self.navigationController?.navigationBar.topItem?.title = NSLocalizedString("_title_new_text_file_", comment: "")
  26. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
  27. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText
  28. self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: NCBrandColor.sharedInstance.navigationBarText]
  29. self.navigationController?.toolbar.barTintColor = NCBrandColor.sharedInstance.navigationBarText
  30. self.navigationController?.toolbar.tintColor = NCBrandColor.sharedInstance.brand
  31. cancelButton.title = NSLocalizedString("_cancel_", comment: "")
  32. nextButton.title = NSLocalizedString("_next_", comment: "")
  33. }
  34. override func viewWillAppear(_ animated: Bool) {
  35. super.viewWillAppear(animated)
  36. if let fileName = fileName {
  37. let path = "\(appDelegate.directoryUser!)/\(fileName)"
  38. loadText = try? String(contentsOfFile: path, encoding: String.Encoding.utf8)
  39. if loadText == nil {
  40. loadText = ""
  41. }
  42. textView.isUserInteractionEnabled = false
  43. } else {
  44. self.fileName = NSLocalizedString("_untitled_txt_", comment: "")
  45. modifyButton.tintColor = UIColor.clear
  46. modifyButton = nil
  47. openInButton.tintColor = UIColor.clear
  48. openInButton = nil
  49. shareButton.tintColor = UIColor.clear
  50. shareButton = nil
  51. deleteButton.tintColor = UIColor.clear
  52. deleteButton = nil
  53. textView.isUserInteractionEnabled = true
  54. textView.becomeFirstResponder()
  55. }
  56. }
  57. @IBAction func cancelButtonTapped(_ sender: AnyObject) {
  58. if textView.text != loadText {
  59. let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: NSLocalizedString("_save_exit_", comment: ""), preferredStyle: .alert)
  60. let actionYes = UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default) { (action:UIAlertAction) in
  61. self.dismiss(animated: true, completion: nil)
  62. }
  63. let actionNo = UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .cancel) { (action:UIAlertAction) in
  64. print("You've pressed No button")
  65. }
  66. alertController.addAction(actionYes)
  67. alertController.addAction(actionNo)
  68. self.present(alertController, animated: true, completion:nil)
  69. } else {
  70. self.dismiss(animated: true, completion: nil)
  71. }
  72. }
  73. @IBAction func nextButtonTapped(_ sender: AnyObject) {
  74. self.dismiss(animated: false, completion: {
  75. let form = CreateFormUploadFile.init(self.titleMain, serverUrl: self.serverUrl, text: self.textView.text, fileName: self.fileName!)
  76. let navigationController = UINavigationController.init(rootViewController: form)
  77. navigationController.modalPresentationStyle = UIModalPresentationStyle.formSheet
  78. self.delegate?.present(navigationController, animated: true, completion: nil)
  79. })
  80. }
  81. @IBAction func modifyButtonTapped(_ sender: AnyObject) {
  82. textView.isUserInteractionEnabled = true
  83. textView.becomeFirstResponder()
  84. }
  85. @IBAction func openInButtonTapped(_ sender: AnyObject) {
  86. }
  87. @IBAction func shareButtonTapped(_ sender: AnyObject) {
  88. }
  89. @IBAction func deleteButtonTapped(_ sender: AnyObject) {
  90. }
  91. }