<commit_before>//
//  CBCollectionView.swift
//  Lingo
//
//  Created by <NAME> on 1/27/16.
//  Copyright © 2016 The Noun Project. All rights reserved.
//

import Foundation

struct SupplementaryViewIdentifier: Hashable {
    let indexPath: NSIndexPath?
    let kind: String!
    let reuseIdentifier : String!
    
    var hashValue: Int {
        if let ip = self.indexPath {
            return "\(ip._section)/\(self.kind)".hashValue
        }
        return "\(self.kind)/\(self.reuseIdentifier)".hashValue
    }
    
    init(kind: String, reuseIdentifier: String, indexPath: NSIndexPath? = nil) {
        self.kind = kind
        self.reuseIdentifier = reuseIdentifier
        self.indexPath = indexPath
    }
}

func ==(lhs: SupplementaryViewIdentifier, rhs: SupplementaryViewIdentifier) -> Bool {
    return lhs.indexPath == rhs.indexPath && lhs.kind == rhs.kind && lhs.reuseIdentifier == rhs.reuseIdentifier
}

public class CBScrollView : NSScrollView {
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.swapClipView()
    }
    public override var flipped : Bool { return true }
    required public init?(coder: NSCoder) {
        super.init(coder: coder)
        self.swapClipView()
    }
    public var clipView : CBClipView? {
        return self.contentView as? CBClipView
    }
    
    func swapClipView() {
        if self.contentView.isKindOfClass(CBClipView) { return }
        let docView = self.documentView
        let clipView = CBClipView(frame: self.contentView.frame)
        clipView.drawsBackground = self.drawsBackground
        self.contentView = clipView
        self.documentView = docView
    }
}

class FloatingSupplementaryView : NSView {
    override var flipped : Bool { return true }
    internal override func hitTest(aPoint: NSPoint) -> NSView? {
        for view in self.subviews {
            if view.frame.contains(aPoint){
                return super.hitTest(aPoint)
            }
        }
        return nil
    }
}



public class CBCollectionView : CBScrollView, NSDraggingSource {
    
    private var _reusableCells : [String:Set<CBCollectionViewCell>] = [:]
    private var _cellClasses : [String:CBCollectionViewCell.Type] = [:]
    private var _cellNibs : [String:NSNib] = [:]
    
    private var _reusableSupplementaryView : [SupplementaryViewIdentifier:[CBCollectionReusableView]] = [:]
    private var _supplementaryViewClasses : [SupplementaryViewIdentifier:CBCollectionReusableView.Type] = [:]
    private var _supplementaryViewNibs : [SupplementaryViewIdentifier:NSNib] = [:]
    
    public weak var contentDocumentView : CBCollectionViewDocumentView! { return self.documentView as! CBCollectionViewDocumentView }
    public var contentVisibleRect : CGRect { return self.documentVisibleRect }
    
    
    public var contentOffset : CGPoint {
        get{ return self.contentVisibleRect.origin }
        set {
            self.clipView?.scrollToPoint(newValue)
            self.reflectScrolledClipView(self.clipView!)
            self.contentDocumentView.prepareRect(self.contentVisibleRect)
            self.contentDocumentView.preparedRect = self.contentVisibleRect
        }
    }
    
    public override var contentSize: NSSize {
        return self.collectionViewLayout.collectionViewContentSize()
    }
    <commit_msg>Updated thumbnail generation for SVG fixes some broken previews for complex SVG Slight improvements for Asset cell layouts Limits name to 50 and no line breaks<commit_after>//
//  CBCollectionView.swift
//  Lingo
//
//  Created by <NAME> on 1/27/16.
//  Copyright © 2016 The Noun Project. All rights reserved.
//

import Foundation

struct SupplementaryViewIdentifier: Hashable {
    let indexPath: NSIndexPath?
    let kind: String!
    let reuseIdentifier : String!
    
    var hashValue: Int {
        if let ip = self.indexPath {
            return "\(ip._section)/\(self.kind)".hashValue
        }
        return "\(self.kind)/\(self.reuseIdentifier)".hashValue
    }
    
    init(kind: String, reuseIdentifier: String, indexPath: NSIndexPath? = nil) {
        self.kind = kind
        self.reuseIdentifier = reuseIdentifier
        self.indexPath = indexPath
    }
}

func ==(lhs: SupplementaryViewIdentifier, rhs: SupplementaryViewIdentifier) -> Bool {
    return lhs.indexPath == rhs.indexPath && lhs.kind == rhs.kind && lhs.reuseIdentifier == rhs.reuseIdentifier
}

public class CBScrollView : NSScrollView {
    override init(frame frameRect: NSRect) {
        super.init(frame: frameRect)
        self.swapClipView()
    }
    public override var flipped : Bool { return true }
    required public init?(coder: NSCoder) {
        super.init(coder: coder)
        self.swapClipView()
    }
    public var clipView : CBClipView? {
        return self.contentView as? CBClipView
    }
    
    func swapClipView() {
        if self.contentView.isKindOfClass(CBClipView) { return }
        let docView = self.documentView
        let clipView = CBClipView(frame: self.contentView.frame)
        clipView.drawsBackground = self.drawsBackground
        self.contentView = clipView
        self.documentView = docView
    }
}

class FloatingSupplementaryView : NSView {
    override var flipped : Bool { return true }
    internal override func hitTest(aPoint: NSPoint) -> NSView? {
        for view in self.subviews {
            if view.frame.contains(aPoint){
                return super.hitTest(aPoint)
            }
        }
        return nil
    }
}


public class CBCollectionView : CBScrollView, NSDraggingSource {
    
    private var _reusableCells : [String:Set<CBCollectionViewCell>] = [:]
    private var _cellClasses : [String:CBCollectionViewCell.Type] = [:]
    private var _cellNibs : [String:NSNib] = [:]
    
    private var _reusableSupplementaryView : [SupplementaryViewIdentifier:[CBCollectionReusableView]] = [:]
    private var _supplementaryViewClasses : [SupplementaryViewIdentifier:CBCollectionReusableView.Type] = [:]
    private var _supplementaryViewNibs : [SupplementaryViewIdentifier:NSNib] = [:]
    
    public weak var contentDocumentView : CBCollectionViewDocumentView! { return self.documentView as! CBCollectionViewDocumentView }
    public var contentVisibleRect : CGRect { return self.documentVisibleRect }
    
    
    public var contentOffset : CGPoint {
        get{ return self.contentVisibleRect.origin }
        set {
            self.clipView?.scrollToPoint(newValue)
            self.reflectScrolledClipView(self.clipView!)
            self.contentDocumentView.prepareRect(self.contentVisibleRect)
            self.contentDocumentView.preparedRect = self.contentVisibleRect
        }
    }
    
    public override var contentSize: NSSize {
        return self.collectionViewLayout.collectionViewContentSize()
    }
    
{'fraction_non_alphanumeric': 0.08809279107326384, 'fraction_numerical': 0.0029364263691087945, 'mean_word_length': 2.877063175867957, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '1443741', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1877, 'n_words': 441}