NCText.swift 3.3 KB

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