Upgrade pods: Alamofire GCDWebServer MASShortcut

This commit is contained in:
Qiu Yuzhou
2019-09-10 14:23:26 +08:00
parent c593564059
commit 075949cdcb
97 changed files with 3392 additions and 2975 deletions

View File

@ -1,6 +0,0 @@
framework module MASShortcut {
umbrella header "Shortcut.h"
export *
module * { export * }
}

View File

@ -3,7 +3,7 @@
#import "MASKeyMasks.h"
// These glyphs are missed in Carbon.h
enum {
typedef NS_ENUM(unsigned short, kMASShortcutGlyph) {
kMASShortcutGlyphEject = 0x23CF,
kMASShortcutGlyphClear = 0x2715,
kMASShortcutGlyphDeleteLeft = 0x232B,

View File

@ -16,14 +16,14 @@
Hardware independent, same as in `NSEvent`. See `Events.h` in the HIToolbox
framework for a complete list, or Command-click this symbol: `kVK_ANSI_A`.
*/
@property (nonatomic, readonly) NSUInteger keyCode;
@property (nonatomic, readonly) NSInteger keyCode;
/**
Cocoa keyboard modifier flags.
Same as in `NSEvent`: `NSCommandKeyMask`, `NSAlternateKeyMask`, etc.
*/
@property (nonatomic, readonly) NSUInteger modifierFlags;
@property (nonatomic, readonly) NSEventModifierFlags modifierFlags;
/**
Same as `keyCode`, just a different type.
@ -68,8 +68,8 @@
*/
@property (nonatomic, readonly) NSString *modifierFlagsString;
- (instancetype)initWithKeyCode:(NSUInteger)code modifierFlags:(NSUInteger)flags;
+ (instancetype)shortcutWithKeyCode:(NSUInteger)code modifierFlags:(NSUInteger)flags;
- (instancetype)initWithKeyCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags;
+ (instancetype)shortcutWithKeyCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags;
/**
Creates a new shortcut from an `NSEvent` object.

View File

@ -8,7 +8,7 @@ static NSString *const MASShortcutModifierFlags = @"ModifierFlags";
#pragma mark Initialization
- (instancetype)initWithKeyCode:(NSUInteger)code modifierFlags:(NSUInteger)flags
- (instancetype)initWithKeyCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags
{
self = [super init];
if (self) {
@ -18,7 +18,7 @@ static NSString *const MASShortcutModifierFlags = @"ModifierFlags";
return self;
}
+ (instancetype)shortcutWithKeyCode:(NSUInteger)code modifierFlags:(NSUInteger)flags
+ (instancetype)shortcutWithKeyCode:(NSInteger)code modifierFlags:(NSEventModifierFlags)flags
{
return [[self alloc] initWithKeyCode:code modifierFlags:flags];
}
@ -48,33 +48,34 @@ static NSString *const MASShortcutModifierFlags = @"ModifierFlags";
- (NSString *)keyCodeStringForKeyEquivalent
{
NSString *keyCodeString = self.keyCodeString;
if (keyCodeString.length > 1) {
switch (self.keyCode) {
case kVK_F1: return NSStringFromMASKeyCode(0xF704);
case kVK_F2: return NSStringFromMASKeyCode(0xF705);
case kVK_F3: return NSStringFromMASKeyCode(0xF706);
case kVK_F4: return NSStringFromMASKeyCode(0xF707);
case kVK_F5: return NSStringFromMASKeyCode(0xF708);
case kVK_F6: return NSStringFromMASKeyCode(0xF709);
case kVK_F7: return NSStringFromMASKeyCode(0xF70a);
case kVK_F8: return NSStringFromMASKeyCode(0xF70b);
case kVK_F9: return NSStringFromMASKeyCode(0xF70c);
case kVK_F10: return NSStringFromMASKeyCode(0xF70d);
case kVK_F11: return NSStringFromMASKeyCode(0xF70e);
case kVK_F12: return NSStringFromMASKeyCode(0xF70f);
// From this point down I am guessing F13 etc come sequentially, I don't have a keyboard to test.
case kVK_F13: return NSStringFromMASKeyCode(0xF710);
case kVK_F14: return NSStringFromMASKeyCode(0xF711);
case kVK_F15: return NSStringFromMASKeyCode(0xF712);
case kVK_F16: return NSStringFromMASKeyCode(0xF713);
case kVK_F17: return NSStringFromMASKeyCode(0xF714);
case kVK_F18: return NSStringFromMASKeyCode(0xF715);
case kVK_F19: return NSStringFromMASKeyCode(0xF716);
case kVK_Space: return NSStringFromMASKeyCode(0x20);
default: return @"";
}
if (keyCodeString.length <= 1) {
return keyCodeString.lowercaseString;
}
switch (self.keyCode) {
case kVK_F1: return NSStringFromMASKeyCode(NSF1FunctionKey);
case kVK_F2: return NSStringFromMASKeyCode(NSF2FunctionKey);
case kVK_F3: return NSStringFromMASKeyCode(NSF3FunctionKey);
case kVK_F4: return NSStringFromMASKeyCode(NSF4FunctionKey);
case kVK_F5: return NSStringFromMASKeyCode(NSF5FunctionKey);
case kVK_F6: return NSStringFromMASKeyCode(NSF6FunctionKey);
case kVK_F7: return NSStringFromMASKeyCode(NSF7FunctionKey);
case kVK_F8: return NSStringFromMASKeyCode(NSF8FunctionKey);
case kVK_F9: return NSStringFromMASKeyCode(NSF9FunctionKey);
case kVK_F10: return NSStringFromMASKeyCode(NSF10FunctionKey);
case kVK_F11: return NSStringFromMASKeyCode(NSF11FunctionKey);
case kVK_F12: return NSStringFromMASKeyCode(NSF12FunctionKey);
case kVK_F13: return NSStringFromMASKeyCode(NSF13FunctionKey);
case kVK_F14: return NSStringFromMASKeyCode(NSF14FunctionKey);
case kVK_F15: return NSStringFromMASKeyCode(NSF15FunctionKey);
case kVK_F16: return NSStringFromMASKeyCode(NSF16FunctionKey);
case kVK_F17: return NSStringFromMASKeyCode(NSF17FunctionKey);
case kVK_F18: return NSStringFromMASKeyCode(NSF18FunctionKey);
case kVK_F19: return NSStringFromMASKeyCode(NSF19FunctionKey);
case kVK_Space: return NSStringFromMASKeyCode(0x20);
default: return @"";
}
return keyCodeString.lowercaseString;
}
- (NSString *)keyCodeString
@ -132,7 +133,7 @@ static NSString *const MASShortcutModifierFlags = @"ModifierFlags";
case kVK_ANSI_KeypadClear: return NSStringFromMASKeyCode(kMASShortcutGlyphPadClear);
case kVK_ANSI_KeypadDivide: return @"/";
case kVK_ANSI_KeypadEnter: return NSStringFromMASKeyCode(kMASShortcutGlyphReturn);
case kVK_ANSI_KeypadMinus: return @"";
case kVK_ANSI_KeypadMinus: return @"-";
case kVK_ANSI_KeypadEquals: return @"=";
// Hardcode
@ -210,7 +211,7 @@ static NSString *const MASShortcutModifierFlags = @"ModifierFlags";
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeInteger:(self.keyCode != NSNotFound ? (NSInteger)self.keyCode : - 1) forKey:MASShortcutKeyCode];
[coder encodeInteger:(self.keyCode != NSNotFound ? self.keyCode : - 1) forKey:MASShortcutKeyCode];
[coder encodeInteger:(NSInteger)self.modifierFlags forKey:MASShortcutModifierFlags];
}
@ -219,7 +220,7 @@ static NSString *const MASShortcutModifierFlags = @"ModifierFlags";
self = [super init];
if (self) {
NSInteger code = [decoder decodeIntegerForKey:MASShortcutKeyCode];
_keyCode = (code < 0 ? NSNotFound : (NSUInteger)code);
_keyCode = (code < 0) ? NSNotFound : code;
_modifierFlags = [decoder decodeIntegerForKey:MASShortcutModifierFlags];
}
return self;

View File

@ -15,8 +15,8 @@
- (BOOL) isShortcutValid: (MASShortcut*) shortcut
{
NSUInteger keyCode = [shortcut keyCode];
NSUInteger modifiers = [shortcut modifierFlags];
NSInteger keyCode = [shortcut keyCode];
NSEventModifierFlags modifiers = [shortcut modifierFlags];
// Allow any function key with any combination of modifiers
BOOL includesFunctionKey = ((keyCode == kVK_F1) || (keyCode == kVK_F2) || (keyCode == kVK_F3) || (keyCode == kVK_F4) ||
@ -53,7 +53,7 @@
- (BOOL) isShortcut: (MASShortcut*) shortcut alreadyTakenInMenu: (NSMenu*) menu explanation: (NSString**) explanation
{
NSString *keyEquivalent = [shortcut keyCodeStringForKeyEquivalent];
NSUInteger flags = [shortcut modifierFlags];
NSEventModifierFlags flags = [shortcut modifierFlags];
for (NSMenuItem *menuItem in menu.itemArray) {
if (menuItem.hasSubmenu && [self isShortcut:shortcut alreadyTakenInMenu:[menuItem submenu] explanation:explanation]) return YES;
@ -91,7 +91,7 @@
CFNumberRef flags = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyModifiers);
CFNumberRef enabled = CFDictionaryGetValue(hotKeyInfo, kHISymbolicHotKeyEnabled);
if (([(__bridge NSNumber *)code unsignedIntegerValue] == [shortcut keyCode]) &&
if (([(__bridge NSNumber *)code integerValue] == [shortcut keyCode]) &&
([(__bridge NSNumber *)flags unsignedIntegerValue] == [shortcut carbonFlags]) &&
([(__bridge NSNumber *)enabled boolValue])) {

View File

@ -2,12 +2,12 @@
extern NSString *const MASShortcutBinding;
typedef enum {
typedef NS_ENUM(NSInteger, MASShortcutViewStyle) {
MASShortcutViewStyleDefault = 0, // Height = 19 px
MASShortcutViewStyleTexturedRect, // Height = 25 px
MASShortcutViewStyleRounded, // Height = 43 px
MASShortcutViewStyleFlat
} MASShortcutViewStyle;
};
@interface MASShortcutView : NSView

View File

@ -24,7 +24,7 @@ static const CGFloat MASButtonFontSize = 11;
NSInteger _shortcutToolTipTag;
NSInteger _hintToolTipTag;
NSTrackingArea *_hintArea;
BOOL _acceptsFirstResponder;
BOOL _acceptsFirstResponder;
}
#pragma mark -
@ -60,7 +60,7 @@ static const CGFloat MASButtonFontSize = 11;
_shortcutValidator = [MASShortcutValidator sharedValidator];
_enabled = YES;
_showsDeleteButton = YES;
_acceptsFirstResponder = NO;
_acceptsFirstResponder = NO;
[self resetShortcutCellStyle];
}
@ -78,6 +78,7 @@ static const CGFloat MASButtonFontSize = 11;
_enabled = flag;
[self updateTrackingAreas];
self.recording = NO;
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
}
}
@ -87,6 +88,7 @@ static const CGFloat MASButtonFontSize = 11;
if (_style != newStyle) {
_style = newStyle;
[self resetShortcutCellStyle];
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
}
}
@ -135,6 +137,7 @@ static const CGFloat MASButtonFontSize = 11;
[self resetToolTips];
[self activateEventMonitoring:_recording];
[self activateResignObserver:_recording];
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
// Give VoiceOver users feedback on the result. Requires at least 10.9 to run.
@ -161,6 +164,7 @@ static const CGFloat MASButtonFontSize = 11;
{
_shortcutValue = shortcutValue;
[self resetToolTips];
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
[self propagateValue:shortcutValue forBinding:MASShortcutBinding];
@ -172,9 +176,17 @@ static const CGFloat MASButtonFontSize = 11;
- (void)setShortcutPlaceholder:(NSString *)shortcutPlaceholder
{
_shortcutPlaceholder = shortcutPlaceholder.copy;
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
}
#pragma mark - Appearance
- (BOOL)allowsVibrancy
{
return YES;
}
#pragma mark - Drawing
- (BOOL)isFlipped
@ -254,6 +266,25 @@ static const CGFloat MASButtonFontSize = 11;
}
}
- (NSSize)intrinsicContentSize
{
NSSize cellSize = _shortcutCell.cellSize;
// Use a "fake" value for width. Since determining the actual width requires information
// that is not determined until drawRect: is called, it doesn't seem feasible to properly
// calculate the intrinsic size without refactoring the code. That would give better results,
// however.
// 120 is an arbitray number that seems to be wide enough for English localization. This
// may need to be adjusted for other locales/languages.
// NOTE: Simply returning cellSize results in a display that is sometimes correct
// and sometimes not, and changes based on whether the mouse is hovering or not.
return NSMakeSize(120, cellSize.height);
}
#pragma mark - Mouse handling
- (void)getShortcutRect:(CGRect *)shortcutRectRef hintRect:(CGRect *)hintRectRef
@ -344,6 +375,7 @@ static const CGFloat MASButtonFontSize = 11;
{
if (_hinting != flag) {
_hinting = flag;
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
}
}
@ -364,10 +396,12 @@ void *kUserDataHint = &kUserDataHint;
- (void)resetToolTips
{
if (_shortcutToolTipTag) {
[self removeToolTip:_shortcutToolTipTag], _shortcutToolTipTag = 0;
[self removeToolTip:_shortcutToolTipTag];
_shortcutToolTipTag = 0;
}
if (_hintToolTipTag) {
[self removeToolTip:_hintToolTipTag], _hintToolTipTag = 0;
[self removeToolTip:_hintToolTipTag];
_hintToolTipTag = 0;
}
if ((self.shortcutValue == nil) || self.recording || !self.enabled) return;
@ -386,7 +420,7 @@ void *kUserDataHint = &kUserDataHint;
else if (data == kUserDataHint) {
return MASLocalizedString(@"Delete shortcut", @"Tooltip for hint button near the non-empty shortcut");
}
return nil;
return @"";
}
#pragma mark - Event monitoring
@ -432,10 +466,10 @@ void *kUserDataHint = &kUserDataHint;
else {
// Verify possible shortcut
if (shortcut.keyCodeString.length > 0) {
if ([_shortcutValidator isShortcutValid:shortcut]) {
if (!weakSelf.shortcutValidator || [weakSelf.shortcutValidator isShortcutValid:shortcut]) {
// Verify that shortcut is not used
NSString *explanation = nil;
if ([_shortcutValidator isShortcutAlreadyTakenBySystem:shortcut explanation:&explanation]) {
if ([weakSelf.shortcutValidator isShortcutAlreadyTakenBySystem:shortcut explanation:&explanation]) {
// Prevent cancel of recording when Alert window is key
[weakSelf activateResignObserver:NO];
[weakSelf activateEventMonitoring:NO];
@ -545,11 +579,6 @@ void *kUserDataHint = &kUserDataHint;
#pragma mark - Accessibility
- (BOOL)accessibilityIsIgnored
{
return NO;
}
- (NSString *)accessibilityHelp
{
return MASLocalizedString(@"To record a new shortcut, click this button, and then type the"
@ -582,22 +611,24 @@ void *kUserDataHint = &kUserDataHint;
- (BOOL)acceptsFirstResponder
{
return _acceptsFirstResponder;
return _acceptsFirstResponder;
}
- (void)setAcceptsFirstResponder:(BOOL)value
{
_acceptsFirstResponder = value;
_acceptsFirstResponder = value;
}
- (BOOL)becomeFirstResponder
{
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
return [super becomeFirstResponder];
}
- (BOOL)resignFirstResponder
{
[self invalidateIntrinsicContentSize];
[self setNeedsDisplay:YES];
return [super resignFirstResponder];
}

View File

@ -17,7 +17,7 @@ Features:
* Can be configured to be compatible with Shortcut Recorder
* Can be installed both through CocoaPods and as a Git submodule
* Mac App Store friendly
* Works on OS X 10.6 and up
* Works on OS X 10.10 and up
* Hacking-friendly codebase covered with tests
Partially done:

View File

@ -0,0 +1,47 @@
/* Cancel action button in recording state */
"Cancel" = "Cancelar";
/* Tooltip for non-empty shortcut button */
"Click to record new shortcut" ="Clique para gravar o atalho";
/* Tooltip for hint button near the non-empty shortcut */
"Delete shortcut" = "Apagar atalho";
/* VoiceOver title */
"keyboard shortcut" = "atalho de teclado";
/* Alert button when shortcut is already used */
"OK" = "OK";
/* Empty shortcut button in normal state */
"Record Shortcut" = "Gravar Atalho";
/* VoiceOver: Shortcut cleared */
"Shortcut cleared" = "Atalho limpo";
/* VoiceOver: Shortcut set */
"Shortcut set" = "Atalho definido";
/* Shortcut glyph name for SPACE key */
"Space" = "Espaço";
/* Title for alert when shortcut is already used */
"The key combination %@ cannot be used" = "A combinação de teclas “%@” não pode ser usada";
/* Message for alert when shortcut is already used by the system */
"This combination cannot be used because it is already used by a system-wide keyboard shortcut.\nIf you really want to use this key combination, most shortcuts can be changed in the Keyboard & Mouse panel in System Preferences." = "Esta combinação não pode ser usada porque ela já é usada por um atalho global do sistema.\nA maioria dos atalhos pode ser alterada no painel Teclado das Preferências do Sistema, caso realmente deseje usar esta combinação.";
/* Message for alert when shortcut is already used */
"This shortcut cannot be used because it is already used by the menu item %@." = "Este atalho não pode ser usado porque ele já é usado pelo item de menu “%@”.";
/* VoiceOver shortcut help */
"To record a new shortcut, click this button, and then type the new shortcut, or press delete to clear an existing shortcut." = "Para gravar um atalho novo, clique neste botão e digite o novo atalho ou pressione apagar para limpar um atalho existente.";
/* Non-empty shortcut button in recording state */
"Type New Shortcut" = "Digite o atalho";
/* Empty shortcut button in recording state */
"Type Shortcut" = "Digite o atalho";
/* Cancel action button for non-empty shortcut in recording state */
"Use Old Shortcut" = "Usar atalho antigo";

View File

@ -0,0 +1,47 @@
/* Cancel action button in recording state */
"Cancel" = "Avbryt";
/* Tooltip for non-empty shortcut button */
"Click to record new shortcut" = "Klicka för att registrera ny kortkommando";
/* Tooltip for hint button near the non-empty shortcut */
"Delete shortcut" = "Ta bort en kortkommando";
/* VoiceOver title */
"keyboard shortcut" = "Tangentbordskortkommando";
/* Alert button when shortcut is already used */
"OK" = "OK";
/* Empty shortcut button in normal state */
"Record Shortcut" = "Registrera kortkommando";
/* VoiceOver: Shortcut cleared */
"Shortcut cleared" = "Kortkommando rensas";
/* VoiceOver: Shortcut set */
"Shortcut set" = "Kortkommando uppsättning";
/* Shortcut glyph name for SPACE key */
"Space" = "Utrymme";
/* Title for alert when shortcut is already used */
"The key combination %@ cannot be used" = "Tangentkombinationen %@ kan inte användas";
/* Message for alert when shortcut is already used by the system */
"This combination cannot be used because it is already used by a system-wide keyboard shortcut.\nIf you really want to use this key combination, most shortcuts can be changed in the Keyboard & Mouse panel in System Preferences." = "Den här kombinationen kan inte användas eftersom den redan används som en tangentbordskortkommando. Om du verkligen vill använda den här tangentkombinationen kan de flesta genvägar ändras under Tangentbord & Mus i Systeminställningar.";
/* Message for alert when shortcut is already used */
"This shortcut cannot be used because it is already used by the menu item %@." = "Denna kortkommando kan inte användas eftersom det redan används av ett menyalternativ %@.";
/* VoiceOver shortcut help */
"To record a new shortcut, click this button, and then type the new shortcut, or press delete to clear an existing shortcut." = "För att registrera en ny kortkommando, klicka på den här knappen och skriv sedan in den nya kortkommando, eller tryck på radera för att rensa en befintlig kortkommando.";
/* Non-empty shortcut button in recording state */
"Type New Shortcut" = "Skriv Ny Kortkommando";
/* Empty shortcut button in recording state */
"Type Shortcut" = "Skriv Kortkommando";
/* Cancel action button for non-empty shortcut in recording state */
"Use Old Shortcut" = "Använd Gammal Kortkommando";