source: releases/Pester/1.0b1/Source/PSAlarmsController.m@ 522

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

Pester 1.0b1

File size: 3.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
13
14@implementation PSAlarmsController
15
16- (id)init;
17{
18 if ( (self = [super initWithWindowNibName: @"Alarms"]) != nil) {
19 alarms = [PSAlarms allAlarms];
20 [[self window] center];
21 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(alarmsChanged) name: PSAlarmsDidChangeNotification object: alarms];
22 [tableView setAutosaveName: @"Alarm list"];
23 [tableView setAutosaveTableColumns: YES];
24 [tableView noteNumberOfRowsChanged];
25 [[self window] makeFirstResponder: tableView];
26 }
27 return self;
28}
29
30- (void)alarmsChanged; // XXX fix autoselection to be more reasonable, see whatever I did in that _Learning Cocoa_ project I think
31{
32 [tableView reloadData];
33 [tableView deselectAll: self];
34}
35
36- (IBAction)remove:(id)sender;
37{
38 [alarms removeAlarmsAtIndices: [[tableView selectedRowEnumerator] allObjects]];
39}
40
41@end
42
43@implementation PSAlarmsController (NSTableDataSource)
44
45- (int)numberOfRowsInTableView:(NSTableView *)tableView;
46{
47 return [alarms alarmCount];
48}
49
50- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;
51{
52 PSAlarm *alarm = [alarms alarmAtIndex: row];
53
54 if ([[tableColumn identifier] isEqualToString: @"message"]) return [alarm message];
55 else {
56 NSCalendarDate *date = [alarm date];
57 if ([[tableColumn identifier] isEqualToString: @"date"]) return [date descriptionWithCalendarFormat: [[NSUserDefaults standardUserDefaults] stringForKey: NSShortDateFormatString]];
58 if ([[tableColumn identifier] isEqualToString: @"time"]) {
59 if (date == nil) return @"ÇexpiredÈ";
60 return [date descriptionWithCalendarFormat: @"%1I:%M:%S%p"]; // XXX regular format doesn't work
61 }
62 }
63 return nil;
64}
65@end
66
67@implementation PSAlarmsController (NSTableViewNotifications)
68
69- (void)tableViewSelectionDidChange:(NSNotification *)aNotification;
70{
71 [removeButton setEnabled: ([tableView numberOfSelectedRows] != 0)];
72}
73
74@end
75
76@implementation PSAlarmsController (NSWindowDelegate)
77
78- (NSRect)windowWillUseStandardFrame:(NSWindow *)sender defaultFrame:(NSRect)defaultFrame;
79{
80 NSWindow *window = [tableView window];
81 NSRect frame = [window frame];
82 NSScrollView *scrollView = [tableView enclosingScrollView];
83 float displayedHeight = [[scrollView contentView] bounds].size.height;
84 float heightChange = [[scrollView documentView] bounds].size.height - displayedHeight;
85 float heightExcess;
86
87 if (heightChange >= 0 && heightChange <= 1) {
88 // either the window is already optimal size, or it's too big
89 float rowHeight = [tableView cellHeight];
90 heightChange = (rowHeight * [tableView numberOfRows]) - displayedHeight;
91 }
92
93 frame.size.height += heightChange;
94
95 if ( (heightExcess = [window minSize].height - frame.size.height) > 1 ||
96 (heightExcess = [window maxSize].height - frame.size.height) < 1) {
97 heightChange += heightExcess;
98 frame.size.height += heightExcess;
99 }
100
101 frame.origin.y -= heightChange;
102
103 return frame;
104}
105
106@end
107
Note: See TracBrowser for help on using the repository browser.