source: releases/Pester/1.1b5/Source/PSAlarmsController.m@ 632

Last change on this file since 632 was 355, checked in by Nicholas Riley, 17 years ago

English.lproj/MainMenu.nib: Modernize menu and alarm set dialog
layout. Use keyed archiving (10.2+) nib format.

Info-Pester.plist: Moved from old PBX project.

NJRFSObjectSelector.m: Bug fixes from code sent to Joey: remove
incorrect usage of tryToPerform:with:; fix logic error in menu
construction. Work around Cocoa's deciding that the menu font size
needs adjustment when it doesn't - so the menu font size now matches
the button font size, though the position is still off. Don't pop up
a menu if we're disabled. Use IconRefs for menu icons, though not
(yet) for the button icon.

NJRHistoryTrackingComboBox.m: Remove item height adjustment
workaround; it now makes the items too tall.

NJRHotKey.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyField.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyManager.m: Add a missing [super dealloc] caught by current
GCC.

NJRIntervalField.m: Fix some type errors.

NJRQTMediaPopUpButton.m: Replace SoundFileManager SPI usage, which
doesn't work in Leopard anyway, with manual enumeration of system
sounds. Start migration to QTKit. Use IconRefs for menu icons.

NJRReadMeController.m: Change source encoding to UTF-8.

NJRSoundManager.m: Fix a type error.

NJRVoicePopUpButton.m: Change source encoding to UTF-8.

NSMenuItem-NJRExtensions.[hm]: Code from ICeCoffEE to use IconRefs for
menu item icons.

PSAlarm.m: Change source encoding to UTF-8.

PSAlarms.m: Fix a signedness mismatch.

PSAlarmsController.m: Change source encoding to UTF-8.

PSAlarmSetController.m: Set keyboard focus after unchecking "Do
script:" and "Play" checkboxes.

PSAlerts.m: Add a missing [super dealloc] caught by current GCC. Fix
a memory leak in property list serialization.

PSPowerManager.[hm]: There's now API for scheduling wakeups; use it
(the old code asserted on startup). To fix: removing scheduled
wakeup. Fix a small type-checking error.

PSPreferencesController.m: Add a missing [super dealloc] caught by
current GCC.

PSScriptAlert.m: Change source encoding to UTF-8.

PSTimeDateEditor.m: Fix a tiny, and one-time, memory leak.

PSTimer.m: Update for new PSPowerManager API.

Pester.pbproj: Deleted; now supporting OS X 10.4+ (up from 10.1,
aiee.)

Pester.xcodeproj: Xcode 2.4+ project, upgraded targets, etc.

SoundFileManager.h: Deleted; this SPI no longer exists in Leopard and
possibly earlier.

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