-
Notifications
You must be signed in to change notification settings - Fork 2
/
FrameworkKeyboardShortcuts.ts
137 lines (111 loc) · 4.7 KB
/
FrameworkKeyboardShortcuts.ts
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
132
133
134
135
136
137
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module KeyboardShortcut
*/
import type { Key } from "ts-key-enum";
import type { ActionButtonItemDef } from "../shared/ActionButtonItemDef";
import type { ItemDefBase } from "../shared/ItemDefBase";
import type { ItemProps } from "../shared/ItemProps";
/** Properties for a Keyboard Shortcut
* @public
*/
export interface KeyboardShortcutProps extends ItemProps {
/** The key that invokes the shortcut.
* This is either an alphanumeric key, a function key or a special key.
*/
key: string | Key;
/** The item to execute when this shortcut is invoked. Either 'item' or 'shortcuts' must be specified. */
item?: ActionButtonItemDef;
/** Nested array of shortcut props. Either 'item' or 'shortcuts' must be specified. */
shortcuts?: KeyboardShortcutProps[];
/** Indicates whether the Alt key required. Default - false */
isAltKeyRequired?: boolean;
/** Indicates whether the Ctrl key required. Default - false */
isCtrlKeyRequired?: boolean;
/** Indicates whether the Shift key required. Default - false */
isShiftKeyRequired?: boolean;
}
/** Keyboard Shortcut used to execute an action
* @public
*/
export interface FrameworkKeyboardShortcut extends ItemDefBase {
/** Returns the id for this shortcut */
readonly id: string;
/** Returns the shortcut container */
readonly shortcutContainer: FrameworkKeyboardShortcutContainer;
/** Finds a shortcut with a given key in the shortcut's container */
getShortcut(mapKey: string): FrameworkKeyboardShortcut | undefined;
/** Returns the shortcut's key map key used as the id */
readonly keyMapKey: string;
/** Returns the [[ActionButtonItemDef]] associated with this shortcut */
readonly item: ActionButtonItemDef | undefined;
/** Called when the [[ActionButtonItemDef]] associated with this shortcut is invoked */
itemPicked(): void;
/** Gets the keyboard key */
readonly key: string;
/** Gets whether the Alt key required. */
readonly isAltKeyRequired: boolean;
/** Gets whether the Ctrl key required. */
readonly isCtrlKeyRequired: boolean;
/** Gets whether the Shift key required. */
readonly isShiftKeyRequired: boolean;
/** Gets whether this is a Function key. */
readonly isFunctionKey: boolean;
/** Gets whether this is a Special key. */
readonly isSpecialKey: boolean;
}
/** Keyboard Shortcut Container
* @public
*/
export interface FrameworkKeyboardShortcutContainer {
/** Registers a Keyboard Shortcut associated with a given key in the managed list */
registerKey(
keyMapKey: string,
inShortcut: FrameworkKeyboardShortcut
): FrameworkKeyboardShortcut | undefined;
/** Finds a Keyboard Shortcut associated with a given key */
findKey(keyMapKey: string): FrameworkKeyboardShortcut | undefined;
/** Determines if any Keyboard Shortcuts are available in this container */
areKeyboardShortcutsAvailable(): boolean;
/** Empties any Keyboard Shortcuts from this container */
emptyData(): void;
getAvailableKeyboardShortcuts(): FrameworkKeyboardShortcut[];
/** Displays a menu for the Keyboard Shortcuts in this container */
showShortcutsMenu(): void;
}
/**
* [[UiFramework.keyboardShortcuts]] interface
* @public
*/
export interface FrameworkKeyboardShortcuts {
/** Loads Keyboard Shortcuts into the managed list */
loadShortcuts(shortcutList: KeyboardShortcutProps[]): void;
/** Loads a Keyboard Shortcut into the managed list */
loadShortcut(shortcutProps: KeyboardShortcutProps): void;
/** Processes a keystroke and invokes a matching Keyboard Shortcut */
processKey(
keyboardKey: string,
isAltKeyPressed?: boolean,
isCtrlKeyPressed?: boolean,
isShiftKeyPressed?: boolean
): boolean;
/** Returns the managed list of Keyboard Shortcuts */
readonly shortcutContainer: FrameworkKeyboardShortcutContainer;
/** Returns a Keyboard Shortcut from the managed lists */
getShortcut(keyMapKey: string): FrameworkKeyboardShortcut | undefined;
/** Determines if focus is set to Home */
readonly isFocusOnHome: boolean;
/** Sets focus to Home */
setFocusToHome(): void;
/** Displays the Keyboard Shortcuts menu at the cursor */
displayMenu(): void;
/** Closes the Keyboard Shortcuts menu */
closeMenu(): void;
/** Returns the cursor X position, which is mouseEvent.pageX. */
readonly cursorX: number;
/** Returns the cursor Y position, which is mouseEvent.pageY. */
readonly cursorY: number;
}