forked from ViennaRSS/vienna-rss
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ActivityViewer.m
207 lines (182 loc) · 6.01 KB
/
ActivityViewer.m
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
// ActivityViewer.m
// Vienna
//
// Created by Steve on Thu Mar 18 2004.
// Copyright (c) 2004-2005 Steve Palmer. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import "ActivityViewer.h"
#import "ActivityLog.h"
#import "AppController.h"
#import "Preferences.h"
#import "SplitViewExtensions.h"
@implementation ActivityViewer
/* init
* Just init the activity window.
*/
-(id)init
{
if ((self = [super initWithWindowNibName:@"ActivityViewer"]) != nil)
{
allItems = [[[ActivityLog defaultLog] allItems] retain];
}
return self;
}
/* windowDidLoad
* Do the things that only make sense after the window file is loaded.
*/
-(void)windowDidLoad
{
// Work around a Cocoa bug where the window positions aren't saved
[self setShouldCascadeWindows:NO];
[self setWindowFrameAutosaveName:@"activityViewer"];
[activityWindow setDelegate:self];
// Default font for the details view
NSFont * detailsFont = [NSFont fontWithName:@"Monaco" size:11.0];
[activityDetail setFont:detailsFont];
// Handle double-click on an item
[activityTable setDoubleAction:@selector(handleDoubleClick:)];
// Set window title
[activityWindow setTitle:NSLocalizedString(@"Activity Window", nil)];
// Set localised column headers
[activityTable localiseHeaderStrings];
// Restore the split position
[splitView setLayout:[[Preferences standardPreferences] objectForKey:@"SplitView3Positions"]];
// Set up to receive notifications when the activity log changes
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(handleLogChange:) name:@"MA_Notify_ActivityLogChange" object:nil];
[nc addObserver:self selector:@selector(handleDetailChange:) name:@"MA_Notify_ActivityDetailChange" object:nil];
}
/* windowShouldClose
* Since we established ourselves as the delegate for the window, we will
* get the notifications when the window closes.
*/
-(BOOL)windowShouldClose:(NSNotification *)notification
{
[[Preferences standardPreferences] setObject:[splitView layout] forKey:@"SplitView3Positions"];
return YES;
}
/* handleDoubleClick
* Handle double-click.
*/
-(IBAction)handleDoubleClick:(id)sender
{
int selectedRow = [activityTable selectedRow];
if (selectedRow >= 0)
{
ActivityItem * selectedItem = [allItems objectAtIndex:selectedRow];
// Name might be a URL if the feed has always been invalid.
Database * db = [Database sharedDatabase];
Folder * folder = [db folderFromName:[selectedItem name]];
if (folder == nil)
folder = [db folderFromFeedURL:[selectedItem name]];
if (folder != nil)
{
AppController * controller = (AppController *)[NSApp delegate];
[controller selectFolder:[folder itemId]];
}
}
}
/* reloadTable
* Reloads the table with the existing log sorted and with the selection preserved.
*/
-(void)reloadTable
{
ActivityItem * selectedItem = nil;
int selectedRow = [activityTable selectedRow];
if (selectedRow >= 0 && selectedRow < [allItems count])
selectedItem = [allItems objectAtIndex:selectedRow];
[[ActivityLog defaultLog] sortUsingDescriptors:[activityTable sortDescriptors]];
[activityTable reloadData];
if (selectedItem == nil)
[activityDetail setString:@""];
else
{
NSUInteger rowToSelect = [allItems indexOfObject:selectedItem];
if (rowToSelect != NSNotFound)
{
NSIndexSet * indexes = [NSIndexSet indexSetWithIndex:rowToSelect];
[activityTable selectRowIndexes:indexes byExtendingSelection:NO];
}
else
{
[activityTable deselectAll:nil];
}
}
}
/* handleLogChange
* Handle the notification that is broadcast when the activity log
* has items added, removed or changed.
*/
-(void)handleLogChange:(NSNotification *)nc
{
[self reloadTable];
}
/* handleDetailChange
* Handle the notification that is sent when an item detail is changed.
*/
-(void)handleDetailChange:(NSNotification *)nc
{
ActivityItem * item = (ActivityItem *)[nc object];
int selectedRow = [activityTable selectedRow];
if (selectedRow >= 0 && (item == [allItems objectAtIndex:selectedRow]))
[activityDetail setString:[item details]];
}
/* numberOfRowsInTableView [datasource]
* Datasource for the table view. Return the total number of rows we'll display which
* is equivalent to the number of log items.
*/
-(NSUInteger)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [allItems count];
}
/* tableViewSelectionDidChange [delegate]
* Handle the selection changing in the table view. Update the details portion with the full
* information for the selected source.
*/
-(void)tableViewSelectionDidChange:(NSNotification *)aNotification
{
int selectedRow = [activityTable selectedRow];
if (selectedRow >= 0 && selectedRow < [allItems count])
{
ActivityItem * item = [allItems objectAtIndex:selectedRow];
[activityDetail setString:[item details]];
}
}
/* sortDescriptorsDidChange
* Called to sort the status table by the specified descriptor.
*/
-(void)tableView:(NSTableView *)aTableView sortDescriptorsDidChange:(NSArray *)oldDescriptors
{
[self reloadTable];
}
/* objectValueForTableColumn [datasource]
* Called by the table view to obtain the object at the specified column and row.
*/
-(id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSUInteger)rowIndex
{
ActivityItem * item = [allItems objectAtIndex:rowIndex];
return ([aTableColumn identifier]) ? [item valueForKey:[aTableColumn identifier]] : @"";
}
/* dealloc
* Clean up before we're freed.
*/
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[allItems release];
[super dealloc];
}
@end