<commit_before>//
//  EntryTextEditorViewController.swift
//  MT_iOS
//
//  Created by CHEEBOW on 2015/06/05.
//  Copyright (c) 2015年 Six Apart, Ltd. All rights reserved.
//

import UIKit

class EntryTextEditorViewController: BaseViewController, UITextViewDelegate {

    var textView: UITextView!

    var object: EntryTextItem!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.textView = UITextView(frame: self.view.bounds)
        self.textView.autocapitalizationType = UITextAutocapitalizationType.None
        self.textView.autocorrectionType = UITextAutocorrectionType.No
        self.textView.font = UIFont.systemFontOfSize(13.0)
        self.textView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
        self.textView.autoresizesSubviews = true
        self.textView.delegate = self
        
        self.view.addSubview(self.textView)
        
        self.title = object.label
        self.textView.text = object.text
        self.textView.selectedRange = NSRange()
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Save, target: self, action: "saveButtonPushed:")
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back_arw"), left: true, target: self, action: "backButtonPushed:")

        self.textView.becomeFirstResponder()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillChangeFrameNotification, object: nil)
    }
    
    override func viewDidDisappear(animated: Bool) {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
    
    func keyboardWillShow(notification: NSNotification) {
        var info = notification.userInfo!
        var keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
        let duration: NSTimeInterval = (info[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
        
        var insets = self.textView.contentInset
        insets.bottom = keyboardFrame.size.height
        UIView.animateWithDuration(duration, animations:
            {_ in
                self.textView.contentInset = insets;
            }
        )
    }
    
    func keyboardWillHide(notification: NSNotification) {
        var info = notification.userInfo!
        var keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
        let duration: NSTimeInterval = (info[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
        
        var insets = self.textView.contentInset
        insets.bottom = 0
        UIView.animateWithDuration(duration, animations:
            {_ in
                self.textView.contentInset = insets;
            }
        )
    }
    
    @IBAction func saveButtonPushed(sender: UIBarButtonItem) {
        object.text = textView.text
        self.navigationController?.popViewControllerAnimated(true)
    }

    @IBAction func backButtonPushed(sender: UIBarButtonItem) {
        if self.textView.text == object.text {
            self.navigationController?.popViewControllerAnimated(true)
            return
        }
    }

}<commit_msg>タイトルに文字を入れると左上のボタンから戻れない #50<commit_after>//
//  EntryTextEditorViewController.swift
//  MT_iOS
//
//  Created by CHEEBOW on 2015/06/05.
//  Copyright (c) 2015年 Six Apart, Ltd. All rights reserved.
//

import UIKit

class EntryTextEditorViewController: BaseViewController, UITextViewDelegate {

    var textView: UITextView!

    var object: EntryTextItem!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.textView = UITextView(frame: self.view.bounds)
        self.textView.autocapitalizationType = UITextAutocapitalizationType.None
        self.textView.autocorrectionType = UITextAutocorrectionType.No
        self.textView.font = UIFont.systemFontOfSize(13.0)
        self.textView.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
        self.textView.autoresizesSubviews = true
        self.textView.delegate = self
        
        self.view.addSubview(self.textView)
        
        self.title = object.label
        self.textView.text = object.text
        self.textView.selectedRange = NSRange()
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Save, target: self, action: "saveButtonPushed:")
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "back_arw"), left: true, target: self, action: "backButtonPushed:")

        self.textView.becomeFirstResponder()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillChangeFrameNotification, object: nil)
    }
    
    override func viewDidDisappear(animated: Bool) {
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
    
    func keyboardWillShow(notification: NSNotification) {
        var info = notification.userInfo!
        var keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
        let duration: NSTimeInterval = (info[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
        
        var insets = self.textView.contentInset
        insets.bottom = keyboardFrame.size.height
        UIView.animateWithDuration(duration, animations:
            {_ in
                self.textView.contentInset = insets;
            }
        )
    }
    
    func keyboardWillHide(notification: NSNotification) {
        var info = notification.userInfo!
        var keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue()
        let duration: NSTimeInterval = (info[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
        
        var insets = self.textView.contentInset
        insets.bottom = 0
        UIView.animateWithDuration(duration, animations:
            {_ in
                self.textView.contentInset = insets;
            }
        )
    }
    
    @IBAction func saveButtonPushed(sender: UIBarButtonItem) {
        object.text = textView.text
        self.navigationController?.popViewControllerAnimated(true)
    }

    @IBAction func backButtonPushed(sender: UIBarButtonItem) {
        if self.textView.text == object.text {
            self.navigationController?.popViewControllerAnimated(true)
            return
        }
        
        Utils.confrimSave(self)
    }

}
{'fraction_non_alphanumeric': 0.08417114800093524, 'fraction_numerical': 0.004442366144493804, 'mean_word_length': 2.9698375870069604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '140702', 'n_tokens_mistral': 2443, 'n_tokens_neox': 2347, 'n_words': 478}