26 Commits

Author SHA1 Message Date
Vadim Shpakovski 9266e38517 Polished Pod spec. 2014-09-22 13:59:45 +02:00
Vadim Shpakovski ddab66d2c0 Updated podspec. 2014-09-22 13:47:40 +02:00
Vadim Shpakovski 8e196a14a0 Merge pull request #45 from pfandrade/master
Implemented initWithCoder: to fix #44
2014-09-17 19:00:06 +03:00
Paulo F. Andrade e53eed24bc Implemented -initWithCoder: in MASShortcutView 2014-09-17 16:50:37 +01:00
Paulo F. Andrade 724376092d Updated MASShortcut 2014-09-17 16:47:37 +01:00
Paulo F. Andrade a5c2e15935 Added support for secure coding 2014-09-17 16:39:48 +01:00
Vadim Shpakovski 0633545a46 Ignoring disabled system shortcuts. 2014-09-02 09:43:53 +03:00
Vadim Shpakovski b30a0b02c4 Merge pull request #43 from darwin/master
allow [MODIFIER]+ESC shortcuts
2014-08-27 12:39:43 +03:00
Antonin Hildebrand 549b3ef29e allow [MODIFIER]+ESC shortcuts
only naked ESC without modifiers should cancel editing

http://discuss.binaryage.com/t/cant-change-activation-key-to-control-esc

tested in TotalTerminal codebase
2014-08-26 13:20:37 +02:00
Vadim Shpakovski f3a8a9a95a Merge pull request #40 from kainjow/master
Fixed compiling with projects that don't use a precompiled header.
2014-07-22 21:14:49 +03:00
Vadim Shpakovski 6e161f95fa Merge pull request #39 from xhacker/podspec
Create MASShortcut.podspec for CocoaPods
2014-07-22 21:12:37 +03:00
Kevin Wojniak 42dfc38ef6 Fixed compiling with projects that don't use a precompiled header. 2014-07-20 15:50:15 -07:00
LIU Dongyuan / 柳东原 dc088a3a77 Create MASShortcut.podspec 2014-07-18 22:45:18 -07:00
Vadim Shpakovski a21ac331ad Merge pull request #35 from ShadowLightz/master
Replace deprecated NSRunCriticalAlertPanel with NSAlert
2014-06-14 15:44:37 +03:00
ShadowLightz 7d3604820e Replace depr. NSRunCriticalAlertPanel with NSAlert
- Now using modern API
- The dialog is now shown as a modal sheet, which suits better
- The alert style is changed to NSWarningAlertStyle,
- NSCriticalAlertStyle was not required
2014-06-14 14:08:03 +02:00
Vadim Shpakovski ea5a30fe6d Merge pull request #32 from iluuu1994/master
Fixed string literal warning
2014-04-06 21:04:36 +03:00
Paulo F. Andrade da27736330 Replaced call to deprecated NSRunCriticalAlertPanel API 2014-04-03 11:25:28 +01:00
Ilija Tovilo 48a311eb90 Fixed string literal warning 2014-03-31 15:27:35 +02:00
Paulo F. Andrade 9c0b4a327c Added support for secure coding 2014-02-17 15:09:41 +00:00
Vadim Shpakovski 28c656d654 Merge pull request #29 from ShadowLightz/master
Silenced compiler warnings, updated README
2014-01-06 06:30:57 -08:00
Jonathan Rahn ce5760d61c update README 2014-01-06 14:08:32 +01:00
Jonathan Rahn f1228d6594 Silence compiler warning "No previous prototype for function..." and added an explicit typecast, update README with a hint to the view's height 2014-01-06 13:59:26 +01:00
Vadim Shpakovski 9edbf670f5 Adding new API for custom drawing. 2013-12-25 18:01:37 +02:00
Vadim Shpakovski b32a19ff7a Adding support for custom drawing. 2013-12-25 18:00:14 +02:00
Vadim Shpakovski fb4ac110a0 Fixing errors in MASShortcutDemo. 2013-07-31 14:26:49 +03:00
Vadim Shpakovski abda36331f Improving README. 2013-06-16 21:20:28 +03:00
9 changed files with 67 additions and 28 deletions
+3 -3
View File
@@ -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 -
-6
View File
@@ -54,12 +54,6 @@
NSString *_observableKeyPath;
}
@synthesize monitor = _monitor;
@synthesize handler = _handler;
@synthesize userDefaultsKey = _userDefaultsKey;
#pragma mark -
void *MASShortcutUserDefaultsContext = &MASShortcutUserDefaultsContext;
- (id)initWithUserDefaultsKey:(NSString *)userDefaultsKey handler:(void (^)())handler
+2 -1
View File
@@ -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
View File
@@ -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 "
+13
View File
@@ -0,0 +1,13 @@
Pod::Spec.new do |s|
s.platform = :osx
s.name = 'MASShortcut'
s.version = '1.3'
s.summary = 'Modern framework for managing global keyboard shortcuts compatible with Mac App Store'
s.homepage = 'https://github.com/shpakovski/MASShortcut'
s.authors = { 'Vadim Shpakovski' => 'vadim@shpakovski.com' }
s.license = 'BSD 2-clause'
s.source = { :git => 'https://github.com/shpakovski/MASShortcut.git', :tag => '1.3' }
s.source_files = '*.{h,m}'
s.osx.frameworks = 'Carbon', 'AppKit'
s.requires_arc = true
end
-5
View File
@@ -45,11 +45,6 @@ void *MASAssociatedDefaultsObserver = &MASAssociatedDefaultsObserver;
BOOL _internalShortcutChange;
}
@synthesize userDefaultsKey = _userDefaultsKey;
@synthesize shortcutView = _shortcutView;
#pragma mark -
- (id)initWithShortcutView:(MASShortcutView *)shortcutView userDefaultsKey:(NSString *)userDefaultsKey
{
self = [super init];
+5
View File
@@ -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
View File
@@ -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];
+2 -2
View File
@@ -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