<commit_before>//
//  PanelButtonBar.swift
//  Helium
//
//  Created by <NAME> on 12/13/18
//  Copyright © 2018 <NAME>. All rights reserved.
//
//	WindowButtonBar.swift - https://gist.github.com/icodeforlove/a334884e59784b4c2567
//	Custom implementation of the OSX Yosemite close, miniaturize, zoom buttons.
//

import Foundation

class PanelButton : NSButton {
	private var _individualized:Bool = false;
	private var _isMouseOver:Bool = false;
	private var useTrackingArea:Bool = true;
	
	var isMouseOver:Bool {
		set {
			self._isMouseOver = newValue;
			self.setNeedsDisplay();
		}
		get {
			return self._isMouseOver;
		}
	};
	var individualized:Bool {
		set {
			self._individualized = newValue;
			self.setNeedsDisplay();
		}
		get {
			return self._individualized;
		}
	}
	var type:NSWindowButton = NSWindowButton.miniaturizeButton;
	
	
	init(frame:NSRect, type:NSWindowButton, useTrackingArea:Bool = true) {
		super.init(frame: frame);
		
		self.type = type;
		self.target = self;
		self.action = #selector(PanelButton.onClick);
		self.useTrackingArea = useTrackingArea;
	}
	
	required init?(coder: NSCoder) {
		super.init(coder: coder);
		
		self.target = self;
		self.action = #selector(PanelButton.onClick);
	}
	
	func onClick () {
		if (type == NSWindowButton.closeButton), let target = self.target, let action = self.action {
			_ = target.perform(action, with: self)
		}
		else
		{
			if (type == NSWindowButton.zoomButton) {
				self.window?.zoom(self);
			} else if (type == NSWindowButton.miniaturizeButton) {
				self.window?.miniaturize(self);
			} else if (type == NSWindowButton.closeButton) {
				self.window?.close();
			}
		}
	}
	
	override func updateTrackingAreas() {
		if (self.useTrackingArea) {
			let options:NSTrackingAreaOptions = NSTrackingAreaOptions.activeInActiveApp
				.union(NSTrackingAreaOptions.mouseEnteredAndExited)
				.union(NSTrackingAreaOptions.assumeInside)
				.union(NSTrackingAreaOptions.inVisibleRect);
			
			let trackingArea = NSTrackingArea(rect: self.bounds, options:options, owner: self, userInfo: nil);
			self.addTrackingArea(trackingArea);
		}
	}
	
	override func mouseEntered(with theEvent: NSEvent) {
		if (self.useTrackingArea) {
			self.isMouseOver = true;
		}
	}
	override func mouseExited(with theEvent: NSEvent) {
		if (self.useTrackingArea) {
			self.isMouseOver = true;
		}
	}
	
	override func draw(_ dirtyRect: NSRect) {
		if !self.isMouseOver { return }
		NSGraphicsContext.current()?.saveGraphicsState();
		var path = NSBezierPath();

		if let image = self.image {
			image.draw(in: dirtyRect)
		}
		else
		{
			//	all buttons are monochrome coloring and gradient
			let backgroundGradient = NSGradient(starting:NSColor.white, ending: NSColor.white)!;
			let strokeColor = NSColor.white
			let lineColor = NSColor.black
			
			// draw background for close, zoom, skipping mini
			if (type != NSWindowButton.miniaturizeButton) {
				path.appendOval(in: NSMakeRect(self.bounds.origin.x + 0.5, self.bounds.origin.y + 0.5, self.bounds.width - 1, self.bounds.height - 1));
				
				backgroundGradient.draw(in: path, relativeCenterPosition: NSMakePoint(0, 0));
				strokeColor.setStroke();
				path.lineWidth = 0.5;
				path.stroke();
			}
			
			if (self.isHighlighted) {
				NSColor(calibratedRed: 0, green: 0, blue: 0, alpha: 0.2).setFill();
				path.fill();
			}
			
			// draw contents
			if (self.isMouseOver) {
				path = NSBezierPath();
				
				if (type == NSWindowButton.zoomButton) {
					NSGraphicsContext.current()?.shouldAntialias = true;
					
					path.move(to: NSMakePoint(self.bounds.width / 2, self.bounds.height * 0.21));
					path.line(to: NSMakePoint(self.bounds.width / 2, self.bounds.height * 0.79));
					
					path.move(to: NSMakePoint(self.bounds.width * 0.79, self.bounds.height / 2));
					path.line(to: NSMakePoint(self.bounds.width * 0.21, self.bounds.height / 2));
					path.lineWidth = 1.25//0.75;
/*	skipped		} else if (type == NSWindowButton.miniaturizeButton) {
					NSGraphicsContext.current()?.shouldAntialias = false;
					
					path.move(to: NSMakePoint(self.bounds.width * 0.80, self.bounds.height / 2));
					path.line(to: NSMakePoint(self.bounds.width * 0.20, self.bounds.height / 2));
					path.lineWidth = 1//0.75;*/
				} else if (type == NSWindowButton.closeButton) {
					NSGraphicsContext.current()?.shouldAntialias = true;

					path.move(to: NSMakePoint(self.bounds.width * 0.27, self.bounds.height * 0.27));
					path.line(to: NSMakePoint(self.bounds.width * 0.73, self.bounds.height * 0.73));
					
					path.move(to: NSMakePoint(self.bounds.width * 0.73, self.bounds.height * 0.27));
					path.line(to: NSMakePoint(self.bounds.width * 0.27, self.bounds.height * 0.73));
					path.lineWidth = 1.25;
				}
				
				lineColor.setStroke();
				path.stroke();
			}
		}
		
		//	show our dirty mark (red dot)
		if (type == NSWindowButton.closeButton), let window = self.window, window.isDocumentEdited {
			let dotGradient = NSGradient(starting:NSColor.yellow, ending: NSColor.yellow)!;
			let pt = NSMakePoint(self.bounds.width * 0.43, self.bounds.height * 0.43)
			
			path.appendOval(in: NSMakeRect(pt.x, pt.y, 2.5, 2.5));
			dotGradient.draw(in: path, relativeCenterPosition: pt);
			NSColor.red.setStroke();
			path.lineWidth = 0.5;
			path.stroke();
		}
		
		if (self.isHighlighted) {
			NSColor(calibratedRed: 0, green: 0, blue: 0, alpha: 0.2).setFill();
			path.fill();

		}
		NSGraphicsContext.current()?.restoreGraphicsState();
	}
}

