cocoabits / MASShortcut

Modern framework for managing global keyboard shortcuts compatible with Mac App Store. More details:
http://blog.shpakovski.com/2012/07/global-keyboard-shortcuts-in-cocoa.html
BSD 2-Clause "Simplified" License
1.52k stars 220 forks source link

Introduce an option to hide the delete hint button #101

Open jordikroon opened 7 years ago

jordikroon commented 7 years ago

I've just spend an hour trying to hide the delete hint button because I don't want users to leave a hotkey empty. They're pre-filled and users have the option to override them.

I managed to delete the button by overriding the getShortcutRect method and setting showsDeleteButton to No like below, but it would be nice to have an option to hide this without overriding the code.

#import "DropShortcutView.h"

static const CGFloat MASHintButtonWidth = 23;

@interface DropShortcutView()
    @property (nonatomic, assign) BOOL showsDeleteButton;
@end

@implementation DropShortcutView

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        self.showsDeleteButton = NO;
    }
    return self;
}

- (void)getShortcutRect:(CGRect *)shortcutRectRef hintRect:(CGRect *)hintRectRef
{
    CGFloat hintButtonWidth = self.shortcutValue == nil || self.recording ? MASHintButtonWidth : 0;

    CGRect shortcutRect, hintRect;
    CGRectDivide(self.bounds, &hintRect, &shortcutRect, hintButtonWidth, CGRectMaxXEdge);
    if (shortcutRectRef) {
        *shortcutRectRef = shortcutRect;
    }

    if (hintRectRef) {
        *hintRectRef = hintRect;
    }
}
@end
shpakovski commented 7 years ago

Thank you for the request, I will consider this feature!