diff options
| author | Vadim Shpakovski | 2014-09-17 19:00:06 +0300 | 
|---|---|---|
| committer | Vadim Shpakovski | 2014-09-17 19:00:06 +0300 | 
| commit | 8e196a14a09a7a16d19c6cf9c3985eea7f7b7554 (patch) | |
| tree | a284a46c044c63864597f0f4f1db89a57da6eba0 | |
| parent | 0633545a4666d969dfbb860e540eb3b008893651 (diff) | |
| parent | e53eed24bc6cc2856e732b16832730f6c2aa2827 (diff) | |
| download | MASShortcut-1.3.tar.bz2 | |
Merge pull request #45 from pfandrade/master1.3
Implemented initWithCoder: to fix #44
| -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; | 
