diff options
| author | Jason Perkins | 2015-01-14 12:23:22 -0500 | 
|---|---|---|
| committer | Jason Perkins | 2015-01-14 12:23:22 -0500 | 
| commit | eda4bdb9c9c9837dceedee792eb8f48d7b365193 (patch) | |
| tree | a2e98fbab8ce04fb960984569630aa19f4a25c22 | |
| parent | 62c142a7f5718fa1c7523d1bd6f6f22430c0329b (diff) | |
| download | MASShortcut-eda4bdb9c9c9837dceedee792eb8f48d7b365193.tar.bz2 | |
Add initial accessibility using 10.10 APIs
| -rw-r--r-- | Framework/MASShortcutView.m | 63 | 
1 files changed, 55 insertions, 8 deletions
| diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m index aace67e..8d2002e 100644 --- a/Framework/MASShortcutView.m +++ b/Framework/MASShortcutView.m @@ -122,14 +122,24 @@ NSString *const MASShortcutBinding = @"shortcutValue";      // Only enabled view supports recording      if (flag && !self.enabled) return; -     -    if (_recording != flag) { -        _recording = flag; -        self.shortcutPlaceholder = nil; -        [self resetToolTips]; -        [self activateEventMonitoring:_recording]; -        [self activateResignObserver:_recording]; -        [self setNeedsDisplay:YES]; + +    // Only care about changes in state +    if (flag == _recording) return; + +    _recording = flag; +    self.shortcutPlaceholder = nil; +    [self resetToolTips]; +    [self activateEventMonitoring:_recording]; +    [self activateResignObserver:_recording]; +    [self setNeedsDisplay:YES]; + +    // Give VO users feedback on the result +    if (_recording == NO) { +        NSString* msg = (_shortcutValue.description) ? +                         NSLocalizedString(@"Shortcut set", @"VoiceOver shortcut recording feedback") : +                         NSLocalizedString(@"Shortcut cleared", @"VoiceOver shortcut recording feedback"); +        NSDictionary *announcementInfo = [[NSDictionary alloc] initWithObjectsAndKeys:msg, NSAccessibilityAnnouncementKey, @"High", NSAccessibilityPriorityKey, nil]; +        NSAccessibilityPostNotificationWithUserInfo(self, NSAccessibilityAnnouncementRequestedNotification, announcementInfo);      }  } @@ -508,4 +518,41 @@ void *kUserDataHint = &kUserDataHint;      [boundObject setValue:value forKeyPath:boundKeyPath];  } +#pragma mark - Accessibility + +- (BOOL)accessibilityIsIgnored +{ +    return NO; +} + +- (NSString *)accessibilityHelp +{ +    return NSLocalizedString(@"To record a new shortcut, click this button, and then type the" +                             @" new shortcut, or press delete to clear an existing shortcut.", +                             @"VoiceOver shortcut help"); +} + +- (NSString *)accessibilityLabel +{ +    NSString* title = _shortcutValue.description ? _shortcutValue.description : @"Empty"; +    title = [title stringByAppendingFormat:@" %@", NSLocalizedString(@"keyboard shortcut", @"VoiceOver title")]; +    return title; +} + +- (BOOL)accessibilityPerformPress +{ +    if (self.isRecording == NO) { +        self.recording = YES; +        return YES; +    } +    else { +        return NO; +    } +} + +- (NSString *)accessibilityRole +{ +    return NSAccessibilityButtonRole; +} +  @end | 
