-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationController.rb
More file actions
90 lines (75 loc) · 2.73 KB
/
ApplicationController.rb
File metadata and controls
90 lines (75 loc) · 2.73 KB
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
class ApplicationController
attr_accessor :contentView, :tweetsTableView, :tweetsTableDelegate, :tweetTableCell, :statusLabel
def init
if !super
return nil
end
center = NSNotificationCenter.defaultCenter
center.addObserver(self,
selector: :"handleTextColorChange:",
name: PreferencesController::TextColorChangedNotification,
object: nil)
center.addObserver(self,
selector: :"handleBackgroundColorChange:",
name: PreferencesController::BackgroundColorChangedNotification,
object: nil)
center.addObserver(self,
selector: :"handleTwitterSearchQueryChange:",
name: PreferencesController::TwitterSearchQueryChangedNotification,
object: nil)
return self
end
def awakeFromNib
refreshTweets
handleTextColorChange(nil)
handleBackgroundColorChange(nil)
end
def toggleFullScreen(sender)
if contentView.isInFullScreenMode
contentView.exitFullScreenModeWithOptions(nil)
else
contentView.enterFullScreenMode(contentView.window.screen,withOptions:nil)
end
end
def handleBackgroundColorChange(notification)
statusLabel.backgroundColor = preferenceController.backgroundColor
tweetsTableView.backgroundColor = preferenceController.backgroundColor
end
def handleTextColorChange(notification)
tweetTableCell.textColor = preferenceController.textColor
# redraw table. FIXME: Find a better way to do this
tweetsTableView.reloadData
statusLabel.textColor = preferenceController.textColor
end
def handleTwitterSearchQueryChange(notification)
twitterService.cancel!
tweetsTableDelegate.tweets = []
refreshTweets
end
def preferenceController
unless @preferenceController
@preferenceController = PreferencesController.alloc.init
end
@preferenceController
end
def showPreferencePanel(sender)
preferenceController.showWindow(self)
end
def refreshTweets
statusLabel.stringValue = "Updating tweets for: #{preferenceController.twitterSearchQuery}"
twitterService.refreshSearch
end
def twitterService
if @twitterService.nil? || @twitterService.cancelled?
@twitterService = TwitterService.new(preferenceController.twitterSearchQuery, delegate: self, refreshInterval: 30)
end
@twitterService
end
def newTweetsReceived(tweets)
tweetsTableDelegate.tweets = tweets + tweetsTableDelegate.tweets
statusLabel.stringValue = "Finished updating tweets"
end
def convertColor(color)
CGColorCreateGenericRGB(color.redComponent, color.greenComponent, color.blueComponent, 1)
end
end