Browse Source

Formatting!

pull/101/head
Abhishek Banthia 3 years ago
parent
commit
13eba45efa
  1. 5
      Clocker/Panel/UI/TimezoneCellView.swift
  2. 54
      Clocker/Panel/UI/Toasty.swift
  3. 8
      Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift
  4. 5
      Clocker/Preferences/Appearance/AppearanceViewController.swift
  5. 6
      Clocker/Preferences/Calendar/CalendarViewController.swift

5
Clocker/Panel/UI/TimezoneCellView.swift

@ -128,7 +128,8 @@ class TimezoneCellView: NSTableCellView {
} }
guard let customFont = customName.font, guard let customFont = customName.font,
let timeFont = time.font else { let timeFont = time.font
else {
assertionFailure("User Font Size is in unexpectedly nil") assertionFailure("User Font Size is in unexpectedly nil")
return return
} }
@ -204,7 +205,7 @@ class TimezoneCellView: NSTableCellView {
pasteboard.declareTypes([.string], owner: nil) pasteboard.declareTypes([.string], owner: nil)
pasteboard.setString(clipboardCopy, forType: .string) pasteboard.setString(clipboardCopy, forType: .string)
self.window?.contentView?.makeToast("Copied to Clipboard".localized()) window?.contentView?.makeToast("Copied to Clipboard".localized())
window?.endEditing(for: nil) window?.endEditing(for: nil)
} }

54
Clocker/Panel/UI/Toasty.swift

