Skip to content

Commit

Permalink
Fix xcode warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Econa77 committed May 11, 2017
1 parent 8ba10bf commit 963e81c
Showing 1 changed file with 98 additions and 99 deletions.
197 changes: 98 additions & 99 deletions Lib/KeyHolder/RecordView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,118 +170,30 @@ public protocol RecordViewDelegate: class {
clearButton.frame = NSRect(x: x, y: y, width: clearSize, height: clearSize)
clearButton.isHidden = !showsClearButton
}
}

// MARK: - Text Attributes
private extension RecordView {
func modifierTextAttributes(_ modifiers: NSEventModifierFlags, checkModifier: NSEventModifierFlags) -> [String: Any] {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSCenterTextAlignment
paragraphStyle.lineBreakMode = NSLineBreakMode.byTruncatingTail
paragraphStyle.baseWritingDirection = NSWritingDirection.leftToRight
let textColor: NSColor
if !enabled {
textColor = .disabledControlTextColor
} else if modifiers.contains(checkModifier) {
textColor = tintColor
} else {
textColor = .lightGray
}
return [NSFontAttributeName: NSFont.systemFont(ofSize: floor(fontSize)),
NSForegroundColorAttributeName: textColor,
NSParagraphStyleAttributeName: paragraphStyle]
}

func keyCodeTextAttributes() -> [String: Any] {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = NSLineBreakMode.byTruncatingTail
paragraphStyle.baseWritingDirection = NSWritingDirection.leftToRight
return [NSFontAttributeName: NSFont.systemFont(ofSize: floor(fontSize)),
NSForegroundColorAttributeName: tintColor,
NSParagraphStyleAttributeName: paragraphStyle]
}
}

// MARK: - Recording
public extension RecordView {
public func beginRecording() -> Bool {
if !enabled { return false }
if recording { return true }

needsDisplay = true

if let delegate = delegate , !delegate.recordViewShouldBeginRecording(self) {
NSBeep()
return false
}

willChangeValue(forKey: "recording")
recording = true
didChangeValue(forKey: "recording")

updateTrackingAreas()

return true
}

public func endRecording() {
if !recording { return }

inputModifiers = NSEventModifierFlags(rawValue: 0)
doubleTapModifier = NSEventModifierFlags(rawValue: 0)
multiModifiers = false

willChangeValue(forKey: "recording")
recording = false
didChangeValue(forKey: "recording")

updateTrackingAreas()
needsDisplay = true

if window?.firstResponder == self && !canBecomeKeyView { window?.makeFirstResponder(nil) }
delegate?.recordViewDidEndRecording(self)
}
}

// MARK: - Clear Keys
public extension RecordView {
public func clear() {
keyCombo = nil
inputModifiers = NSEventModifierFlags(rawValue: 0)
needsDisplay = true
delegate?.recordViewDidClearShortcut(self)
}

public func clearAndEndRecording() {
clear()
endRecording()
}
}

// MARK: - NSReponder
public extension RecordView {
open override var acceptsFirstResponder: Bool {
// MARK: - NSResponder
override open var acceptsFirstResponder: Bool {
return enabled
}

open override var canBecomeKeyView: Bool {
override open var canBecomeKeyView: Bool {
return super.canBecomeKeyView && NSApp.isFullKeyboardAccessEnabled
}

open override var needsPanelToBecomeKey: Bool {
override open var needsPanelToBecomeKey: Bool {
return true
}

open override func resignFirstResponder() -> Bool {
override open func resignFirstResponder() -> Bool {
endRecording()
return super.resignFirstResponder()
}

open override func acceptsFirstMouse(for theEvent: NSEvent?) -> Bool {
override open func acceptsFirstMouse(for theEvent: NSEvent?) -> Bool {
return true
}

open override func mouseDown(with theEvent: NSEvent) {
override open func mouseDown(with theEvent: NSEvent) {
if !enabled {
super.mouseDown(with: theEvent)
return
Expand All @@ -295,11 +207,11 @@ public extension RecordView {
}
}

open override func keyDown(with theEvent: NSEvent) {
override open func keyDown(with theEvent: NSEvent) {
if !performKeyEquivalent(with: theEvent) { super.keyDown(with: theEvent) }
}

open override func performKeyEquivalent(with theEvent: NSEvent) -> Bool {
override open func performKeyEquivalent(with theEvent: NSEvent) -> Bool {
if !enabled { return false }
if window?.firstResponder != self { return false }

Expand Down Expand Up @@ -331,7 +243,7 @@ public extension RecordView {
return false
}

open override func flagsChanged(with theEvent: NSEvent) {
override open func flagsChanged(with theEvent: NSEvent) {
if recording {
inputModifiers = theEvent.modifierFlags
needsDisplay = true
Expand Down Expand Up @@ -387,9 +299,96 @@ public extension RecordView {
} else {
inputModifiers = NSEventModifierFlags(rawValue: 0)
}

super.flagsChanged(with: theEvent)
}

}

// MARK: - Text Attributes
private extension RecordView {
func modifierTextAttributes(_ modifiers: NSEventModifierFlags, checkModifier: NSEventModifierFlags) -> [String: Any] {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSCenterTextAlignment
paragraphStyle.lineBreakMode = NSLineBreakMode.byTruncatingTail
paragraphStyle.baseWritingDirection = NSWritingDirection.leftToRight
let textColor: NSColor
if !enabled {
textColor = .disabledControlTextColor
} else if modifiers.contains(checkModifier) {
textColor = tintColor
} else {
textColor = .lightGray
}
return [NSFontAttributeName: NSFont.systemFont(ofSize: floor(fontSize)),
NSForegroundColorAttributeName: textColor,
NSParagraphStyleAttributeName: paragraphStyle]
}

func keyCodeTextAttributes() -> [String: Any] {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = NSLineBreakMode.byTruncatingTail
paragraphStyle.baseWritingDirection = NSWritingDirection.leftToRight
return [NSFontAttributeName: NSFont.systemFont(ofSize: floor(fontSize)),
NSForegroundColorAttributeName: tintColor,
NSParagraphStyleAttributeName: paragraphStyle]
}
}

// MARK: - Recording
public extension RecordView {
public func beginRecording() -> Bool {
if !enabled { return false }
if recording { return true }

needsDisplay = true

if let delegate = delegate , !delegate.recordViewShouldBeginRecording(self) {
NSBeep()
return false
}

willChangeValue(forKey: "recording")
recording = true
didChangeValue(forKey: "recording")

updateTrackingAreas()

return true
}

public func endRecording() {
if !recording { return }

inputModifiers = NSEventModifierFlags(rawValue: 0)
doubleTapModifier = NSEventModifierFlags(rawValue: 0)
multiModifiers = false

willChangeValue(forKey: "recording")
recording = false
didChangeValue(forKey: "recording")

updateTrackingAreas()
needsDisplay = true

if window?.firstResponder == self && !canBecomeKeyView { window?.makeFirstResponder(nil) }
delegate?.recordViewDidEndRecording(self)
}
}

// MARK: - Clear Keys
public extension RecordView {
public func clear() {
keyCombo = nil
inputModifiers = NSEventModifierFlags(rawValue: 0)
needsDisplay = true
delegate?.recordViewDidClearShortcut(self)
}

public func clearAndEndRecording() {
clear()
endRecording()
}
}

// MARK: - Modifiers
Expand Down

0 comments on commit 963e81c

Please sign in to comment.