diff options
| -rw-r--r-- | MASShortcut.h | 2 | ||||
| -rw-r--r-- | MASShortcut.m | 5 | ||||
| -rw-r--r-- | MASShortcutView.m | 45 |
3 files changed, 35 insertions, 17 deletions
diff --git a/MASShortcut.h b/MASShortcut.h index 905ddaf..c9081a2 100644 --- a/MASShortcut.h +++ b/MASShortcut.h @@ -31,7 +31,7 @@ enum { kMASShortcutGlyphSoutheastArrow = 0x2198, } MASShortcutGlyph; -@interface MASShortcut : NSObject <NSCoding> +@interface MASShortcut : NSObject <NSSecureCoding> @property (nonatomic) NSUInteger keyCode; @property (nonatomic) NSUInteger modifierFlags; diff --git a/MASShortcut.m b/MASShortcut.m index 5b94310..b217a98 100644 --- a/MASShortcut.m +++ b/MASShortcut.m @@ -13,6 +13,11 @@ NSString *const MASShortcutModifierFlags = @"ModifierFlags"; #pragma mark - ++ (BOOL)supportsSecureCoding +{ + return YES; +} + - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeInteger:(self.keyCode != NSNotFound ? (NSInteger)self.keyCode : - 1) forKey:MASShortcutKeyCode]; diff --git a/MASShortcutView.m b/MASShortcutView.m index 96dcc86..b2d2531 100644 --- a/MASShortcutView.m +++ b/MASShortcutView.m @@ -42,15 +42,29 @@ { self = [super initWithFrame:frameRect]; if (self) { - _shortcutCell = [[[self.class shortcutCellClass] alloc] init]; - _shortcutCell.buttonType = NSPushOnPushOffButton; - _shortcutCell.font = [[NSFontManager sharedFontManager] convertFont:_shortcutCell.font toSize:BUTTON_FONT_SIZE]; - _enabled = YES; - [self resetShortcutCellStyle]; + [self commonInit]; } return self; } +- (id)initWithCoder:(NSCoder *)coder +{ + self = [super initWithCoder:coder]; + if (self) { + [self commonInit]; + } + return self; +} + +- (void)commonInit +{ + _shortcutCell = [[[self.class shortcutCellClass] alloc] init]; + _shortcutCell.buttonType = NSPushOnPushOffButton; + _shortcutCell.font = [[NSFontManager sharedFontManager] convertFont:_shortcutCell.font toSize:BUTTON_FONT_SIZE]; + _enabled = YES; + [self resetShortcutCellStyle]; +} + - (void)dealloc { [self activateEventMonitoring:NO]; @@ -380,17 +394,16 @@ void *kUserDataHint = &kUserDataHint; [weakSelf activateEventMonitoring:NO]; NSString *format = NSLocalizedString(@"The key combination %@ cannot be used", @"Title for alert when shortcut is already used"); - NSAlert* alert = [[NSAlert alloc]init]; - alert.messageText = [NSString stringWithFormat:format, shortcut]; - alert.informativeText = error.localizedDescription; - alert.alertStyle = NSWarningAlertStyle; - weakSelf.recording = NO; - [alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse returnCode) { - weakSelf.shortcutPlaceholder = nil; - [weakSelf activateResignObserver:YES]; - [weakSelf activateEventMonitoring:YES]; - weakSelf.recording = YES; - }]; + NSAlert *alert = [[NSAlert alloc] init]; + alert.alertStyle = NSCriticalAlertStyle; + alert.informativeText = [NSString stringWithFormat:format, shortcut]; + alert.messageText = error.localizedDescription; + [alert addButtonWithTitle:NSLocalizedString(@"OK", @"Alert button when shortcut is already used")]; + + [alert runModal]; + weakSelf.shortcutPlaceholder = nil; + [weakSelf activateResignObserver:YES]; + [weakSelf activateEventMonitoring:YES]; } else { weakSelf.shortcutValue = shortcut; |
