<commit_before>//
//  ProcedureController.swift
//  ReformApplication
//
//  Created by <NAME> on 14.08.15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import Cocoa

import ReformExpression
import ReformCore

final class ProcedureController : NSViewController {
    private var cycle = false

    override var representedObject : AnyObject? {
        didSet {
            procedureViewModel = representedObject as? ProcedureViewModel
        }
    }

    var procedureViewModel : ProcedureViewModel? {
        didSet {
            procedureChanged()
        }
    }

    override func viewDidAppear() {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "procedureEvaluated", name:"ProcedureEvaluated", object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "procedureChanged", name:"ProcedureAnalyzed", object: nil)
    }

    override func viewDidDisappear() {
        NSNotificationCenter.defaultCenter().removeObserver(self, name:"ProcedureEvaluated", object: nil)

        NSNotificationCenter.defaultCenter().removeObserver(self,  name:"ProcedureAnalyzed", object: nil)
    }

    dynamic func procedureChanged() {
        instructions = procedureViewModel?.analyzer.instructions ?? []
        cycle = true
        defer { cycle = false }

        tableView?.reloadData()

        if let focus = procedureViewModel?.instructionFocus.current,
            index = instructions.indexOf({ $0.node === focus }) {
                tableView?.selectRowIndexes(NSIndexSet(index: index), byExtendingSelection: false)
        }

    }

    dynamic func procedureEvaluated() {
        instructions = procedureViewModel?.analyzer.instructions ?? []

        if let focus = procedureViewModel?.instructionFocus.current,
            index = instructions.indexOf({ $0.node === focus }) {

                tableView?.scrollRowToVisible(index)
        }
    }


    var instructions : [InstructionOutlineRow] = []

    @IBOutlet var tableView : NSTableView?
}

extension ProcedureController : NSTableViewDataSource {
    func numberOfRowsInTableView(tableView: NSTableView) -> Int {
        return instructions.count
    }

}

extension ProcedureController : NSTableViewDelegate {<commit_msg>fix error text color<commit_after>//
//  ProcedureController.swift
//  ReformApplication
//
//  Created by <NAME> on 14.08.15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import Cocoa

import ReformExpression
import ReformCore

final class ProcedureController : NSViewController {
    private var cycle = false

    override var representedObject : AnyObject? {
        didSet {
            procedureViewModel = representedObject as? ProcedureViewModel
        }
    }

    var procedureViewModel : ProcedureViewModel? {
        didSet {
            procedureChanged()
        }
    }

    override func viewDidAppear() {
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "procedureEvaluated", name:"ProcedureEvaluated", object: nil)
        NSNotificationCenter.defaultCenter().addObserver(self, selector: "procedureChanged", name:"ProcedureAnalyzed", object: nil)
    }

    override func viewDidDisappear() {
        NSNotificationCenter.defaultCenter().removeObserver(self, name:"ProcedureEvaluated", object: nil)

        NSNotificationCenter.defaultCenter().removeObserver(self,  name:"ProcedureAnalyzed", object: nil)
    }

    dynamic func procedureChanged() {
        instructions = procedureViewModel?.analyzer.instructions ?? []
        cycle = true
        defer { cycle = false }

        tableView?.reloadData()

        if let focus = procedureViewModel?.instructionFocus.current,
            index = instructions.indexOf({ $0.node === focus }) {
                tableView?.selectRowIndexes(NSIndexSet(index: index), byExtendingSelection: false)
        }

    }

    dynamic func procedureEvaluated() {
        instructions = procedureViewModel?.analyzer.instructions ?? []

    tableView?.reloadDataForRowIndexes(NSIndexSet(indexesInRange: NSRange(0..<instructions.count)), columnIndexes: NSIndexSet(index: 0))

        if let focus = procedureViewModel?.instructionFocus.current,
            index = instructions.indexOf({ $0.node === focus }) {

                tableView?.scrollRowToVisible(index)
        }
    }


    var instructions : [InstructionOutlineRow] = []

    @IBOutlet var tableView : NSTableView?
}

extension ProcedureController : NSTableViewDataSource {
    func numberOfRowsInTableView(tableView: NSTableView) -> Int {
        return instructions.count
    }

}

extension ProcedureController : NSTableViewDelegate {
{'fraction_non_alphanumeric': 0.09599314334690379, 'fraction_numerical': 0.005571030640668524, 'mean_word_length': 3.160427807486631, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 9, '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': '2141185', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1147, 'n_words': 262}