Ignore:
Timestamp:
04/01/03 21:25:02 (21 years ago)
Author:
Nicholas Riley
Message:

PSPreferencesController.[hm]: Added support for registering hot keys;
not the most elegant thing in the world, but much better than it was
in the prototype. Triggered by +readPreferences.

NJRHotKeyField.[hm]: Replaced model components (wow, was that ever
dumb) by NJRHotKey reference, eliminating cumbersome archiving model.
Added accessors for hot key.

NJRHotKeyManager.[hm]: Ported Quentin Carnicelli's HotKeyCenter code
to use NJRHotKey, cleaned up, and removed reverse-engineered pre-10.2
support.

NJRHotKey.[hm]: New. Provides Cocoa-centric storage for
three-component hot keys, mapping from Cocoa to Carbon modifiers.

PSApplication.m: Reorganized. Added invocation of
+[PSPreferencesController readPreferences].

Fixes bug 29.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSPreferencesController.m

    r130 r131  
    88
    99#import "PSPreferencesController.h"
     10#import "PSApplication.h"
    1011#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";
    1120
    1221@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            NSRunAlertPanel(NSLocalizedString(@"Can't reserve alarm key equivalent", "Hot key set failure"),
     37                            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]);
     38            [defaults removeObjectForKey: PSSetAlarmHotKey];
     39            [(PSApplication *)NSApp performSelector: @selector(orderFrontPreferencesPanel:) withObject: self afterDelay: 0.1];
     40        }
     41    }
     42}
    1343
    1444#pragma mark interface updating
     
    2454{
    2555    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    26     [setAlarmHotKey setFromPropertyList: [defaults dictionaryForKey: @"Pester set alarm system-wide keyboard shortcut"]];
     56    NJRHotKey *hotKey = [[NJRHotKey alloc] initWithPropertyList: [defaults dictionaryForKey: PSSetAlarmHotKey]];
     57    [setAlarmHotKey setHotKey: hotKey];
     58    [hotKey release];
    2759}
    2860
     
    3062{
    3163    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    32     [defaults setObject: [setAlarmHotKey propertyListRepresentation] forKey: @"Pester set alarm system-wide keyboard shortcut"];
     64    [defaults setObject: [[setAlarmHotKey hotKey] propertyListRepresentation] forKey: @"Pester set alarm system-wide keyboard shortcut"];
    3365    [defaults synchronize];
     66    [[self class] readPreferences];
    3467}
    3568
     
    3871- (id)init {
    3972    if ( (self = [super initWithWindowNibName: @"Preferences"]) != nil) {
    40         [self window]; // connect outlets
     73        [[self window] center]; // connect outlets
    4174        [self readFromPrefs];
    4275        [self update];
Note: See TracChangeset for help on using the changeset viewer.