source: releases/Pester/1.1b4/Source/PSPreferencesController.m@ 332

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

VERSION: Updated for 1.1b4.

PSMovieAlertController.[hm]: Set output volume from alert; save and
restore output volume (bug 27).

PSBeepAlert.[hm]: Save and set volume, disabled pending a
synchronous equivalent to NSBeep().

NJRQTMediaPopUpButton.[hm]: Save movieHasAudio (does not include
beeps, pending the above fix, since they don't permit volume
adjustment). savedVolume indicates whether the volume has been saved
but not restored yet; outputVolume stores the set volume (eventually
incorporated into a PSMediaAlert).

PSMediaAlert.[hm]: Stores repetitions and volume information for audio
alerts. New superclass of PSBeepAlert and PSMovieAlert.

PSPreferencesController.m: Fixed bug where hot keys still appeared
even after they couldn't be set - last of bug 29. Add Command-comma
to the list of disallowed equivalents, as it's reserved for
Preferences now (still a bug - it'll show the entire set key
equivalent at the left side of the window when you press
command-comma; ah well.)

Volume [0123].png: Volume-indicating small icons from QuickTime 6.

NJRSoundManager.[hm]: Interface to volume saving, restoring, setting -
necessary because the QuickTime call to SetDefaultOutputVolume sets
the right channel volume only (bug 27).

PSVolumeController.h: Controller for volume popup window (bug 27).
Not your average NSWindowController, but it works. Keyboard control
of volume is still necessary; filed as bug 31.

PSAlarmSetController.[hm]: Added references to sound volume button and
showVolume: action. Added volume setting support (bug 27); mostly
similar interface to calendar, though we need direct calls to
NJRSoundManager to restore sound volume at times. Only enable sound
volume button if selected media file has audio component (and isn't the
system alert sound, which I discussed above). Take advantage of
PSMediaAlert to factor some code in _readAlerts:. Save and restore
volume as part of alerts.

Read Me.rtfd: Updated release notes; fixed some bizarre text
formatting problems; search/replace "* " bullet-space with "*\t"
bullet-tab to improve alignment in release notes.

PSMovieAlert.[hm]: Factored code into PSMediaAlert. Describe output
volume as percentage of maximum.

NJRHotKey.m: Fixed some odd spacing left over from Ecky's code.

PSApplication.m: Restore saved output volume on quit.

English.lproj/MainMenu.nib: Added volume button.

English.lproj/Volume.nib: Volume nib (bug 27).

PSCalendarController.m: Removed casts from a copy/paste error. Fixed
variable names in some code inherited from my TextExtras incremental
search modifications - it's not always a text field now.