public class PanelButtonBar : NSView {
	var closeButton : PanelButton?;
	var miniaturizeButton : PanelButton?;
	var zoomButton : PanelButton?;
	
	required public init?(coder: NSCoder) {
		super.init(coder: coder);
		self.setupViews();
	}
	
	override init (frame:NSRect) {
		super.init(frame: frame);
		self.setupViews();
	}<commit_msg>modified red dot - modification marker<commit_after>//
//  PanelButtonBar.swift
//  Helium
//
//  Created by <NAME> on 12/13/18
//  Copyright © 2018 Carlos Santiaog. All rights reserved.
//
//	WindowButtonBar.swift - https://gist.github.com/icodeforlove/a334884e59784b4c2567
//	Custom implementation of the OSX Yosemite close, miniaturize, zoom buttons.
//

import Foundation

class PanelButton : NSButton {
	private var _individualized:Bool = false;
	private var _isMouseOver:Bool = false;
	private var useTrackingArea:Bool = true;
	
	var isMouseOver:Bool {
		set {
			self._isMouseOver = newValue;
			self.setNeedsDisplay();
		}
		get {
			return self._isMouseOver;
		}
	};
	var individualized:Bool {
		set {
			self._individualized = newValue;
			self.setNeedsDisplay();
		}
		get {
			return self._individualized;
		}
	}
	var type:NSWindowButton = NSWindowButton.miniaturizeButton;
	
	
	init(frame:NSRect, type:NSWindowButton, useTrackingArea:Bool = true) {
		super.init(frame: frame);
		
		self.type = type;
		self.target = self;
		self.action = #selector(PanelButton.onClick);
		self.useTrackingArea = useTrackingArea;
	}
	
	required init?(coder: NSCoder) {
		super.init(coder: coder);
		
		self.target = self;
		self.action = #selector(PanelButton.onClick);
	}
	
	func onClick () {
		if (type == NSWindowButton.closeButton), let target = self.target, let action = self.action {
			_ = target.perform(action, with: self)
		}
		else
		{
			if (type == NSWindowButton.zoomButton) {
				self.window?.zoom(self);
			} else if (type == NSWindowButton.miniaturizeButton) {
				self.window?.miniaturize(self);
			} else if (type == NSWindowButton.closeButton) {
				self.window?.close();
			}
		}
	}
	
	override func updateTrackingAreas() {
		if (self.useTrackingArea) {
			let options:NSTrackingAreaOptions = NSTrackingAreaOptions.activeInActiveApp
				.union(NSTrackingAreaOptions.mouseEnteredAndExited)
				.union(NSTrackingAreaOptions.assumeInside)
				.union(NSTrackingAreaOptions.inVisibleRect);
			
			let trackingArea = NSTrackingArea(rect: self.bounds, options:options, owner: self, userInfo: nil);
			self.addTrackingArea(trackingArea);
		}
	}
	
