-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimerWindowController.rb
executable file
·110 lines (91 loc) · 2.45 KB
/
TimerWindowController.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# AboutWindowsController.rb
# Timey
#
# Created by Jade Meskill on 9/28/10.
# Copyright 2010 Integrum Technologies, LLC. All rights reserved.
class TimerWindowController < NSWindowController
attr_accessor :timeLabel, :startButton, :countdownTimer
attr_accessor :playButton, :pauseButton, :stopButton, :reloadButton
attr_accessor :appDelegate
def show(sender)
self.appDelegate = sender
NSApp.activateIgnoringOtherApps(true)
window
invalidateTimer
updateDisplay
addObservers
showWindow(sender)
setWindowLevel
end
def addObservers
NSNotificationCenter.defaultCenter.addObserver(self, selector:(:defaultsChanged), name:"NSUserDefaultsDidChangeNotification", object:nil)
end
def defaultsChanged
setWindowLevel
appDelegate.updateStatusBar
if appDelegate.origStartingTime != NSUserDefaults.standardUserDefaults.integerForKey("defaultStartingTime")
invalidateTimer
resetTime
end
end
def setWindowLevel
if NSUserDefaults.standardUserDefaults.boolForKey("stayOnTop")
window.level = NSModalPanelWindowLevel
else
window.level = NSNormalWindowLevel
end
end
def close
window.close
end
def updateDisplay
timeLabel.stringValue = appDelegate.currentTimeAsString
appDelegate.updateStatusBar
end
def resetTime
appDelegate.resetCurrentTime
updateDisplay
end
def invalidateTimer
@countdownTimer.invalidate if @countdownTimer
playButton.enabled = true
pauseButton.enabled = false
stopButton.enabled = false
end
def startTime
close if NSUserDefaults.standardUserDefaults.boolForKey("hideOnTimerStart")
@countdownTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target:self, selector:(:countDown), userInfo:nil, repeats:true)
playButton.enabled = false
stopButton.enabled = true
pauseButton.enabled = true
end
def startTimer(sender)
startTime
end
def stopTimer(sender)
invalidateTimer
resetTime
end
def pauseTimer(sender)
invalidateTimer
end
def reloadTimer(sender)
invalidateTimer
resetTime
startTime
end
def onTimerComplete
wc = TimerCompleteController.alloc.initWithWindowNibName("TimerCompleteFullScreen")
wc.show(self)
end
def countDown
appDelegate.currentTime -= 1
if appDelegate.currentTime <= 0
appDelegate.currentTime = 0
invalidateTimer
updateDisplay
onTimerComplete
end
updateDisplay
end
end