forked from Kentzo/ShortcutRecorder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSRValidator.h
131 lines (88 loc) · 4.31 KB
/
SRValidator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// SRValidator.h
// ShortcutRecorder
//
// Copyright 2006-2012 Contributors. All rights reserved.
//
// License: BSD
//
// Contributors:
// David Dauer
// Jesper
// Jamie Kirkpatrick
// Andy Kim
// Silvio Rizzi
// Ilya Kulakov
#import <Cocoa/Cocoa.h>
@protocol SRValidatorDelegate;
/*!
@brief Implements logic to check whether shortcut is taken by other parts of the application and system.
*/
@interface SRValidator : NSObject
@property (assign) NSObject<SRValidatorDelegate> *delegate;
- (instancetype)initWithDelegate:(NSObject<SRValidatorDelegate> *)aDelegate;
/*!
@brief Determines whether shortcut is taken.
@discussion Key is checked in the following order:
1. If delegate implements shortcutValidator:isKeyCode:andFlagsTaken:reason:
2. If delegate allows system-wide shortcuts are checked
3. If delegate allows application menu it checked
@see SRValidatorDelegate
*/
- (BOOL)isKeyCode:(unsigned short)aKeyCode andFlagsTaken:(NSUInteger)aFlags error:(NSError **)outError;
/*!
@brief Determines whether shortcut is taken in delegate.
@discussion If delegate does not implement appropriate method, returns immediately.
*/
- (BOOL)isKeyCode:(unsigned short)aKeyCode andFlagTakenInDelegate:(NSUInteger)aFlags error:(NSError **)outError;
/*!
@brief Determines whether shortcut is taken by system-wide shortcuts.
@discussion Does not check whether delegate allows or disallows checking in system shortcuts.
*/
- (BOOL)isKeyCode:(unsigned short)aKeyCode andFlagsTakenInSystemShortcuts:(NSUInteger)aFlags error:(NSError **)outError;
/*!
@brief Determines whether shortcut is taken by application menu item.
@discussion Does not check whether delegate allows or disallows checking in application menu.
*/
- (BOOL)isKeyCode:(unsigned short)aKeyCode andFlags:(NSUInteger)aFlags takenInMenu:(NSMenu *)aMenu error:(NSError **)outError;
@end
@protocol SRValidatorDelegate
@optional
/*!
@brief Asks the delegate if aKeyCode and aFlags are valid.
@param aValidator The validator that validates key code and flags.
@param aKeyCode Key code to validate.
@param aFlags Flags to validate.
@param outReason If delegate decides that shortcut is invalid, it may pass here an error message.
@result YES if shortcut is valid. Otherwise NO.
@discussion Implementation of this method by the delegate is optional. If it is not present, checking proceeds as if this method had returned YES.
*/
- (BOOL)shortcutValidator:(SRValidator *)aValidator isKeyCode:(unsigned short)aKeyCode andFlagsTaken:(NSUInteger)aFlags reason:(NSString **)outReason;
/*!
@brief Asks the delegate whether validator should check key equivalents of app's menu items.
@param aValidator The validator that going to check app's menu items.
@result YES if validator should check key equivalents of app's menu items. Otherwise NO.
@discussion Implementation of this method by the delegate is optional. If it is not present, checking proceeds as if this method had returned YES.
*/
- (BOOL)shortcutValidatorShouldCheckMenu:(SRValidator *)aValidator;
/*!
@brief Asks the delegate whether it should check system shortcuts.
@param aValidator The validator that going to check system shortcuts.
@result YES if validator should check system shortcuts. Otherwise NO.
@discussion Implementation of this method by the delegate is optional. If it is not present, checking proceeds as if this method had returned YES.
*/
- (BOOL)shortcutValidatorShouldCheckSystemShortcuts:(SRValidator *)aValidator;
/*!
@brief Asks the delegate whether it should use ASCII representation of key code when making error messages.
@param aValidator The validator that is about to make an error message.
@result YES if validator should use ASCII representation. Otherwise NO.
@discussion Implementation of this method by the delegate is optional. If it is not present, ASCII representation of key code is used.
*/
- (BOOL)shortcutValidatorShouldUseASCIIStringForKeyCodes:(SRValidator *)aValidator;
@end
@interface NSMenuItem (SRValidator)
/*!
@brief Returns full path to the menu item. E.g. "Window ➝ Zoom"
*/
- (NSString *)SR_path;
@end