source: trunk/Cocoa/Pester/Source/PSAlarmsController.m@ 51

Last change on this file since 51 was 51, checked in by Nicholas Riley, 21 years ago

Alarms.nib: Removed horizontal scroll bar. Turned on grid. Set delegate to NJRTableDelegate instead of PSAlarmSetController.

NJRTableDelegate: In general, made functional (was previously unused). Fixed MyCompanyName. Changed ORDER_BY_CONTEXT to use key-value coding instead of assuming data consists of a dictionary of dictionaries. Added sorting support (reorderedData, replaces oData) with autosave support for sort context. Added _positionTypeSelectDisplay, which adjusts position and justification of type select display control based on the current sort column. Added support for reverse sorting in type select string. Use table data source instead of sorted data so text matches as displayed (this will break with non-text cells...).

NJRTableView: Adapted from iTableView (Jaguar table alternate table background color), TableTester (most everything else) and NJROutlineView (keyDown, moveToBeginning/EndOfDocument). Support for type selection, delete shortcut for row deletion, and iTunes-alike background colors and frame.

NSCharacterSet-NJRExtensions: Moved _typeSelectSet from NJROutlineView as it's now shared with NJRTableView. Still need to factor NJROutlineView as embedded in HostLauncher some day.

PSAlarm: Reorganized, renamed and categorized methods. Added time accessor for the benefit of sorting. Renamed compare: to compareDate: for clarity. Added compareMessage:, though it's currently unused. Renamed cancel to cancelTimer for clarity.

PSAlarmSetController: More fun with initial first responder on window show/hide; still need to work around bug properly (subclass NSComboBox?) and fix it for real. As is, works for OS X 10.1.

PSAlarms: Added alarms accessor, returning alarm array. Fixed memory leak on successful alarm removal (oops). Added removeAlarms:, needed with sorted alarm list.

PSAlarmsController: Set window resize increment. Changes to table delegate methods to use reordered alarm list. Register for NSTableViewSelectionDidChangeNotification now we're no longer the table view delegate. Fixed autoselection in alarmsChanged by using data reordering support in NJRTableView. Implement NJRTableViewDataSource to permit deletion from table view.

Pester.pbproj: Added new files.

Read Me.rtfd: Added TableTester/iTableView acknowledgements. Updated release notes.

File size: 4.3 KB
Line 
1//
2// PSAlarmsController.m
3// Pester
4//
5// Created by Nicholas Riley on Fri Oct 11 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSAlarmsController.h"
10#import "PSAlarm.h"
11#import "NSTableView-NJRExtensions.h"
12#import "NJRTableView.h"
13#import "NJRTableDelegate.h"
14
15@implementation PSAlarmsController
16
17- (void)alarmsChanged;
18{
19 reorderedAlarms = [[tableView delegate] reorderedDataForData: [alarms alarms]];
20}
21
22- (id)init;
23{
24 if ( (self = [super initWithWindowNibName: @"Alarms"]) != nil) {
25 alarms = [PSAlarms allAlarms];
26 // XXX workaround for bug in 10.2.1, 10.1.5: autosave name set in IB doesn't show up
27 [self setWindowFrameAutosaveName: @"Pester alarm list"];
28 // Apple documents the NSUserDefaults key, so we can rely on it hopefully.
29 if (nil == [[NSUserDefaults standardUserDefaults] objectForKey:
30 [@"NSWindow Frame " stringByAppendingString: [[self window] frameAutosaveName]]])
31 {
32 [[self window] center];
33 }
34 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(alarmsChanged) name: PSAlarmsDidChangeNotification object: alarms];
35 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(tableViewSelectionDidChange:) name: NSTableViewSelectionDidChangeNotification object: tableView];
36 [tableView setAutosaveName: @"Alarm list"];
37 [tableView setAutosaveTableColumns: YES];
38 [self alarmsChanged];
39 [[self window] makeFirstResponder: tableView];
40 [[self window] setResizeIncrements: NSMakeSize(1, [tableView cellHeight])];
41 }
42 return self;
43}
44
45
46- (IBAction)remove:(id)sender;
47{
48 [alarms removeAlarms: [[tableView delegate] selectedItems]];
49}
50
51@end
52
53@implementation PSAlarmsController (NSTableDataSource)
54
55- (int)numberOfRowsInTableView:(NSTableView *)tableView;
56{
57 return [alarms alarmCount];
58}
59
60- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;
61{
62 PSAlarm *alarm = [reorderedAlarms objectAtIndex: row];
63
64 if ([[tableColumn identifier] isEqualToString: @"message"]) return [alarm message];
65 else {
66 NSCalendarDate *date = [alarm date];
67 if ([[tableColumn identifier] isEqualToString: @"date"]) return [alarm shortDateString];
68 if ([[tableColumn identifier] isEqualToString: @"time"]) {
69 if (date == nil) return @"ÇexpiredÈ";
70 return [alarm timeString];
71 }
72 }
73 return nil;
74}
75@end
76
77@implementation PSAlarmsController (NJRTableViewDataSource)
78
79- (void)removeSelectedRowsFromTableView:(NSTableView *)aTableView;
80{
81 [self remove: aTableView];
82}
83
84@end
85
86@implementation PSAlarmsController (NSTableViewNotifications)
87
88- (void)tableViewSelectionDidChange:(NSNotification *)aNotification;
89{
90 [removeButton setEnabled: ([tableView numberOfSelectedRows] != 0)];
91}
92
93@end
94
95@implementation PSAlarmsController (NSWindowDelegate)
96
97// XXX workaround for bug in 10.1.5, 10.2.1 (and earlier?): no autosave on window move
98- (void)windowDidMove:(NSNotification *)aNotification
99{
100 NSString *autosaveName = [[self window] frameAutosaveName];
101 // on initial display, we get a notification inside -[NSWindow setFrameAutosaveName]!
102 if (autosaveName != nil) {
103 [[self window] saveFrameUsingName: autosaveName];
104 }
105}
106
107- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame;
108{
109 NSWindow *window = [tableView window];
110 NSRect frame = [window frame];
111 NSScrollView *scrollView = [tableView enclosingScrollView];
112 float displayedHeight = [[scrollView contentView] bounds].size.height;
113 float heightChange = [[scrollView documentView] bounds].size.height - displayedHeight;
114 float heightExcess;
115
116 if (heightChange >= 0 && heightChange <= 1) {
117 // either the window is already optimal size, or it's too big
118 float rowHeight = [tableView cellHeight];
119 heightChange = (rowHeight * [tableView numberOfRows]) - displayedHeight;
120 }
121
122 frame.size.height += heightChange;
123
124 if ( (heightExcess = [window minSize].height - frame.size.height) > 1 ||
125 (heightExcess = [window maxSize].height - frame.size.height) < 1) {
126 heightChange += heightExcess;
127 frame.size.height += heightExcess;
128 }
129
130 frame.origin.y -= heightChange;
131
132 return frame;
133}
134
135@end
Note: See TracBrowser for help on using the repository browser.