NCText.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  14. var metadata: tableMetadata?
  15. var loadText: String?
  16. override func viewDidLoad() {
  17. super.viewDidLoad()
  18. self.navigationController?.navigationBar.topItem?.title = NSLocalizedString("_title_new_text_file_", comment: "")
  19. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
  20. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.navigationBarText
  21. self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: NCBrandColor.sharedInstance.navigationBarText]
  22. self.navigationController?.toolbar.barTintColor = NCBrandColor.sharedInstance.navigationBarText
  23. self.navigationController?.toolbar.tintColor = NCBrandColor.sharedInstance.brand
  24. cancelButton.title = NSLocalizedString("_cancel_", comment: "")
  25. nextButton.title = NSLocalizedString("_next_", comment: "")
  26. if let metadata = metadata {
  27. let path = "\(appDelegate.directoryUser!)/\(metadata.fileID)"
  28. loadText = try? String(contentsOfFile: path, encoding: String.Encoding.utf8)
  29. textView.text = loadText
  30. }
  31. textView.isUserInteractionEnabled = true
  32. textView.becomeFirstResponder()
  33. }
  34. override func viewWillAppear(_ animated: Bool) {
  35. super.viewWillAppear(animated)
  36. }
  37. @IBAction func cancelButtonTapped(_ sender: AnyObject) {
  38. if textView.text != loadText {
  39. let alertController = UIAlertController(title: NSLocalizedString("_info_", comment: ""), message: NSLocalizedString("_save_exit_", comment: ""), preferredStyle: .alert)
  40. let actionYes = UIAlertAction(title: NSLocalizedString("_yes_", comment: ""), style: .default) { (action:UIAlertAction) in
  41. self.dismiss(animated: true, completion: nil)
  42. }
  43. let actionNo = UIAlertAction(title: NSLocalizedString("_no_", comment: ""), style: .cancel) { (action:UIAlertAction) in
  44. print("You've pressed No button")
  45. }
  46. alertController.addAction(actionYes)
  47. alertController.addAction(actionNo)
  48. self.present(alertController, animated: true, completion:nil)
  49. } else {
  50. self.dismiss(animated: true, completion: nil)
  51. }
  52. }
  53. @IBAction func nextButtonTapped(_ sender: AnyObject) {
  54. if let metadata = metadata {
  55. //let formViewController = CreateFormUploadFile.init(self.titleMain, serverUrl: self.serverUrl, text: self.textView.text, fileName: self.fileName!)
  56. //self.navigationController?.pushViewController(formViewController, animated: true)
  57. } else {
  58. let formViewController = CreateFormUploadFile.init(NSLocalizedString("_untitled_txt_", comment: ""), serverUrl: appDelegate.activeMain.serverUrl, text: self.textView.text, fileName: NSLocalizedString("_untitled_txt_", comment: ""))
  59. self.navigationController?.pushViewController(formViewController, animated: true)
  60. }
  61. }
  62. }