Changeset 431 for trunk/ICeCoffEE


Ignore:
Timestamp:
03/03/08 08:21:22 (17 years ago)
Author:
Nicholas Riley
Message:

Handle NSUserKeyEquivalents; disable conflict resolution; fix keyEquivalents invalidation crasher

Location:
trunk/ICeCoffEE/ICeCoffEE
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEKeyEquivalents.m

    r319 r431  
    140140    return keyEquivalentAttributedString;
    141141}
     142
     143// converts NSUserKeyEquivalents prefixes into modifier flags
     144NSAttributedString *ICCF_KeyEquivalentAttributedString(NSString *self, unsigned count) {
     145    unsigned modifierFlags = 0;
     146    int i;
     147    for (i = 0 ; i < [self length] - 1; i++) {
     148        switch ([self characterAtIndex: i]) {
     149            case '@': modifierFlags |= NSCommandKeyMask; break;
     150            case '~': modifierFlags |= NSAlternateKeyMask; break;
     151            case '^': modifierFlags |= NSControlKeyMask; break;
     152            case '$': modifierFlags |= NSShiftKeyMask; break;
     153            default:
     154                return nil;
     155        }
     156    }
     157    return ICCF_KeyEquivalentAttributedStringWithModifierFlags([self substringFromIndex: i], modifierFlags, count);
     158}
     159
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEServicePrefController.m

    r428 r431  
    2929
    3030static NSMutableDictionary *keyEquivalents;
     31static NSDictionary *userKeyEquivalents;
    3132
    3233static void ICCF_RemoveSingleKeyEquivalents() {
     
    7576
    7677static inline void ICCF_UpdateKeyEquivalentForItem(NSMenuItem *item, int state) {
     78    return; // XXX disabled until we can affect menubar Services menu(s)
    7779    int oldState = ICCF_GetServiceState(item);
    7880    if ((oldState == ICCF_SERVICE_UNKNOWN || oldState == ICCF_SERVICE_SHOWN) && state == ICCF_SERVICE_HIDDEN)
     
    204206        } else {
    205207            NSString *keyEquivalent = (NSString *)[itemInfo objectForKey: (NSString *)kICServiceShortcut];
     208            if (keyEquivalent == nil) {
     209                keyEquivalent = [userKeyEquivalents objectForKey: [menuItem title]];
     210            } else if ([keyEquivalent length] != 1) {
     211                keyEquivalent = nil;
     212            } else {
     213                // XXX Inconsistency between Cocoa and Carbon: always command-shift in Carbon, not in Cocoa.  Since we only patch Cocoa for the moment, keep as is.
     214                unichar key = [keyEquivalent characterAtIndex: 0];
     215                if ([[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember: key])
     216                    keyEquivalent = [NSString stringWithFormat: @"$@%c", key];
     217                else
     218                    keyEquivalent = [NSString stringWithFormat: @"@%c", key];
     219            }
    206220            if (keyEquivalent != nil) {
    207221                [menuItem setToolTip: keyEquivalent];
     
    274288- (void)dealloc;
    275289{
    276     [keyEquivalents release];
    277     [servicesMenu release];
    278     [closedTriangle release];
    279     [selectedClosedTriangle release];
    280     [openTriangle release];
    281     [selectedOpenTriangle release];
     290    [keyEquivalents release]; keyEquivalents = nil;
     291    [userKeyEquivalents release]; userKeyEquivalents = nil;
     292    [servicesMenu release]; servicesMenu = nil;
     293    [closedTriangle release]; closedTriangle = nil;
     294    [selectedClosedTriangle release]; selectedClosedTriangle = nil;
     295    [openTriangle release]; openTriangle = nil;
     296    [selectedOpenTriangle release]; selectedOpenTriangle = nil;
    282297    [super dealloc];
    283298}
     
    336351    if (servicesMenu == nil) {
    337352        keyEquivalents = [[NSMutableDictionary alloc] init];
     353        userKeyEquivalents = [[[NSUserDefaults standardUserDefaults] dictionaryForKey: @"NSUserKeyEquivalents"] retain];
    338354        servicesMenu = [[NSMenu alloc] initWithTitle: @""];
    339355        ICCF_SetServicesMenu(servicesMenu);
     
    359375}
    360376
    361 NSAttributedString *ICCF_KeyEquivalentAttributedStringWithModifierFlags(NSString *self, unsigned int modifierFlags, unsigned count);
     377NSAttributedString *ICCF_KeyEquivalentAttributedString(NSString *self, unsigned count);
    362378
    363379- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
     
    380396    } else if ([[tableColumn identifier] isEqualToString: @"key"]) {
    381397        NSString *equivalent = [item toolTip];
    382         if (equivalent == nil || [equivalent length] != 1) return nil;
    383         // XXX Inconsistency between Cocoa and Carbon: always command-shift in Carbon, not in Cocoa.  Since we only patch Cocoa for the moment, keep as is.
    384         return ICCF_KeyEquivalentAttributedStringWithModifierFlags(equivalent, [item keyEquivalentModifierMask] | ([[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember: [equivalent characterAtIndex: 0]] ? NSShiftKeyMask : 0), ICCF_CountForKeyEquivalent(equivalent));
     398        if (equivalent == nil)
     399            return nil;
     400        return ICCF_KeyEquivalentAttributedString(equivalent, ICCF_CountForKeyEquivalent(equivalent));
    385401    }
    386402    return nil;
Note: See TracChangeset for help on using the changeset viewer.