@ -1,13 +1,14 @@
// Copyright © 2015 Abhishek Banthia // Copyright © 2015 Abhishek Banthia
import Foundation
import AppKit import AppKit
import Foundation
extension CGRect { extension CGRect {
static func center(of layer: CALayer) -> CGPoint { static func center(of layer: CALayer) -> CGPoint {
let parentSize = layer.frame.size let parentSize = layer.frame.size
return CGPoint(x: parentSize.width / 2, y: parentSize.height / 2) return CGPoint(x: parentSize.width / 2, y: parentSize.height / 2)
} }
static func center(of parent: NSView) -> CGPoint { static func center(of parent: NSView) -> CGPoint {
let parentSize = parent.frame.size let parentSize = parent.frame.size
return CGPoint(x: parentSize.width / 2, y: parentSize.height / 6) return CGPoint(x: parentSize.width / 2, y: parentSize.height / 6)
@ -22,18 +23,21 @@ extension String {
} }
} }
fileprivate class HideAnimationDelegate: NSObject, CAAnimationDelegate { private class HideAnimationDelegate: NSObject, CAAnimationDelegate {
private weak var view: NSView? private weak var view: NSView?
fileprivate init(view: NSView) { fileprivate init(view: NSView) {
self.view = view self.view = view
} }
fileprivate static func delegate(forView NSView: NSView) -> CAAnimationDelegate { fileprivate static func delegate(forView NSView: NSView) -> CAAnimationDelegate {
return HideAnimationDelegate(view: NSView) return HideAnimationDelegate(view: NSView)
} }
fileprivate func animationDidStart(_ anim: CAAnimation) {
fileprivate func animationDidStart(_: CAAnimation) {
view?.layer?.opacity = 0.0 view?.layer?.opacity = 0.0
} }
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
func animationDidStop(_: CAAnimation, finished _: Bool) {
view?.removeFromSuperview() view?.removeFromSuperview()
view = nil view = nil
} }
@ -68,32 +72,34 @@ public protocol Style {
var activitySize: CGSize { get } var activitySize: CGSize { get }
} }
extension Style { public extension Style {
public var labelOriginWithMargin: CGPoint { var labelOriginWithMargin: CGPoint {
return CGPoint(x: horizontalMargin, y: verticalMargin) return CGPoint(x: horizontalMargin, y: verticalMargin)
} }
public var fontSize: CGFloat {return 12}
public var font: NSFont { var fontSize: CGFloat { return 12 }
var font: NSFont {
if let avenirFont = NSFont(name: "Avenir-Light", size: fontSize) { if let avenirFont = NSFont(name: "Avenir-Light", size: fontSize) {
return avenirFont return avenirFont
} }
return NSFont.systemFont(ofSize: fontSize) return NSFont.systemFont(ofSize: fontSize)
} }
public var horizontalMargin: CGFloat {return 10}
public var verticalMargin: CGFloat {return 5} var horizontalMargin: CGFloat { return 10 }
public var cornerRadius: CGFloat {return 8} var verticalMargin: CGFloat { return 5 }
public var backgroundColor: NSColor {return .black} var cornerRadius: CGFloat { return 8 }
public var foregroundColor: NSColor {return .white} var backgroundColor: NSColor { return .black }
public var activitySize: CGSize {return CGSize(width: 100, height: 100)} var foregroundColor: NSColor { return .white }
public var fadeInOutDuration: CGFloat {return 1.0} var activitySize: CGSize { return CGSize(width: 100, height: 100) }
public var fadeInOutDelay: CGFloat {return 1.0} var fadeInOutDuration: CGFloat { return 1.0 }
var fadeInOutDelay: CGFloat { return 1.0 }
} }
public struct DefaultStyle: Style { public struct DefaultStyle: Style {
public static let shared = DefaultStyle() public static let shared = DefaultStyle()
} }
private struct ToastKeys { private enum ToastKeys {
static var ActiveToast = "TSToastActiveToastKey" static var ActiveToast = "TSToastActiveToastKey"
} }
@ -103,8 +109,8 @@ class ToastView: NSView {
private let style: Style private let style: Style
init(message: String) { init(message: String) {
self.message = message self.message = message
self.style = DefaultStyle() style = DefaultStyle()
self.labelSize = message.size(with: style.fontSize) labelSize = message.size(with: style.fontSize)
let size = CGSize( let size = CGSize(
width: labelSize.width + style.horizontalMargin * 2, width: labelSize.width + style.horizontalMargin * 2,
height: labelSize.height + style.verticalMargin * 2 height: labelSize.height + style.verticalMargin * 2
@ -113,7 +119,9 @@ class ToastView: NSView {
super.init(frame: rect) super.init(frame: rect)
wantsLayer = true wantsLayer = true
} }
required init?(coder aDecoder: NSCoder) { fatalError() }
@available(*, unavailable)
required init?(coder _: NSCoder) { fatalError() }
override func viewDidMoveToSuperview() { override func viewDidMoveToSuperview() {
super.viewDidMoveToSuperview() super.viewDidMoveToSuperview()
@ -155,10 +163,10 @@ class ToastView: NSView {
} }
} }
extension NSView { public extension NSView {
public func makeToast(_ message: String) { func makeToast(_ message: String) {
let toast = ToastView(message: message) let toast = ToastView(message: message)
self.addSubview(toast) addSubview(toast)
hideAnimation(view: toast, style: DefaultStyle.shared) hideAnimation(view: toast, style: DefaultStyle.shared)
} }
} }

8
Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift

@ -11,7 +11,7 @@ extension NSNib.Name {
static let startAtLoginViewIdentifier = NSNib.Name("StartAtLoginView") static let startAtLoginViewIdentifier = NSNib.Name("StartAtLoginView")
} }
struct AppFeedbackConstants { enum AppFeedbackConstants {
static let CLAppFeedbackNibIdentifier = "AppFeedbackWindow" static let CLAppFeedbackNibIdentifier = "AppFeedbackWindow"
static let CLAppFeedbackNoResponseString = "Not Provided" static let CLAppFeedbackNoResponseString = "Not Provided"
static let CLAppFeedbackNameProperty = "name" static let CLAppFeedbackNameProperty = "name"
@ -59,7 +59,7 @@ class AppFeedbackWindowController: NSWindowController {
} }
} }
static var sharedWindow: AppFeedbackWindowController = AppFeedbackWindowController(windowNibName: NSNib.Name.appFeedbackWindowIdentifier) static var sharedWindow = AppFeedbackWindowController(windowNibName: NSNib.Name.appFeedbackWindowIdentifier)
override func windowDidLoad() { override func windowDidLoad() {
super.windowDidLoad() super.windowDidLoad()
@ -100,6 +100,7 @@ class AppFeedbackWindowController: NSWindowController {
} }
} }
@available(*, unavailable)
required init?(coder _: NSCoder) { required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
@ -144,7 +145,8 @@ class AppFeedbackWindowController: NSWindowController {
private func retrieveDataForSending() -> [String: String] { private func retrieveDataForSending() -> [String: String] {
guard let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String, guard let shortVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String,
let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String else { let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String
else {
return [:] return [:]
} }

5
Clocker/Preferences/Appearance/AppearanceViewController.swift

@ -183,7 +183,8 @@ class AppearanceViewController: ParentViewController {
refresh(panel: true, floating: true) refresh(panel: true, floating: true)
if let selectedFormat = sender.selectedItem?.title, if let selectedFormat = sender.selectedItem?.title,
selectedFormat.contains("ss") { selectedFormat.contains("ss")
{
print("Seconds are contained") print("Seconds are contained")
guard let panelController = PanelController.panel() else { return } guard let panelController = PanelController.panel() else { return }
panelController.pauseTimer() panelController.pauseTimer()
@ -193,7 +194,7 @@ class AppearanceViewController: ParentViewController {
previewPanelTableView.reloadData() previewPanelTableView.reloadData()
} }
private var previousBackgroundColor: NSColor = NSColor.white private var previousBackgroundColor = NSColor.white
@IBAction func themeChanged(_ sender: NSSegmentedControl) { @IBAction func themeChanged(_ sender: NSSegmentedControl) {
previousBackgroundColor = Themer.shared().mainBackgroundColor() previousBackgroundColor = Themer.shared().mainBackgroundColor()

6
Clocker/Preferences/Calendar/CalendarViewController.swift

@ -239,13 +239,15 @@ extension CalendarViewController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? { func tableView(_ tableView: NSTableView, viewFor _: NSTableColumn?, row: Int) -> NSView? {
if let currentSource = calendars[row] as? String, if let currentSource = calendars[row] as? String,
let message = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "sourceCellView"), owner: self) as? SourceTableViewCell { let message = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "sourceCellView"), owner: self) as? SourceTableViewCell
{
message.sourceName.stringValue = currentSource message.sourceName.stringValue = currentSource
return message return message
} }
if let currentSource = calendars[row] as? CalendarInfo, if let currentSource = calendars[row] as? CalendarInfo,
let calendarCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "calendarCellView"), owner: self) as? CalendarTableViewCell { let calendarCell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "calendarCellView"), owner: self) as? CalendarTableViewCell
{
calendarCell.calendarName.stringValue = currentSource.calendar.title calendarCell.calendarName.stringValue = currentSource.calendar.title
calendarCell.calendarSelected.state = currentSource.selected ? NSControl.StateValue.on : NSControl.StateValue.off calendarCell.calendarSelected.state = currentSource.selected ? NSControl.StateValue.on : NSControl.StateValue.off
calendarCell.calendarSelected.target = self calendarCell.calendarSelected.target = self

Loading…
Cancel
Save