aboutsummaryrefslogtreecommitdiffstats
path: root/Framework/MASShortcutView.m
diff options
context:
space:
mode:
authorJason Perkins2015-02-16 10:09:48 -0500
committerJason Perkins2015-02-16 10:09:48 -0500
commit86d5b1ae49105c1b0a789cbdac17dd7ce0da0479 (patch)
tree58f9e363bd64e9a667e35b990655093481bbf64e /Framework/MASShortcutView.m
parentb564f5296a489d83d0007b8b21185c5b3326dbc8 (diff)
parent3ea350cec127d7118ef64f0e84a9ad84fa249a11 (diff)
downloadMASShortcut-86d5b1ae49105c1b0a789cbdac17dd7ce0da0479.tar.bz2
Merge branch 'master' into issue-47-accessibility
Diffstat (limited to 'Framework/MASShortcutView.m')
-rw-r--r--Framework/MASShortcutView.m18
1 files changed, 13 insertions, 5 deletions
diff --git a/Framework/MASShortcutView.m b/Framework/MASShortcutView.m
index dfeeac6..4132ce2 100644
--- a/Framework/MASShortcutView.m
+++ b/Framework/MASShortcutView.m
@@ -13,6 +13,7 @@ NSString *const MASShortcutBinding = @"shortcutValue";
@property (nonatomic, getter = isHinting) BOOL hinting;
@property (nonatomic, copy) NSString *shortcutPlaceholder;
+@property (nonatomic, assign) BOOL showsDeleteButton;
@end
@@ -57,6 +58,7 @@ NSString *const MASShortcutBinding = @"shortcutValue";
_shortcutCell.font = [[NSFontManager sharedFontManager] convertFont:_shortcutCell.font toSize:BUTTON_FONT_SIZE];
_shortcutValidator = [MASShortcutValidator sharedValidator];
_enabled = YES;
+ _showsDeleteButton = YES;
[self resetShortcutCellStyle];
}
@@ -198,9 +200,15 @@ NSString *const MASShortcutBinding = @"shortcutValue";
- (void)drawRect:(CGRect)dirtyRect
{
if (self.shortcutValue) {
- [self drawInRect:self.bounds withTitle:NSStringFromMASKeyCode(self.recording ? kMASShortcutGlyphEscape : kMASShortcutGlyphDeleteLeft)
- alignment:NSRightTextAlignment state:NSOffState];
-
+ NSString *buttonTitle;
+ if (self.recording) {
+ buttonTitle = NSStringFromMASKeyCode(kMASShortcutGlyphEscape);
+ } else if (self.showsDeleteButton) {
+ buttonTitle = NSStringFromMASKeyCode(kMASShortcutGlyphClear);
+ }
+ if (buttonTitle != nil) {
+ [self drawInRect:self.bounds withTitle:buttonTitle alignment:NSRightTextAlignment state:NSOffState];
+ }
CGRect shortcutRect;
[self getShortcutRect:&shortcutRect hintRect:NULL];
NSString *title = (self.recording
@@ -379,7 +387,7 @@ void *kUserDataHint = &kUserDataHint;
static id eventMonitor = nil;
if (shouldActivate) {
- __weak MASShortcutView *weakSelf = self;
+ __unsafe_unretained MASShortcutView *weakSelf = self;
NSEventMask eventMask = (NSKeyDownMask | NSFlagsChangedMask);
eventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^(NSEvent *event) {
@@ -460,7 +468,7 @@ void *kUserDataHint = &kUserDataHint;
static id observer = nil;
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
if (shouldActivate) {
- __weak MASShortcutView *weakSelf = self;
+ __unsafe_unretained MASShortcutView *weakSelf = self;
observer = [notificationCenter addObserverForName:NSWindowDidResignKeyNotification object:self.window
queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
weakSelf.recording = NO;