<commit_before>//
//  VaultItemOutlineViewController.swift
//  two-half-password
//
//  Created by <NAME> on 15/6/15.
//  Copyright © 2015 ParseCool. All rights reserved.
//

import Cocoa

class VaultOutlineViewController: NSViewController, NSOutlineViewDataSource, NSOutlineViewDelegate {

    var vaultViewController: VaultViewController!
    
    @IBOutlet weak var outlineView: NSOutlineView!
    class Category: NSObject {
        var type: String
        var items: NSMutableArray
        
        init(type: String) {
            self.type = type
            self.items = NSMutableArray()
        }
    }
    var items: NSMutableDictionary = NSMutableDictionary()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
    }
    
    func addItems(items: [VaultItem]) {
        for item in items {
            if self.items[item.type] == nil {
                let category = Category(type: item.type)
                self.items.setValue(category, forKey: item.type)
            }
            let category = self.items[item.type] as! Category
            category.items.addObject(item)
        }
        
        outlineView.reloadData()
        outlineView.expandItem(nil, expandChildren: true)
    }
    
    // MARK: NSOutlineView DataSource
    
    func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
        if (item == nil) {
            return items.count
        } else {
            if (item is Category) {
                return (item as! Category).items.count
            } else {
                return 0
            }
        }
    }
    
    func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool {
        return item is Category && (item as! Category).items.count > 0
    }
    
    func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
        if (item == nil) {
            return items.allValues[index]
        } else {
            if (item is Category) {<commit_msg>Sort vault items in outline view<commit_after>//
//  VaultItemOutlineViewController.swift
//  two-half-password
//
//  Created by Xinhong LIU on 15/6/15.
//  Copyright © 2015 ParseCool. All rights reserved.
//

import Cocoa

class VaultOutlineViewController: NSViewController, NSOutlineViewDataSource, NSOutlineViewDelegate {

    var vaultViewController: VaultViewController!
    
    @IBOutlet weak var outlineView: NSOutlineView!
    class Category: NSObject {
        var type: String
        var items: NSMutableArray
        
        init(type: String) {
            self.type = type
            self.items = NSMutableArray()
        }
    }
    var items: NSMutableDictionary = NSMutableDictionary()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
    }
    
    func addItems(items: [VaultItem]) {
        for item in items {
            if self.items[item.type] == nil {
                let category = Category(type: item.type)
                self.items.setValue(category, forKey: item.type)
            }
            let category = self.items[item.type] as! Category
            category.items.addObject(item)
        }
        
        for key in self.items.allKeys as! [String] {
            let value = self.items.valueForKey(key) as! Category
            value.items.sortUsingComparator({ (this, that) -> NSComparisonResult in
                if (this as! VaultItem).title < (that as! VaultItem).title {
                    return NSComparisonResult.OrderedAscending
                } else {
                    return NSComparisonResult.OrderedDescending
                }
            })
        }
        
        outlineView.reloadData()
        outlineView.expandItem(nil, expandChildren: true)
    }
    
    // MARK: NSOutlineView DataSource
    
    func outlineView(outlineView: NSOutlineView, numberOfChildrenOfItem item: AnyObject?) -> Int {
        if (item == nil) {
            return items.count
        } else {
            if (item is Category) {
                return (item as! Category).items.count
            } else {
                return 0
            }
        }
    }
    
    func outlineView(outlineView: NSOutlineView, isItemExpandable item: AnyObject) -> Bool {
        return item is Category && (item as! Category).items.count > 0
    }
    
    func outlineView(outlineView: NSOutlineView, child index: Int, ofItem item: AnyObject?) -> AnyObject {
        if (item == nil) {
            return items.allValues[index]
        } else {
            if (item is Category) {
{'fraction_non_alphanumeric': 0.08925869894099848, 'fraction_numerical': 0.004754700669980549, 'mean_word_length': 1.872749844816884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '3435015', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1254, 'n_words': 326}