source: releases/Pester/1.1b1/Source/PSAlarmsController.m@ 138

Last change on this file since 138 was 53, checked in by Nicholas Riley, 22 years ago

Updated for Pester 1.1a5 (very limited release).

Pester 1.1a4 was never released.

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