File size: 5.5 KB
Line 
1//
2// PSPreferencesController.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Mar 29 2003.
6// Copyright (c) 2003 Nicholas Riley. All rights reserved.
7//
8
9#import "PSPreferencesController.h"
10#import "PSApplication.h"
11#import "NJRHotKeyField.h"
12#import "NJRHotKey.h"
13#import "NJRHotKeyManager.h"
14
15// NSUserDefaults key
16static NSString * const PSSetAlarmHotKey = @"Pester set alarm system-wide keyboard shortcut";
17
18// NJRHotKeyManager shortcut identifier
19static NSString * const PSSetAlarmHotKeyShortcut = @"PSSetAlarmHotKeyShortcut";
20
21@implementation PSPreferencesController
22
23+ (void)readPreferences;
24{
25 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
26 NJRHotKeyManager *hotKeyManager = [NJRHotKeyManager sharedManager];
27 NJRHotKey *hotKey = [[[NJRHotKey alloc] initWithPropertyList: [defaults dictionaryForKey: PSSetAlarmHotKey]] autorelease];
28
29 if (hotKey == nil) {
30 [hotKeyManager removeShortcutWithIdentifier: PSSetAlarmHotKeyShortcut];
31 } else {
32 if (![hotKeyManager addShortcutWithIdentifier: PSSetAlarmHotKeyShortcut
33 hotKey: hotKey
34 target: NSApp
35 action: @selector(orderFrontSetAlarmPanel:)]) {
36 [defaults removeObjectForKey: PSSetAlarmHotKey];
37 NSRunAlertPanel(NSLocalizedString(@"Can't reserve alarm key equivalent", "Hot key set failure"),
38 NSLocalizedString(@"Pester was unable to reserve the key equivalent %@. Please select another in Pester's Preferences, or click Clear to remove it.", "Hot key set failure"), nil, nil, nil, [hotKey keyGlyphs]);
39 [(PSApplication *)NSApp performSelector: @selector(orderFrontPreferencesPanel:) withObject: self afterDelay: 0.1];
40 }
41 }
42}
43
44#pragma mark interface updating
45
46- (void)update;
47{
48 // perform any interface propagation that needs to be done
49}
50
51#pragma mark preferences I/O
52
53- (void)readFromPrefs;
54{
55 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
56 NJRHotKey *hotKey = [[NJRHotKey alloc] initWithPropertyList: [defaults dictionaryForKey: PSSetAlarmHotKey]];
57 [setAlarmHotKey setHotKey: hotKey];
58 [hotKey release];
59}
60
61- (void)writeToPrefs;
62{
63 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
64 [defaults setObject: [[setAlarmHotKey hotKey] propertyListRepresentation] forKey: @"Pester set alarm system-wide keyboard shortcut"];
65 [defaults synchronize];
66 [[self class] readPreferences];
67}
68
69#pragma mark initialize-release
70
71- (id)init {
72 if ( (self = [super initWithWindowNibName: @"Preferences"]) != nil) {
73 [[self window] center]; // connect outlets
74 [self readFromPrefs];
75 [self update];
76 // command
77 NSMutableCharacterSet *set = [[NSCharacterSet alphanumericCharacterSet] mutableCopy];
78 [set addCharactersInString: @"`-=[]/\\, "];
79 commandRejectSet = [set copy];
80 [set release];
81 // no modifiers, shift, option, option-shift
82 set = [[NSCharacterSet alphanumericCharacterSet] mutableCopy];
83 [set formUnionWithCharacterSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
84 [set formUnionWithCharacterSet: [NSCharacterSet punctuationCharacterSet]];
85 [set addCharactersInString: @"\t\r\e\x7f\x03\x19"]; // tab, CR, escape, delete, enter, backtab
86 [set addCharactersInRange: NSMakeRange(0xF700, 0x1FF)]; // reserved function key range
87 [set removeCharactersInRange: NSMakeRange(NSF1FunctionKey, 15)]; // F1-F15
88 textRejectSet = [set copy];
89 [set release];
90 // command-shift
91 commandShiftRejectSet = [[NSCharacterSet characterSetWithCharactersInString: @"ACFGHIPQS~? "] retain];
92 // command-option
93 commandOptionRejectSet = [[NSCharacterSet characterSetWithCharactersInString: @"DW\\-= "] retain];
94 }
95 return self;
96}
97
98- (void)dealloc;
99{
100 [textRejectSet release];
101 [commandRejectSet release];
102 [commandShiftRejectSet release];
103 [commandOptionRejectSet release];
104}
105
106#pragma mark actions
107
108- (IBAction)hotKeySet:(NJRHotKeyField *)sender;
109{
110 [self writeToPrefs];
111}
112
113- (IBAction)showWindow:(id)sender;
114{
115 [self readFromPrefs];
116 [super showWindow: sender];
117}
118
119@end
120
121@implementation PSPreferencesController (NJRHotKeyFieldDelegate)
122
123- (BOOL)hotKeyField:(NJRHotKeyField *)hotKeyField shouldAcceptCharacter:(unichar)keyChar modifierFlags:(unsigned)modifierFlags rejectionMessage:(NSString **)message;
124{
125 *message = nil;
126
127 if (modifierFlags == 0 || modifierFlags == NSShiftKeyMask || modifierFlags == NSAlternateKeyMask || modifierFlags == (NSShiftKeyMask | NSAlternateKeyMask)) {
128 *message = modifierFlags == 0 ? @"key is reserved for typing text" :
129 @"key combination is reserved for typing text";
130 return ![textRejectSet characterIsMember: keyChar];
131 }
132 if (modifierFlags == NSCommandKeyMask) {
133 *message = @"key combination is reserved for application use";
134 return ![commandRejectSet characterIsMember: keyChar];
135 }
136 if (modifierFlags == (NSCommandKeyMask | NSShiftKeyMask)) {
137 *message = @"key combination is reserved for application use";
138 return ![commandShiftRejectSet characterIsMember: keyChar];
139 }
140 if (modifierFlags == (NSCommandKeyMask | NSAlternateKeyMask)) {
141 *message = @"key combination is reserved for Mac OS X use";
142 return ![commandOptionRejectSet characterIsMember: keyChar];
143 }
144 return YES;
145}
146
147@end
Note: See TracBrowser for help on using the repository browser.