Changeset 131 for trunk/Cocoa/Pester/Source/NJRHotKeyField.m
- Timestamp:
- 04/01/03 21:25:02 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/NJRHotKeyField.m
r130 r131 9 9 #import "NJRHotKeyField.h" 10 10 #import "NJRHotKeyFieldCell.h" 11 #import "NJRHotKey.h" 11 12 #import "NSString-NJRExtensions.h" 12 13 // property list keys14 static NSString * const PLCharacters = @"characters"; // NSString15 static NSString * const PLModifierFlags = @"modifierFlags"; // NSNumber16 static NSString * const PLKeyCode = @"keyCode"; // NSNumber17 13 18 14 static const NSRange zeroRange = {0, 0}; … … 48 44 } 49 45 46 #pragma mark initialize-release 47 50 48 - (id)initWithCoder:(NSCoder *)coder; 51 49 { … … 63 61 return self; 64 62 } 63 64 - (void)dealloc; 65 { 66 [hotKey release]; 67 } 68 69 #pragma mark interface updating 65 70 66 71 // XXX still problems with command-A the first time … … 85 90 - (void)showKeyEquivalentAttributedStringFinalized:(BOOL)finalized; 86 91 { 87 if ( hotKeyCharacters== nil) {92 if ([hotKey characters] == nil) { 88 93 [self showStatus: @"none assigned"]; 89 94 return; 90 95 } 91 NSMutableAttributedString *equivString = [[ hotKeyCharacters keyEquivalentAttributedStringWithModifierFlags: hotKeyModifierFlags] mutableCopy];96 NSMutableAttributedString *equivString = [[[hotKey characters] keyEquivalentAttributedStringWithModifierFlags: [hotKey modifierFlags]] mutableCopy]; 92 97 [equivString addAttribute: NSParagraphStyleAttributeName 93 98 value: (finalized ? centerAlignStyle : leftAlignStyle) … … 98 103 } 99 104 100 - (void)clearHotKey; 101 { 102 [hotKeyCharacters release]; 103 hotKeyCharacters = nil; 104 hotKeyModifierFlags = 0; 105 hotKeyCode = 0; 106 [NSApp sendAction: [self action] to: [self target] from: self]; 107 } 105 #pragma mark event handling 108 106 109 107 - (void)keyUp:(NSEvent *)theEvent; … … 122 120 [self showStatus: message != nil ? message : @"key is unavailable for use"]; 123 121 } else { 124 [hotKeyCharacters release]; 125 hotKeyCharacters = [characters retain]; 126 hotKeyModifierFlags = modifierFlags; 127 hotKeyCode = [theEvent keyCode]; 122 [self setHotKey: [NJRHotKey hotKeyWithCharacters: characters modifierFlags: modifierFlags keyCode: [theEvent keyCode]]]; 128 123 [NSApp sendAction: [self action] to: [self target] from: self]; 129 124 [self showKeyEquivalentAttributedStringFinalized: ([theEvent modifierFlags] & capturedModifierMask) == 0]; … … 150 145 } 151 146 147 #pragma mark acccessing 148 149 - (NJRHotKey *)hotKey; 150 { 151 return hotKey; 152 } 153 154 - (void)setHotKey:(NJRHotKey *)aKey; 155 { 156 if (aKey != hotKey) { 157 [hotKey release]; 158 hotKey = [aKey retain]; 159 [self showKeyEquivalentAttributedStringFinalized: ([[NSApp currentEvent] modifierFlags] & capturedModifierMask) == 0]; 160 } 161 } 162 163 #pragma mark actions 164 152 165 - (IBAction)clear:(id)sender; 153 166 { 154 [self clearHotKey]; 167 [self setHotKey: nil]; 168 [NSApp sendAction: [self action] to: [self target] from: self]; 155 169 [self showKeyEquivalentAttributedStringFinalized: YES]; 156 170 } 157 171 158 #pragma mark property list serialization (Pester 1.1)159 160 - (NSDictionary *)propertyListRepresentation;161 {162 return [NSDictionary dictionaryWithObjectsAndKeys:163 hotKeyCharacters, PLCharacters,164 [NSNumber numberWithUnsignedInt: hotKeyModifierFlags], PLModifierFlags,165 [NSNumber numberWithUnsignedShort: hotKeyCode], PLKeyCode,166 nil];167 }168 169 - (void)setFromPropertyList:(NSDictionary *)dict;170 {171 NS_DURING172 hotKeyCharacters = [[dict objectForKey: PLCharacters] retain];173 hotKeyModifierFlags = [[dict objectForKey: PLModifierFlags] unsignedIntValue];174 hotKeyCode = [[dict objectForKey: PLKeyCode] unsignedShortValue];175 [self showKeyEquivalentAttributedStringFinalized: ([[NSApp currentEvent] modifierFlags] & capturedModifierMask) == 0];176 NS_HANDLER177 [self clear: nil];178 NS_ENDHANDLER179 }180 181 172 @end
Note:
See TracChangeset
for help on using the changeset viewer.