source: trunk/Cocoa/Pester/Source/PSAlerts.m@ 355

Last change on this file since 355 was 355, checked in by Nicholas Riley, 16 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: 3.8 KB
RevLine 
[53]1//
2// PSAlerts.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Dec 21 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSAlerts.h"
10#import "PSAlert.h"
11#import "PSDockBounceAlert.h"
12#import "PSNotifierAlert.h"
13#import "PSBeepAlert.h"
14
15// property list keys
16static NSString * const PLAlerts = @"alerts"; // NSString
17
18@implementation PSAlerts
19
20#pragma mark initialize-release
21
22- (id)init;
23{
24 if ( (self = [super init]) != nil) {
25 alerts = [[NSMutableArray alloc] initWithCapacity: 4];
26 }
27 return self;
28}
29
30- (id)initWithPesterVersion1Alerts;
31{
32 if ( (self = [self init]) != nil) {
33 [self addAlert: [PSDockBounceAlert alert]];
34 [self addAlert: [PSNotifierAlert alert]];
35 [self addAlert: [PSBeepAlert alertWithRepetitions: 1]];
36 }
37 return self;
38}
39
40- (void)dealloc;
41{
42 [alerts release]; alerts = nil;
[355]43 [super dealloc];
[53]44}
45
46#pragma mark accessing
47
48- (void)addAlert:(PSAlert *)alert;
49{
50 [alerts addObject: alert];
51 if ([alert requiresPesterFrontmost])
52 requirePesterFrontmost = YES;
53}
54
55- (void)removeAlerts;
56{
57 [alerts removeAllObjects];
58 requirePesterFrontmost = NO;
59}
60
61- (NSEnumerator *)alertEnumerator;
62{
63 return [alerts objectEnumerator];
64}
65
66- (NSArray *)allAlerts;
67{
68 return [[alerts copy] autorelease];
69}
70
71- (BOOL)requirePesterFrontmost;
72{
73 return requirePesterFrontmost;
74}
75
76#pragma mark actions
77
[61]78- (void)prepareForAlarm:(PSAlarm *)alarm;
79{
80 [alerts makeObjectsPerformSelector: @selector(prepareForAlarm:) withObject: alarm];
81}
82
[53]83- (void)triggerForAlarm:(PSAlarm *)alarm;
84{
85 [alerts makeObjectsPerformSelector: @selector(triggerForAlarm:) withObject: alarm];
86}
87
88#pragma mark printing
89
90- (NSAttributedString *)prettyList;
91{
92 NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
93 NSEnumerator *e = [self alertEnumerator];
94 PSAlert *alert;
95 unsigned int length;
96 while ( (alert = [e nextObject]) != nil) {
[103]97 [string appendAttributedString: [NSLocalizedString(@"* ", "Unordered list label (usually a bullet followed by a space)") small]];
[53]98 [string appendAttributedString: [alert actionDescription]];
99 [string appendAttributedString: [@"\n" small]];
100 }
101 if ( (length = [string length]) == 0) {
102 [string release];
103 return nil;
104 } else {
105 NSMutableParagraphStyle *paraStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
106 [string deleteCharactersInRange: NSMakeRange(length - 1, 1)]; // remove trailing newline
[103]107 [paraStyle setHeadIndent: [[string attribute: NSFontAttributeName atIndex: 0 effectiveRange: NULL] widthOfString: NSLocalizedString(@"* ", "Unordered list label (usually a bullet followed by a space)")]];
[53]108 [string addAttribute: NSParagraphStyleAttributeName value: paraStyle range: NSMakeRange(0, length - 1)];
109 [paraStyle release]; paraStyle = nil;
110 return [string autorelease];
111 }
112}
113
114#pragma mark property list serialization (Pester 1.1)
115
116- (NSDictionary *)propertyListRepresentation;
117{
118 NSMutableArray *plAlerts = [[NSMutableArray alloc] initWithCapacity: [alerts count]];
119 NSEnumerator *e = [self alertEnumerator];
120 PSAlert *alert;
121 while ( (alert = [e nextObject]) != nil) {
122 [plAlerts addObject: [alert propertyListRepresentation]];
123 }
[355]124 NSDictionary *dict = [NSDictionary dictionaryWithObject: plAlerts forKey: PLAlerts];
125 [plAlerts release];
126 return dict;
[53]127}
128
129- (id)initWithPropertyList:(NSDictionary *)dict;
130{
131 if ( (self = [self init]) != nil) {
132 NSArray *plAlerts = [dict objectForKey: PLAlerts];
133 NSEnumerator *e = [plAlerts objectEnumerator];
134 NSDictionary *alertDict;
135 while ( (alertDict = [e nextObject]) != nil) {
136 [self addAlert: [[PSAlert alloc] initWithPropertyList: alertDict]];
137 }
138 }
139 return self;
140}
141
142@end
Note: See TracBrowser for help on using the repository browser.