-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeedsController.rb
69 lines (57 loc) · 1.97 KB
/
FeedsController.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
framework 'PubSub'
class FeedsController
attr_writer :feedsTableView
attr_writer :entriesTableView
def awakeFromNib
@client = PSClient.applicationClient
@feeds = @client.feeds
selectFeed 0
@feeds.each { |feed| feed.refresh nil }
end
def addSearch(sender)
search = sender.stringValue
addFeed(search) if search.size > 0
end
def addFeed(query)
url = "http://search.twitter.com/search.atom?rpp=100&q=#{query.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)}"
feed = @client.addFeedWithURL NSURL.URLWithString(url)
NSNotificationCenter.defaultCenter.addObserver self, selector:"refresh:", name:PSFeedRefreshingNotification, object:feed
feed.refresh nil
@feeds = @client.feeds
@feedsTableView.reloadData
end
def refresh(notification)
feed = notification.object
@feedsTableView.reloadData unless feed.isRefreshing
end
def numberOfRowsInTableView(view)
@feeds.size
end
def tableView(view, objectValueForTableColumn:column, row:index)
query = @feeds[index].URL.query.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
" #{ query.split('q=').last.split('+').last.gsub('from:', '@') }".with_attributes({
:baseline_offset => 2,
:font => NSFont.systemFontOfSize(12)
})
end
def selectFeed(index)
if @feeds.size > 0
@feedsTableView.selectRowIndexes NSIndexSet.indexSetWithIndex(index), byExtendingSelection:false
tableView @feedsTableView, shouldSelectRow:index
end
end
def removeFeed(index)
@client.removeFeed @feeds.slice!(index)
@feedsTableView.reloadData
selectFeed index - 1
end
def tableView(tableView, shouldSelectRow:index)
@entriesTableView.dataSource.displayEntries @feeds[index].entries.reverse
@entriesTableView.setIntercellSpacing [ 0, 1 ]
@entriesTableView.reloadData
true
end
def windowDidBecomeMain(notification)
notification.object.setBackgroundColor @feedsTableView.backgroundColor
end
end