	override func mouseEntered(with theEvent: NSEvent) {
		if (self.useTrackingArea) {
			self.isMouseOver = true;
		}
	}
	override func mouseExited(with theEvent: NSEvent) {
		if (self.useTrackingArea) {
			self.isMouseOver = true;
		}
	}
	
	override func draw(_ dirtyRect: NSRect) {
		if !self.isMouseOver { return }
		NSGraphicsContext.current()?.saveGraphicsState();
		var path = NSBezierPath();

		if let image = self.image {
			image.draw(in: dirtyRect)
		}
		else
		{
			//	all buttons are monochrome coloring and gradient
			let backgroundGradient = NSGradient(starting:NSColor.white, ending: NSColor.white)!;
			let strokeColor = NSColor.white
			let lineColor = NSColor.black
			
			// draw background for close, zoom, skipping mini
			if (type != NSWindowButton.miniaturizeButton) {
				path.appendOval(in: NSMakeRect(self.bounds.origin.x + 0.5, self.bounds.origin.y + 0.5, self.bounds.width - 1, self.bounds.height - 1));
				
				backgroundGradient.draw(in: path, relativeCenterPosition: NSMakePoint(0, 0));
				strokeColor.setStroke();
				path.lineWidth = 0.5;
				path.stroke();
			}
			
			if (self.isHighlighted) {
				NSColor(calibratedRed: 0, green: 0, blue: 0, alpha: 0.2).setFill();
				path.fill();
			}
			
			// draw contents
			if (self.isMouseOver) {
				path = NSBezierPath();
				
				if (type == NSWindowButton.zoomButton) {
					NSGraphicsContext.current()?.shouldAntialias = true;
					
					path.move(to: NSMakePoint(self.bounds.width / 2, self.bounds.height * 0.21));
					path.line(to: NSMakePoint(self.bounds.width / 2, self.bounds.height * 0.79));
					
					path.move(to: NSMakePoint(self.bounds.width * 0.79, self.bounds.height / 2));
					path.line(to: NSMakePoint(self.bounds.width * 0.21, self.bounds.height / 2));
					path.lineWidth = 1.25//0.75;
/*	skipped		} else if (type == NSWindowButton.miniaturizeButton) {
					NSGraphicsContext.current()?.shouldAntialias = false;
					
					path.move(to: NSMakePoint(self.bounds.width * 0.80, self.bounds.height / 2));
					path.line(to: NSMakePoint(self.bounds.width * 0.20, self.bounds.height / 2));
					path.lineWidth = 1//0.75;*/
				} else if (type == NSWindowButton.closeButton) {
					NSGraphicsContext.current()?.shouldAntialias = true;

					path.move(to: NSMakePoint(self.bounds.width * 0.27, self.bounds.height * 0.27));
					path.line(to: NSMakePoint(self.bounds.width * 0.73, self.bounds.height * 0.73));
					
					path.move(to: NSMakePoint(self.bounds.width * 0.73, self.bounds.height * 0.27));
					path.line(to: NSMakePoint(self.bounds.width * 0.27, self.bounds.height * 0.73));
					path.lineWidth = 1.25;
				}
				
				lineColor.setStroke();
				path.stroke();
			}
		}
		
		//	show our dirty mark (red dot)
		if (type == NSWindowButton.closeButton), let window = self.window, window.isDocumentEdited {
			let dotGradient = NSGradient(starting:NSColor.red, ending: NSColor.red)!;
			let pt = NSMakePoint(self.bounds.width * 0.42, self.bounds.height * 0.42)
			
			path.appendOval(in: NSMakeRect(pt.x, pt.y, 2.3, 2.3));
			dotGradient.draw(in: path, relativeCenterPosition: pt);
			NSColor.red.setStroke();
			path.lineWidth = 0.5;
			path.stroke();
		}
		
		if (self.isHighlighted) {
			NSColor(calibratedRed: 0, green: 0, blue: 0, alpha: 0.2).setFill();
			path.fill();

		}
		NSGraphicsContext.current()?.restoreGraphicsState();
	}
}

public class PanelButtonBar : NSView {
	var closeButton : PanelButton?;
	var miniaturizeButton : PanelButton?;
	var zoomButton : PanelButton?;
	
	required public init?(coder: NSCoder) {
		super.init(coder: coder);
		self.setupViews();
	}
	
	override init (frame:NSRect) {
		super.init(frame: frame);
		self.setupViews();
	}
{'fraction_non_alphanumeric': 0.13511884257664486, 'fraction_numerical': 0.020496038580778506, 'mean_word_length': 3.483783783783784, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, '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': '4803546', 'n_tokens_mistral': 4848, 'n_tokens_neox': 3958, 'n_words': 783}