 //
 //  CCNPreferencesWindowController.swift
 //
-//  Original Objective-C code created by Frank Gregor on 16/01/15, adapted to Swift by Bruno Vandekerkhove on 30/08/15.
+//  Original Objective-C code created by Frank Gregor on 16/01/15, adapted by Bruno Vandekerkhove on 30/08/15.
 //  Copyright (c) 2015 cocoa:naut. All rights reserved.
 //
 

    func toolbar(toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: String, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
        
        if itemIdentifier == NSToolbarFlexibleSpaceItemIdentifier {
            
            return nil
            
        }
        else if itemIdentifier == CCNPreferencesToolbarSegmentedControlIdentifier {
            
            var toolbarItem = NSToolbarItem(itemIdentifier: itemIdentifier)
            toolbarItem.view = segmentedControl
            toolbarItem.minSize = segmentedControl!.frame.size
            toolbarItem.maxSize = segmentedControl!.frame.size
            
            return toolbarItem
            

        
        super.init(coder: coder)
        
    }
    
    // MARK: - Window Delegate
    
    func windowDidBecomeMain(notification: NSNotification) {
        
        active = true
        
    }
    
    func windowDidResignMain(notification: NSNotification) {
        
        active = false
        
    }
    
    // MARK: - Interface Builder
    
    override func awakeFromNib() {
        
        headerView.color = NSColor(red: 0.18, green: 0.58, blue: 0.74, alpha: 1.0)
        
        window?.center()
        window?.movableByWindowBackground = true
        
    }
    
    var active = true {
        didSet {
            
            if self.active {
                
                headerView.color = NSColor(red: 0.18, green: 0.58, blue: 0.74, alpha: 1.0)
                
            }
            else {
                
                headerView.color = NSColor(calibratedWhite: 0.9, alpha: 1.0)
                
            }
            
        }
    }
    
    ////////////////////////////////////////////////////////////////////////////////
