Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e196a14a0 | |||
| e53eed24bc | |||
| 724376092d | |||
| a5c2e15935 | |||
| 0633545a46 | |||
| b30a0b02c4 | |||
| 549b3ef29e | |||
| f3a8a9a95a | |||
| 6e161f95fa | |||
| 42dfc38ef6 | |||
| dc088a3a77 | |||
| a21ac331ad | |||
| 7d3604820e | |||
| ea5a30fe6d | |||
| da27736330 | |||
| 48a311eb90 | |||
| 9c0b4a327c | |||
| 28c656d654 | |||
| ce5760d61c | |||
| f1228d6594 | |||
| 9edbf670f5 | |||
| b32a19ff7a | |||
| fb4ac110a0 | |||
| abda36331f |
@@ -1,9 +1,9 @@
|
||||
#import "MASShortcut+Monitoring.h"
|
||||
|
||||
NSMutableDictionary *MASRegisteredHotKeys();
|
||||
BOOL InstallCommonEventHandler();
|
||||
NSMutableDictionary *MASRegisteredHotKeys(void);
|
||||
BOOL InstallCommonEventHandler(void);
|
||||
BOOL InstallHotkeyWithShortcut(MASShortcut *shortcut, UInt32 *outCarbonHotKeyID, EventHotKeyRef *outCarbonHotKey);
|
||||
void UninstallEventHandler();
|
||||
void UninstallEventHandler(void);
|
||||
|
||||
#pragma mark -
|
||||
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
#import <Carbon/Carbon.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#define MASShortcutChar(char) [NSString stringWithFormat:@"%C", (unsigned short)(char)]
|
||||
#define MASShortcutClear(flags) (flags & (NSControlKeyMask | NSShiftKeyMask | NSAlternateKeyMask | NSCommandKeyMask))
|
||||
@@ -30,7 +31,7 @@ enum {
|
||||
kMASShortcutGlyphSoutheastArrow = 0x2198,
|
||||
} MASShortcutGlyph;
|
||||
|
||||
@interface MASShortcut : NSObject <NSCoding>
|
||||
@interface MASShortcut : NSObject <NSSecureCoding>
|
||||
|
||||
@property (nonatomic) NSUInteger keyCode;
|
||||
@property (nonatomic) NSUInteger modifierFlags;
|
||||
|
||||
+9
-2
@@ -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];
|
||||
@@ -189,7 +194,7 @@ NSString *const MASShortcutModifierFlags = @"ModifierFlags";
|
||||
UniCharCount length = 0;
|
||||
UniChar chars[256] = { 0 };
|
||||
UInt32 deadKeyState = 0;
|
||||
error = UCKeyTranslate(layoutData, self.keyCode, kUCKeyActionDisplay, 0, // No modifiers
|
||||
error = UCKeyTranslate(layoutData, (UInt16)self.keyCode, kUCKeyActionDisplay, 0, // No modifiers
|
||||
LMGetKbdType(), kUCKeyTranslateNoDeadKeysMask, &deadKeyState,
|
||||
sizeof(chars) / sizeof(UniChar), &length, chars);
|
||||
keystroke = ((error == noErr) && length ? [NSString stringWithCharacters:chars length:length] : @"");
|
||||
@@ -322,9 +327,11 @@ BOOL MASShortcutAllowsAnyHotkeyWithOptionModifier = NO;
|
||||
CFDictionaryRef hotKeyInfo = CFArrayGetValueAtIndex(globalHotKeys, i);
|
||||
CFNumberRef code = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyCode);
|
||||
CFNumberRef flags = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyModifiers);
|
||||
CFNumberRef enabled = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyEnabled);
|
||||
|
||||
if (([(__bridge NSNumber *)code unsignedIntegerValue] == self.keyCode) &&
|
||||
([(__bridge NSNumber *)flags unsignedIntegerValue] == self.carbonFlags)) {
|
||||
([(__bridge NSNumber *)flags unsignedIntegerValue] == self.carbonFlags) &&
|
||||
([(__bridge NSNumber *)enabled boolValue])) {
|
||||
|
||||
if (outError) {
|
||||
NSString *description = NSLocalizedString(@"This combination cannot be used because it is already used by a system-wide "
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'MASShortcut'
|
||||
s.version = '1.2.3'
|
||||
s.summary = 'Modern framework for managing global keyboard shortcuts compatible with Mac App Store'
|
||||
s.homepage = 'https://github.com/sonoramac/MASShortcut'
|
||||
s.authors = { 'Vadim Shpakovski' => 'vadim@shpakovski.com' }
|
||||
s.license = 'BSD 2-clause'
|
||||
|
||||
s.source = { :git => 'git@github.com:shpakovski/MASShortcut.git', :tag => '1.2.3' }
|
||||
s.source_files = '*.{h,m}'
|
||||
s.framework = 'Carbon'
|
||||
s.requires_arc = true
|
||||
end
|
||||
@@ -1,3 +1,5 @@
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
@class MASShortcut;
|
||||
|
||||
typedef enum {
|
||||
@@ -14,4 +16,7 @@ typedef enum {
|
||||
@property (nonatomic, copy) void (^shortcutValueChange)(MASShortcutView *sender);
|
||||
@property (nonatomic) MASShortcutViewAppearance appearance;
|
||||
|
||||
/// Returns custom class for drawing control.
|
||||
+ (Class)shortcutCellClass;
|
||||
|
||||
@end
|
||||
|
||||
+33
-9
@@ -29,22 +29,42 @@
|
||||
@synthesize shortcutPlaceholder = _shortcutPlaceholder;
|
||||
@synthesize shortcutValueChange = _shortcutValueChange;
|
||||
@synthesize recording = _recording;
|
||||
@synthesize appearance = _appearance;
|
||||
|
||||
#pragma mark -
|
||||
|
||||
+ (Class)shortcutCellClass
|
||||
{
|
||||
return [NSButtonCell class];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(CGRect)frameRect
|
||||
{
|
||||
self = [super initWithFrame:frameRect];
|
||||
if (self) {
|
||||
_shortcutCell = [[NSButtonCell 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];
|
||||
@@ -353,7 +373,7 @@ void *kUserDataHint = &kUserDataHint;
|
||||
weakSelf.recording = NO;
|
||||
event = nil;
|
||||
}
|
||||
else if (shortcut.keyCode == kVK_Escape) {
|
||||
else if (shortcut.keyCode == kVK_Escape && !shortcut.modifierFlags) {
|
||||
// Cancel recording
|
||||
weakSelf.recording = NO;
|
||||
event = nil;
|
||||
@@ -374,9 +394,13 @@ void *kUserDataHint = &kUserDataHint;
|
||||
[weakSelf activateEventMonitoring:NO];
|
||||
NSString *format = NSLocalizedString(@"The key combination %@ cannot be used",
|
||||
@"Title for alert when shortcut is already used");
|
||||
NSRunCriticalAlertPanel([NSString stringWithFormat:format, shortcut], error.localizedDescription,
|
||||
NSLocalizedString(@"OK", @"Alert button when shortcut is already used"),
|
||||
nil, nil);
|
||||
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];
|
||||
|
||||
@@ -9,7 +9,7 @@ The project MASShortcut introduces modern API and user interface for recording,
|
||||
I hope, it is really easy:
|
||||
|
||||
```objective-c
|
||||
// Drop a custom view into XIB and set its class to MASShortcutView
|
||||
// Drop a custom view into XIB, set its class to MASShortcutView and its height to 19. If you select another appearance style look up the correct values in MASShortcutView.h
|
||||
@property (nonatomic, weak) IBOutlet MASShortcutView *shortcutView;
|
||||
|
||||
// Think up a preference key to store a global shortcut between launches
|
||||
@@ -64,7 +64,7 @@ _observableKeyPath = [@"values." stringByAppendingString:kPreferenceGlobalShortc
|
||||
|
||||
# Non-ARC Version
|
||||
|
||||
If you like retain/release, please check out these forks: [heardrwt/MASShortcut](https://github.com/heardrwt/MASShortcut) and [chendo/MASShortcut](https://github.com/chendo/MASShortcut).
|
||||
If you like retain/release, please check out these forks: [heardrwt/MASShortcut](https://github.com/heardrwt/MASShortcut) and [chendo/MASShortcut](https://github.com/chendo/MASShortcut). However, the preferred way is to enable the `-fobjc-arc` in Xcode source options.
|
||||
|
||||
# Copyright
|
||||
|
||||
|
||||
Reference in New Issue
Block a user