source: trunk/Cocoa/Pester/Source/PSPreferencesController.m@ 468

Last change on this file since 468 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.5 KB
RevLine 
[129]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"
[131]10#import "PSApplication.h"
[129]11#import "NJRHotKeyField.h"
[131]12#import "NJRHotKey.h"
13#import "NJRHotKeyManager.h"
[129]14
[131]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
[129]21@implementation PSPreferencesController
22
[131]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:)]) {
[133]36 [defaults removeObjectForKey: PSSetAlarmHotKey];
[131]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
[129]44#pragma mark interface updating
45
46- (void)update;
47{
[130]48 // perform any interface propagation that needs to be done
[129]49}
50
51#pragma mark preferences I/O
52
53- (void)readFromPrefs;
54{
[130]55 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[131]56 NJRHotKey *hotKey = [[NJRHotKey alloc] initWithPropertyList: [defaults dictionaryForKey: PSSetAlarmHotKey]];
57 [setAlarmHotKey setHotKey: hotKey];
58 [hotKey release];
[129]59}
60
61- (void)writeToPrefs;
62{
63 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[131]64 [defaults setObject: [[setAlarmHotKey hotKey] propertyListRepresentation] forKey: @"Pester set alarm system-wide keyboard shortcut"];
[129]65 [defaults synchronize];
[131]66 [[self class] readPreferences];
[129]67}
68
69#pragma mark initialize-release
70
71- (id)init {
72 if ( (self = [super initWithWindowNibName: @"Preferences"]) != nil) {
[131]73 [[self window] center]; // connect outlets
[129]74 [self readFromPrefs];
75 [self update];
[130]76 // command
77 NSMutableCharacterSet *set = [[NSCharacterSet alphanumericCharacterSet] mutableCopy];
[133]78 [set addCharactersInString: @"`-=[]/\\, "];
[130]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];
[129]94 }
95 return self;
96}
97
98- (void)dealloc;
99{
[130]100 [textRejectSet release];
101 [commandRejectSet release];
102 [commandShiftRejectSet release];
103 [commandOptionRejectSet release];
[355]104 [super dealloc];
[130]105}
[129]106
[130]107#pragma mark actions
108
109- (IBAction)hotKeySet:(NJRHotKeyField *)sender;
110{
111 [self writeToPrefs];
[129]112}
113
[133]114- (IBAction)showWindow:(id)sender;
115{
116 [self readFromPrefs];
117 [super showWindow: sender];
118}
119
[129]120@end
[130]121
122@implementation PSPreferencesController (NJRHotKeyFieldDelegate)
123
124- (BOOL)hotKeyField:(NJRHotKeyField *)hotKeyField shouldAcceptCharacter:(unichar)keyChar modifierFlags:(unsigned)modifierFlags rejectionMessage:(NSString **)message;
125{
126 *message = nil;
127
128 if (modifierFlags == 0 || modifierFlags == NSShiftKeyMask || modifierFlags == NSAlternateKeyMask || modifierFlags == (NSShiftKeyMask | NSAlternateKeyMask)) {
129 *message = modifierFlags == 0 ? @"key is reserved for typing text" :
130 @"key combination is reserved for typing text";
131 return ![textRejectSet characterIsMember: keyChar];
132 }
133 if (modifierFlags == NSCommandKeyMask) {
134 *message = @"key combination is reserved for application use";
135 return ![commandRejectSet characterIsMember: keyChar];
136 }
137 if (modifierFlags == (NSCommandKeyMask | NSShiftKeyMask)) {
138 *message = @"key combination is reserved for application use";
139 return ![commandShiftRejectSet characterIsMember: keyChar];
140 }
141 if (modifierFlags == (NSCommandKeyMask | NSAlternateKeyMask)) {
142 *message = @"key combination is reserved for Mac OS X use";
143 return ![commandOptionRejectSet characterIsMember: keyChar];
144 }
145 return YES;
146}
147
148@end
Note: See TracBrowser for help on using the repository browser.