<commit_before>//
//  LYTabBarView.swift
//  LYTabBarView
//
//  Created by <NAME> on 16/3/29.
//  Copyright © 2016年 <NAME>. All rights reserved.
//

import Foundation
import Cocoa

public class LYTabBarView: NSView {
    private let serialQueue = dispatch_queue_create("Operations.TabBarView.UpdaterQueue", DISPATCH_QUEUE_SERIAL)
    private var _needsUpdate = false
    
    @IBOutlet public var delegate : NSTabViewDelegate?
    
    public var needAnimation = true

    var backgroundColor = NSColor(white: 0.73, alpha: 1)
    var borderColor = NSColor(white: 0.61, alpha: 1)
    var selectedBorderColor = NSColor(white: 0.71, alpha: 1)
    public var showAddNewTabButton = true {
        didSet {
            if showAddNewTabButton && addTabButton.superview == nil {
                stackView.addView(addTabButton, inGravity: .Bottom)
            } else if !showAddNewTabButton && addTabButton.superview != nil {
                addTabButton.removeFromSuperview()
            }
        }
    }
    
    @IBOutlet var tabView : NSTabView? {
        didSet {
            self.needsUpdate = true
        }
    }

    private let stackView = NSStackView(frame: .zero)
    private var addTabButton : NSButton!
    private var addTabButtonHeightConstraint : NSLayoutConstraint?
    
    override public var intrinsicContentSize: NSSize {
        var height : CGFloat = 22;
        if let aTabView = self.tabViews().first {
            height = aTabView.intrinsicContentSize.height+2
        }
        if let constraint = addTabButtonHeightConstraint {
            constraint.active = false
            addTabButtonHeightConstraint = addTabButton.heightAnchor.constraintEqualToConstant(height)
            addTabButtonHeightConstraint?.active = true
        }
        return NSMakeSize(NSViewNoIntrinsicMetric, height)
    }
    
    required public init?(coder: NSCoder) {
        super.init(coder: coder)
        
        stackView.translatesAutoresizingMaskIntoConstraints = false
        self.addSubview(stackView)
        stackView.trailingAnchor.constraintEqualToAnchor(self.trailingAnchor).active = true
        stackView.topAnchor.constraintEqualToAnchor(self.topAnchor).active = true
        stackView.leadingAnchor.constraintEqualToAnchor(self.leadingAnchor).active = true
        stackView.bottomAnchor.constraintEqualToAnchor(self.bottomAnchor).active = true
        stackView.orientation = .Horizontal
        stackView.distribution = .FillEqually
        stackView.spacing = 1
        
        addTabButton = NSButton(frame: .zero)
        addTabButton.translatesAutoresizingMaskIntoConstraints = false
        addTabButton.setButtonType(.MomentaryChangeButton)
        addTabButton.image = NSImage(named: NSImageNameAddTemplate)
        addTabButton.bezelStyle = .ShadowlessSquareBezelStyle
        addTabButton.bordered = false
        addTabButton.imagePosition = .ImageOnly
        addTabButtonHeightConstraint = addTabButton.heightAnchor.constraintEqualToConstant(22)
        addTabButtonHeightConstraint?.active = true
        addTabButton.widthAnchor.constraintEqualToAnchor(addTabButton.heightAnchor).active = true
        addTabButton.target = self<commit_msg>fix window size issue caused by stack view hugging priority<commit_after>//
//  LYTabBarView.swift
//  LYTabBarView
//
//  Created by <NAME> on 16/3/29.
//  Copyright © 2016年 <NAME>. All rights reserved.
//

import Foundation
import Cocoa

public class LYTabBarView: NSView {
    private let serialQueue = dispatch_queue_create("Operations.TabBarView.UpdaterQueue", DISPATCH_QUEUE_SERIAL)
    private var _needsUpdate = false
    
    @IBOutlet public var delegate : NSTabViewDelegate?
    
    public var needAnimation = true

    var backgroundColor = NSColor(white: 0.73, alpha: 1)
    var borderColor = NSColor(white: 0.61, alpha: 1)
    var selectedBorderColor = NSColor(white: 0.71, alpha: 1)
    public var showAddNewTabButton = true {
        didSet {
            if showAddNewTabButton && addTabButton.superview == nil {
                stackView.addView(addTabButton, inGravity: .Bottom)
            } else if !showAddNewTabButton && addTabButton.superview != nil {
                addTabButton.removeFromSuperview()
            }
        }
    }
    
    @IBOutlet var tabView : NSTabView? {
        didSet {
            self.needsUpdate = true
        }
    }

    private let stackView = NSStackView(frame: .zero)
    private var addTabButton : NSButton!
    private var addTabButtonHeightConstraint : NSLayoutConstraint?
    
    override public var intrinsicContentSize: NSSize {
        var height : CGFloat = 22;
        if let aTabView = self.tabViews().first {
            height = aTabView.intrinsicContentSize.height+2
        }
        if let constraint = addTabButtonHeightConstraint {
            constraint.active = false
            addTabButtonHeightConstraint = addTabButton.heightAnchor.constraintEqualToConstant(height)
            addTabButtonHeightConstraint?.active = true
        }
        return NSMakeSize(NSViewNoIntrinsicMetric, height)
    }
    
    required public init?(coder: NSCoder) {
        super.init(coder: coder)
        
        stackView.translatesAutoresizingMaskIntoConstraints = false
        self.addSubview(stackView)
        stackView.trailingAnchor.constraintEqualToAnchor(self.trailingAnchor).active = true
        stackView.topAnchor.constraintEqualToAnchor(self.topAnchor).active = true
        stackView.leadingAnchor.constraintEqualToAnchor(self.leadingAnchor).active = true
        stackView.bottomAnchor.constraintEqualToAnchor(self.bottomAnchor).active = true
        stackView.orientation = .Horizontal
        stackView.distribution = .FillEqually
        stackView.spacing = 1
        stackView.setHuggingPriority(NSLayoutPriorityDefaultLow, forOrientation: .Horizontal)
        
        addTabButton = NSButton(frame: .zero)
        addTabButton.translatesAutoresizingMaskIntoConstraints = false
        addTabButton.setButtonType(.MomentaryChangeButton)
        addTabButton.image = NSImage(named: NSImageNameAddTemplate)
        addTabButton.bezelStyle = .ShadowlessSquareBezelStyle
        addTabButton.bordered = false
        addTabButton.imagePosition = .ImageOnly
        addTabButtonHeightConstraint = addTabButton.heightAnchor.constraintEqualToConstant(22)
        addTabButtonHeightConstraint?.active = true
        addTabButton.widthAnchor.constraintEqualToAnchor(addTabButton.heightAnchor).active = true
        addTabButton.target = self
{'fraction_non_alphanumeric': 0.07320824361734851, 'fraction_numerical': 0.008305136880959704, 'mean_word_length': 2.9293051359516618, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1655564', 'n_tokens_mistral': 1809, 'n_tokens_neox': 1750, 'n_words': 353}