34 Commits

Author SHA1 Message Date
Vadim Shpakovski a3a459b4e4 Merge pull request #52 from starkos/flat-button-style
Flat button style
2014-11-24 17:33:12 +03:00
Jason Perkins 443e2db73d Fix indentation on previous commits: tabs to four spaces 2014-11-24 08:15:24 -05:00
Jason Perkins 5c7dd53380 Add new "flat" button style
Hides the button border and background; good for placing several shortcut buttons into a table view.
2014-11-24 08:07:41 -05:00
Vadim Shpakovski 72904d4dde Merge pull request #51 from starkos/userdefaults-semicolon-fix
Fix "Parse issue: Semicolon before method body is ignored"
2014-11-21 16:21:47 +03:00
Jason Perkins aa6c9fbab9 Fix "Parse issue: Semicolon before method body is ignored" 2014-11-21 07:54:39 -05:00
Vadim Shpakovski 7308a0927d Fixes possible memory leak. 2014-11-03 15:46:37 +03:00
Vadim Shpakovski d95c03289c Final touches to Podspec. 2014-09-22 14:06:03 +02:00
Vadim Shpakovski 14a9a4c4a6 Fixed Podspec. 2014-09-22 14:02:19 +02:00
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 86 additions and 32 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 -
+1 -7
View File
@@ -25,7 +25,7 @@
return shared;
}
+ (void)registerGlobalShortcutWithUserDefaultsKey:(NSString *)userDefaultsKey handler:(void (^)())handler;
+ (void)registerGlobalShortcutWithUserDefaultsKey:(NSString *)userDefaultsKey handler:(void (^)())handler
{
MASShortcutUserDefaultsHotKey *hotKey = [[MASShortcutUserDefaultsHotKey alloc] initWithUserDefaultsKey:userDefaultsKey handler:handler];
[[self registeredUserDefaultsHotKeys] setObject:hotKey forKey:userDefaultsKey];
@@ -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;
+13 -4
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] : @"");
@@ -315,6 +320,7 @@ BOOL MASShortcutAllowsAnyHotkeyWithOptionModifier = NO;
- (BOOL)isTakenError:(NSError **)outError
{
CFArrayRef globalHotKeys;
BOOL isTaken = NO;
if (CopySymbolicHotKeys(&globalHotKeys) == noErr) {
// Enumerate all global hotkeys and check if any of them matches current shortcut
@@ -322,9 +328,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 "
@@ -334,12 +342,13 @@ BOOL MASShortcutAllowsAnyHotkeyWithOptionModifier = NO;
NSDictionary *info = [NSDictionary dictionaryWithObject:description forKey:NSLocalizedDescriptionKey];
*outError = [NSError errorWithDomain:NSCocoaErrorDomain code:0 userInfo:info];
}
return YES;
isTaken = YES;
break;
}
}
CFRelease(globalHotKeys);
}
return [self isKeyEquivalent:self.keyCodeStringForKeyEquivalent flags:self.modifierFlags takenInMenu:[NSApp mainMenu] error:outError];
return (isTaken || [self isKeyEquivalent:self.keyCodeStringForKeyEquivalent flags:self.modifierFlags takenInMenu:[NSApp mainMenu] error:outError]);
}
@end
+14
View File
@@ -0,0 +1,14 @@
Pod::Spec.new do |s|
s.platform = :osx
s.osx.deployment_target = "10.7"
s.name = 'MASShortcut'
s.version = '1.3.1'
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.1' }
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];
+7 -1
View File
@@ -1,9 +1,12 @@
#import <AppKit/AppKit.h>
@class MASShortcut;
typedef enum {
MASShortcutViewAppearanceDefault = 0, // Height = 19 px
MASShortcutViewAppearanceTexturedRect, // Height = 25 px
MASShortcutViewAppearanceRounded // Height = 43 px
MASShortcutViewAppearanceRounded, // Height = 43 px
MASShortcutViewAppearanceFlat
} MASShortcutViewAppearance;
@interface MASShortcutView : NSView
@@ -14,4 +17,7 @@ typedef enum {
@property (nonatomic, copy) void (^shortcutValueChange)(MASShortcutView *sender);
@property (nonatomic) MASShortcutViewAppearance appearance;
/// Returns custom class for drawing control.
+ (Class)shortcutCellClass;
@end
+44 -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];
@@ -87,6 +107,12 @@
_shortcutCell.bezelStyle = NSRoundedBezelStyle;
break;
}
case MASShortcutViewAppearanceFlat: {
self.wantsLayer = YES;
_shortcutCell.backgroundColor = [NSColor clearColor];
_shortcutCell.bordered = NO;
break;
}
}
}
@@ -156,6 +182,10 @@
[_shortcutCell drawWithFrame:CGRectOffset(frame, 0.0, 1.0) inView:self];
break;
}
case MASShortcutViewAppearanceFlat: {
[_shortcutCell drawWithFrame:frame inView:self];
break;
}
}
}
@@ -207,6 +237,7 @@
switch (self.appearance) {
case MASShortcutViewAppearanceTexturedRect: hintButtonWidth += 2.0; break;
case MASShortcutViewAppearanceRounded: hintButtonWidth += 3.0; break;
case MASShortcutViewAppearanceFlat: hintButtonWidth -= 8.0 - (_shortcutCell.font.pointSize - BUTTON_FONT_SIZE); break;
default: break;
}
CGRectDivide(self.bounds, &hintRect, &shortcutRect, hintButtonWidth, CGRectMaxXEdge);
@@ -353,7 +384,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 +405,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