@theia/memory-inspector 1.45.0 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -71
- package/lib/browser/diff-widget/memory-diff-options-widget.d.ts +36 -36
- package/lib/browser/diff-widget/memory-diff-options-widget.js +132 -132
- package/lib/browser/diff-widget/memory-diff-select-widget.d.ts +50 -50
- package/lib/browser/diff-widget/memory-diff-select-widget.js +137 -137
- package/lib/browser/diff-widget/memory-diff-table-widget.d.ts +77 -77
- package/lib/browser/diff-widget/memory-diff-table-widget.js +314 -314
- package/lib/browser/diff-widget/memory-diff-widget-types.d.ts +41 -41
- package/lib/browser/diff-widget/memory-diff-widget-types.js +23 -23
- package/lib/browser/editable-widget/memory-editable-table-widget.d.ts +64 -64
- package/lib/browser/editable-widget/memory-editable-table-widget.js +324 -324
- package/lib/browser/memory-inspector-frontend-contribution.d.ts +46 -46
- package/lib/browser/memory-inspector-frontend-contribution.js +291 -291
- package/lib/browser/memory-inspector-frontend-module.d.ts +21 -21
- package/lib/browser/memory-inspector-frontend-module.js +87 -87
- package/lib/browser/memory-provider/cdt-gdb-memory-provider.d.ts +35 -35
- package/lib/browser/memory-provider/cdt-gdb-memory-provider.js +136 -136
- package/lib/browser/memory-provider/memory-provider-service.d.ts +36 -36
- package/lib/browser/memory-provider/memory-provider-service.js +101 -101
- package/lib/browser/memory-provider/memory-provider.d.ts +65 -65
- package/lib/browser/memory-provider/memory-provider.js +96 -96
- package/lib/browser/memory-provider/memory-provider.spec.d.ts +16 -16
- package/lib/browser/memory-provider/memory-provider.spec.js +23 -23
- package/lib/browser/memory-widget/memory-options-widget.d.ts +136 -136
- package/lib/browser/memory-widget/memory-options-widget.js +564 -564
- package/lib/browser/memory-widget/memory-table-widget.d.ts +146 -146
- package/lib/browser/memory-widget/memory-table-widget.js +487 -487
- package/lib/browser/memory-widget/memory-widget.d.ts +33 -33
- package/lib/browser/memory-widget/memory-widget.js +112 -112
- package/lib/browser/register-widget/register-filter-service.d.ts +42 -42
- package/lib/browser/register-widget/register-filter-service.js +81 -81
- package/lib/browser/register-widget/register-options-widget.d.ts +81 -81
- package/lib/browser/register-widget/register-options-widget.js +338 -338
- package/lib/browser/register-widget/register-table-widget.d.ts +77 -77
- package/lib/browser/register-widget/register-table-widget.js +230 -230
- package/lib/browser/register-widget/register-widget-types.d.ts +29 -29
- package/lib/browser/register-widget/register-widget-types.js +35 -35
- package/lib/browser/utils/memory-commands.d.ts +27 -27
- package/lib/browser/utils/memory-commands.js +67 -67
- package/lib/browser/utils/memory-hover-renderer.d.ts +33 -33
- package/lib/browser/utils/memory-hover-renderer.js +111 -111
- package/lib/browser/utils/memory-recents.d.ts +27 -27
- package/lib/browser/utils/memory-recents.js +52 -52
- package/lib/browser/utils/memory-widget-components.d.ts +58 -58
- package/lib/browser/utils/memory-widget-components.js +69 -69
- package/lib/browser/utils/memory-widget-manager.d.ts +50 -50
- package/lib/browser/utils/memory-widget-manager.js +182 -182
- package/lib/browser/utils/memory-widget-utils.d.ts +113 -113
- package/lib/browser/utils/memory-widget-utils.js +42 -42
- package/lib/browser/utils/memory-widget-variable-utils.d.ts +57 -57
- package/lib/browser/utils/memory-widget-variable-utils.js +143 -143
- package/lib/browser/utils/multi-select-bar.d.ts +31 -31
- package/lib/browser/utils/multi-select-bar.js +34 -34
- package/lib/browser/wrapper-widgets/memory-dock-panel.d.ts +24 -24
- package/lib/browser/wrapper-widgets/memory-dock-panel.js +48 -48
- package/lib/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.d.ts +23 -23
- package/lib/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.js +57 -57
- package/lib/browser/wrapper-widgets/memory-layout-widget.d.ts +51 -51
- package/lib/browser/wrapper-widgets/memory-layout-widget.js +191 -191
- package/lib/common/util.d.ts +21 -21
- package/lib/common/util.js +30 -30
- package/lib/common/utils.spec.d.ts +16 -16
- package/lib/common/utils.spec.js +45 -45
- package/package.json +4 -4
- package/src/browser/diff-widget/memory-diff-options-widget.tsx +152 -152
- package/src/browser/diff-widget/memory-diff-select-widget.tsx +163 -163
- package/src/browser/diff-widget/memory-diff-table-widget.tsx +366 -366
- package/src/browser/diff-widget/memory-diff-widget-types.ts +45 -45
- package/src/browser/editable-widget/memory-editable-table-widget.tsx +359 -359
- package/src/browser/memory-inspector-frontend-contribution.ts +301 -301
- package/src/browser/memory-inspector-frontend-module.ts +118 -118
- package/src/browser/memory-provider/cdt-gdb-memory-provider.ts +132 -132
- package/src/browser/memory-provider/memory-provider-service.ts +86 -86
- package/src/browser/memory-provider/memory-provider.spec.ts +23 -23
- package/src/browser/memory-provider/memory-provider.ts +119 -119
- package/src/browser/memory-widget/memory-options-widget.tsx +738 -738
- package/src/browser/memory-widget/memory-table-widget.tsx +625 -625
- package/src/browser/memory-widget/memory-widget.ts +114 -114
- package/src/browser/register-widget/register-filter-service.ts +76 -76
- package/src/browser/register-widget/register-options-widget.tsx +393 -393
- package/src/browser/register-widget/register-table-widget.tsx +276 -276
- package/src/browser/register-widget/register-widget-types.ts +45 -45
- package/src/browser/register-widget/register-widget.css +34 -34
- package/src/browser/style/index.css +746 -746
- package/src/browser/style/memory-lock.svg +21 -21
- package/src/browser/style/memory-view.svg +20 -20
- package/src/browser/style/register-lock.svg +29 -29
- package/src/browser/style/register-view.svg +28 -28
- package/src/browser/utils/memory-commands.ts +76 -76
- package/src/browser/utils/memory-hover-renderer.ts +113 -113
- package/src/browser/utils/memory-recents.ts +58 -58
- package/src/browser/utils/memory-widget-components.tsx +193 -193
- package/src/browser/utils/memory-widget-manager.ts +179 -179
- package/src/browser/utils/memory-widget-utils.tsx +132 -132
- package/src/browser/utils/memory-widget-variable-utils.ts +170 -170
- package/src/browser/utils/multi-select-bar.css +61 -61
- package/src/browser/utils/multi-select-bar.tsx +75 -75
- package/src/browser/wrapper-widgets/memory-dock-panel.ts +51 -51
- package/src/browser/wrapper-widgets/memory-dockpanel-placeholder-widget.tsx +38 -38
- package/src/browser/wrapper-widgets/memory-layout-widget.tsx +167 -167
- package/src/common/util.ts +28 -28
- package/src/common/utils.spec.ts +52 -52
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (C) 2021 Ericsson and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
* Utility for storing and sorting an array of most recently visited memory locations
|
|
19
|
-
*/
|
|
20
|
-
interface RecentsOptions {
|
|
21
|
-
maxValues?: number;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class Recents {
|
|
25
|
-
protected maxValues: number;
|
|
26
|
-
protected _values: string[] = [];
|
|
27
|
-
get values(): string[] {
|
|
28
|
-
return this._values;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
constructor(initialValues?: string[], opts?: RecentsOptions) {
|
|
32
|
-
this.maxValues = opts?.maxValues ?? 10;
|
|
33
|
-
if (initialValues) {
|
|
34
|
-
if (initialValues.length <= this.maxValues) {
|
|
35
|
-
this._values = initialValues;
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
console.error('Initial values length is greater than allowed length, resetting to empty array');
|
|
39
|
-
}
|
|
40
|
-
this._values = [];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
add(locationString: string): void {
|
|
44
|
-
const indexOf = this.has(locationString);
|
|
45
|
-
if (indexOf > -1) {
|
|
46
|
-
this._values.splice(indexOf, 1);
|
|
47
|
-
} else {
|
|
48
|
-
if (this._values.length === this.maxValues) {
|
|
49
|
-
this._values.shift();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
this._values.push(locationString);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
has(locationString: string): number {
|
|
56
|
-
return this._values.indexOf(locationString);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 Ericsson and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Utility for storing and sorting an array of most recently visited memory locations
|
|
19
|
+
*/
|
|
20
|
+
interface RecentsOptions {
|
|
21
|
+
maxValues?: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class Recents {
|
|
25
|
+
protected maxValues: number;
|
|
26
|
+
protected _values: string[] = [];
|
|
27
|
+
get values(): string[] {
|
|
28
|
+
return this._values;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
constructor(initialValues?: string[], opts?: RecentsOptions) {
|
|
32
|
+
this.maxValues = opts?.maxValues ?? 10;
|
|
33
|
+
if (initialValues) {
|
|
34
|
+
if (initialValues.length <= this.maxValues) {
|
|
35
|
+
this._values = initialValues;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
console.error('Initial values length is greater than allowed length, resetting to empty array');
|
|
39
|
+
}
|
|
40
|
+
this._values = [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
add(locationString: string): void {
|
|
44
|
+
const indexOf = this.has(locationString);
|
|
45
|
+
if (indexOf > -1) {
|
|
46
|
+
this._values.splice(indexOf, 1);
|
|
47
|
+
} else {
|
|
48
|
+
if (this._values.length === this.maxValues) {
|
|
49
|
+
this._values.shift();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
this._values.push(locationString);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
has(locationString: string): number {
|
|
56
|
+
return this._values.indexOf(locationString);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,193 +1,193 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (C) 2021 Ericsson and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
|
|
17
|
-
import { Key, KeyCode } from '@theia/core/lib/browser';
|
|
18
|
-
import * as React from '@theia/core/shared/react';
|
|
19
|
-
import { Interfaces } from './memory-widget-utils';
|
|
20
|
-
|
|
21
|
-
export interface MWLabelProps { id: string; label: string; disabled?: boolean; classNames?: string[] }
|
|
22
|
-
|
|
23
|
-
export const MWLabel: React.FC<MWLabelProps> = ({ id, label, disabled, classNames }) => {
|
|
24
|
-
const additionalClassNames = classNames ? classNames.join(' ') : '';
|
|
25
|
-
return <label htmlFor={id} className={`t-mv-label theia-header no-select ${additionalClassNames}${disabled ? ' disabled' : ''}`}>{label}</label>;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export interface InputProps<T extends HTMLElement = HTMLElement> {
|
|
29
|
-
id: string;
|
|
30
|
-
label: string;
|
|
31
|
-
defaultValue?: string;
|
|
32
|
-
value?: string;
|
|
33
|
-
onChange?: React.EventHandler<React.ChangeEvent>;
|
|
34
|
-
onKeyDown?: React.EventHandler<React.KeyboardEvent<HTMLInputElement>>;
|
|
35
|
-
passRef?: React.ClassAttributes<T>['ref'];
|
|
36
|
-
title?: string;
|
|
37
|
-
disabled?: boolean;
|
|
38
|
-
placeholder?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const MWInput: React.FC<InputProps<HTMLInputElement>> = ({ id, label, passRef, defaultValue, onChange, title, onKeyDown, disabled }) => (
|
|
42
|
-
<>
|
|
43
|
-
<MWLabel id={id} label={label} disabled={disabled} />
|
|
44
|
-
<input
|
|
45
|
-
tabIndex={0}
|
|
46
|
-
type='text'
|
|
47
|
-
ref={passRef}
|
|
48
|
-
id={id}
|
|
49
|
-
className='theia-input t-mv-input'
|
|
50
|
-
defaultValue={defaultValue}
|
|
51
|
-
onChange={onChange}
|
|
52
|
-
onKeyDown={onKeyDown}
|
|
53
|
-
title={title}
|
|
54
|
-
spellCheck={false}
|
|
55
|
-
disabled={disabled}
|
|
56
|
-
/>
|
|
57
|
-
</>
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
export interface LabelAndSelectProps extends InputProps<HTMLSelectElement> {
|
|
61
|
-
options: string[];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const MWSelect: React.FC<LabelAndSelectProps> = ({ id, label, options, passRef, onChange, title, value, disabled }) => (
|
|
65
|
-
<>
|
|
66
|
-
<MWLabel id={id} label={label} disabled={disabled} />
|
|
67
|
-
<select
|
|
68
|
-
tabIndex={0}
|
|
69
|
-
ref={passRef}
|
|
70
|
-
id={id}
|
|
71
|
-
className='theia-select t-mv-select'
|
|
72
|
-
value={value}
|
|
73
|
-
onChange={onChange}
|
|
74
|
-
title={title}
|
|
75
|
-
disabled={disabled}
|
|
76
|
-
>
|
|
77
|
-
{options.map(option => <option value={option} key={option}>{option}</option>)}
|
|
78
|
-
</select>
|
|
79
|
-
</>
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
export interface LabelAndSelectWithNameProps extends InputProps<HTMLSelectElement> {
|
|
83
|
-
options: Array<[string, string]>;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const MWSelectWithName: React.FC<LabelAndSelectWithNameProps> = ({ id, label, options, passRef, onChange, title, value, disabled }) => (
|
|
87
|
-
<>
|
|
88
|
-
<MWLabel id={id} label={label} disabled={disabled} />
|
|
89
|
-
<select
|
|
90
|
-
tabIndex={0}
|
|
91
|
-
ref={passRef}
|
|
92
|
-
id={id}
|
|
93
|
-
className='theia-select'
|
|
94
|
-
value={value}
|
|
95
|
-
onChange={onChange}
|
|
96
|
-
title={title}
|
|
97
|
-
disabled={disabled}
|
|
98
|
-
>
|
|
99
|
-
{options.map(option => <option value={option[0]} key={option[0]}>{option[1]}</option>)}
|
|
100
|
-
</select>
|
|
101
|
-
</>
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
export interface InputWithSelectProps<T extends HTMLElement> extends InputProps<T> {
|
|
105
|
-
options: string[];
|
|
106
|
-
onSelectChange?(e: React.ChangeEvent): void;
|
|
107
|
-
onInputChange?(e: React.ChangeEvent<HTMLInputElement>): void;
|
|
108
|
-
}
|
|
109
|
-
export const MWInputWithSelect: React.FC<InputWithSelectProps<HTMLInputElement>> = (
|
|
110
|
-
{ id, label, passRef, onKeyDown, title, options, onSelectChange, defaultValue, disabled, placeholder },
|
|
111
|
-
) => (
|
|
112
|
-
<>
|
|
113
|
-
<MWLabel id={id} label={label} disabled={disabled} />
|
|
114
|
-
<div className='mw-input-select'>
|
|
115
|
-
<input
|
|
116
|
-
tabIndex={0}
|
|
117
|
-
type='text'
|
|
118
|
-
ref={passRef}
|
|
119
|
-
id={id}
|
|
120
|
-
className='theia-input t-mv-input'
|
|
121
|
-
defaultValue={defaultValue}
|
|
122
|
-
onKeyDown={onKeyDown}
|
|
123
|
-
title={title}
|
|
124
|
-
spellCheck={false}
|
|
125
|
-
disabled={disabled}
|
|
126
|
-
placeholder={placeholder}
|
|
127
|
-
/>
|
|
128
|
-
<select
|
|
129
|
-
className='theia-select t-mv-select'
|
|
130
|
-
onChange={onSelectChange}
|
|
131
|
-
disabled={disabled || (options.length === 0)}
|
|
132
|
-
>
|
|
133
|
-
{options.reverse().map(option => <option key={`'mw-input-select'-${id}-${option}`} value={option}>{option}</option>)}
|
|
134
|
-
</select>
|
|
135
|
-
</div>
|
|
136
|
-
</>
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
export interface MoreMemoryProps {
|
|
140
|
-
options: number[];
|
|
141
|
-
direction: 'above' | 'below';
|
|
142
|
-
handler(opts: Interfaces.MoreMemoryOptions): void;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export const MWMoreMemorySelect: React.FC<MoreMemoryProps> = ({ options, handler, direction }) => {
|
|
146
|
-
const [numBytes, setNumBytes] = React.useState<number>(options[0]);
|
|
147
|
-
const containerRef = React.createRef<HTMLDivElement>();
|
|
148
|
-
const onSelectChange = (e: React.ChangeEvent<HTMLSelectElement>): void => {
|
|
149
|
-
e.stopPropagation();
|
|
150
|
-
const { value } = e.currentTarget;
|
|
151
|
-
setNumBytes(parseInt(value));
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const loadMoreMemory = (e: React.MouseEvent | React.KeyboardEvent): void => {
|
|
155
|
-
containerRef.current?.blur();
|
|
156
|
-
const doHandle = !('key' in e) || KeyCode.createKeyCode(e.nativeEvent).key?.keyCode === Key.ENTER.keyCode;
|
|
157
|
-
if (doHandle) {
|
|
158
|
-
handler({
|
|
159
|
-
numBytes,
|
|
160
|
-
direction,
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
<div
|
|
167
|
-
className='mw-more-memory-select'
|
|
168
|
-
tabIndex={0}
|
|
169
|
-
role='button'
|
|
170
|
-
onClick={loadMoreMemory}
|
|
171
|
-
onKeyDown={loadMoreMemory}
|
|
172
|
-
ref={containerRef}
|
|
173
|
-
>
|
|
174
|
-
<div className='mw-more-memory-select-top no-select'>
|
|
175
|
-
Load
|
|
176
|
-
<select
|
|
177
|
-
className='theia-select'
|
|
178
|
-
onChange={onSelectChange}
|
|
179
|
-
tabIndex={0}
|
|
180
|
-
>
|
|
181
|
-
{options.map(option => (
|
|
182
|
-
<option
|
|
183
|
-
key={`mw-more-memory-select-${option}`}
|
|
184
|
-
value={option}
|
|
185
|
-
>
|
|
186
|
-
{option}
|
|
187
|
-
</option>))}
|
|
188
|
-
</select>
|
|
189
|
-
{`more bytes ${direction}`}
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
);
|
|
193
|
-
};
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2021 Ericsson and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import { Key, KeyCode } from '@theia/core/lib/browser';
|
|
18
|
+
import * as React from '@theia/core/shared/react';
|
|
19
|
+
import { Interfaces } from './memory-widget-utils';
|
|
20
|
+
|
|
21
|
+
export interface MWLabelProps { id: string; label: string; disabled?: boolean; classNames?: string[] }
|
|
22
|
+
|
|
23
|
+
export const MWLabel: React.FC<MWLabelProps> = ({ id, label, disabled, classNames }) => {
|
|
24
|
+
const additionalClassNames = classNames ? classNames.join(' ') : '';
|
|
25
|
+
return <label htmlFor={id} className={`t-mv-label theia-header no-select ${additionalClassNames}${disabled ? ' disabled' : ''}`}>{label}</label>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export interface InputProps<T extends HTMLElement = HTMLElement> {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
defaultValue?: string;
|
|
32
|
+
value?: string;
|
|
33
|
+
onChange?: React.EventHandler<React.ChangeEvent>;
|
|
34
|
+
onKeyDown?: React.EventHandler<React.KeyboardEvent<HTMLInputElement>>;
|
|
35
|
+
passRef?: React.ClassAttributes<T>['ref'];
|
|
36
|
+
title?: string;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const MWInput: React.FC<InputProps<HTMLInputElement>> = ({ id, label, passRef, defaultValue, onChange, title, onKeyDown, disabled }) => (
|
|
42
|
+
<>
|
|
43
|
+
<MWLabel id={id} label={label} disabled={disabled} />
|
|
44
|
+
<input
|
|
45
|
+
tabIndex={0}
|
|
46
|
+
type='text'
|
|
47
|
+
ref={passRef}
|
|
48
|
+
id={id}
|
|
49
|
+
className='theia-input t-mv-input'
|
|
50
|
+
defaultValue={defaultValue}
|
|
51
|
+
onChange={onChange}
|
|
52
|
+
onKeyDown={onKeyDown}
|
|
53
|
+
title={title}
|
|
54
|
+
spellCheck={false}
|
|
55
|
+
disabled={disabled}
|
|
56
|
+
/>
|
|
57
|
+
</>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
export interface LabelAndSelectProps extends InputProps<HTMLSelectElement> {
|
|
61
|
+
options: string[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const MWSelect: React.FC<LabelAndSelectProps> = ({ id, label, options, passRef, onChange, title, value, disabled }) => (
|
|
65
|
+
<>
|
|
66
|
+
<MWLabel id={id} label={label} disabled={disabled} />
|
|
67
|
+
<select
|
|
68
|
+
tabIndex={0}
|
|
69
|
+
ref={passRef}
|
|
70
|
+
id={id}
|
|
71
|
+
className='theia-select t-mv-select'
|
|
72
|
+
value={value}
|
|
73
|
+
onChange={onChange}
|
|
74
|
+
title={title}
|
|
75
|
+
disabled={disabled}
|
|
76
|
+
>
|
|
77
|
+
{options.map(option => <option value={option} key={option}>{option}</option>)}
|
|
78
|
+
</select>
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
export interface LabelAndSelectWithNameProps extends InputProps<HTMLSelectElement> {
|
|
83
|
+
options: Array<[string, string]>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const MWSelectWithName: React.FC<LabelAndSelectWithNameProps> = ({ id, label, options, passRef, onChange, title, value, disabled }) => (
|
|
87
|
+
<>
|
|
88
|
+
<MWLabel id={id} label={label} disabled={disabled} />
|
|
89
|
+
<select
|
|
90
|
+
tabIndex={0}
|
|
91
|
+
ref={passRef}
|
|
92
|
+
id={id}
|
|
93
|
+
className='theia-select'
|
|
94
|
+
value={value}
|
|
95
|
+
onChange={onChange}
|
|
96
|
+
title={title}
|
|
97
|
+
disabled={disabled}
|
|
98
|
+
>
|
|
99
|
+
{options.map(option => <option value={option[0]} key={option[0]}>{option[1]}</option>)}
|
|
100
|
+
</select>
|
|
101
|
+
</>
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
export interface InputWithSelectProps<T extends HTMLElement> extends InputProps<T> {
|
|
105
|
+
options: string[];
|
|
106
|
+
onSelectChange?(e: React.ChangeEvent): void;
|
|
107
|
+
onInputChange?(e: React.ChangeEvent<HTMLInputElement>): void;
|
|
108
|
+
}
|
|
109
|
+
export const MWInputWithSelect: React.FC<InputWithSelectProps<HTMLInputElement>> = (
|
|
110
|
+
{ id, label, passRef, onKeyDown, title, options, onSelectChange, defaultValue, disabled, placeholder },
|
|
111
|
+
) => (
|
|
112
|
+
<>
|
|
113
|
+
<MWLabel id={id} label={label} disabled={disabled} />
|
|
114
|
+
<div className='mw-input-select'>
|
|
115
|
+
<input
|
|
116
|
+
tabIndex={0}
|
|
117
|
+
type='text'
|
|
118
|
+
ref={passRef}
|
|
119
|
+
id={id}
|
|
120
|
+
className='theia-input t-mv-input'
|
|
121
|
+
defaultValue={defaultValue}
|
|
122
|
+
onKeyDown={onKeyDown}
|
|
123
|
+
title={title}
|
|
124
|
+
spellCheck={false}
|
|
125
|
+
disabled={disabled}
|
|
126
|
+
placeholder={placeholder}
|
|
127
|
+
/>
|
|
128
|
+
<select
|
|
129
|
+
className='theia-select t-mv-select'
|
|
130
|
+
onChange={onSelectChange}
|
|
131
|
+
disabled={disabled || (options.length === 0)}
|
|
132
|
+
>
|
|
133
|
+
{options.reverse().map(option => <option key={`'mw-input-select'-${id}-${option}`} value={option}>{option}</option>)}
|
|
134
|
+
</select>
|
|
135
|
+
</div>
|
|
136
|
+
</>
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
export interface MoreMemoryProps {
|
|
140
|
+
options: number[];
|
|
141
|
+
direction: 'above' | 'below';
|
|
142
|
+
handler(opts: Interfaces.MoreMemoryOptions): void;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const MWMoreMemorySelect: React.FC<MoreMemoryProps> = ({ options, handler, direction }) => {
|
|
146
|
+
const [numBytes, setNumBytes] = React.useState<number>(options[0]);
|
|
147
|
+
const containerRef = React.createRef<HTMLDivElement>();
|
|
148
|
+
const onSelectChange = (e: React.ChangeEvent<HTMLSelectElement>): void => {
|
|
149
|
+
e.stopPropagation();
|
|
150
|
+
const { value } = e.currentTarget;
|
|
151
|
+
setNumBytes(parseInt(value));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const loadMoreMemory = (e: React.MouseEvent | React.KeyboardEvent): void => {
|
|
155
|
+
containerRef.current?.blur();
|
|
156
|
+
const doHandle = !('key' in e) || KeyCode.createKeyCode(e.nativeEvent).key?.keyCode === Key.ENTER.keyCode;
|
|
157
|
+
if (doHandle) {
|
|
158
|
+
handler({
|
|
159
|
+
numBytes,
|
|
160
|
+
direction,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return (
|
|
166
|
+
<div
|
|
167
|
+
className='mw-more-memory-select'
|
|
168
|
+
tabIndex={0}
|
|
169
|
+
role='button'
|
|
170
|
+
onClick={loadMoreMemory}
|
|
171
|
+
onKeyDown={loadMoreMemory}
|
|
172
|
+
ref={containerRef}
|
|
173
|
+
>
|
|
174
|
+
<div className='mw-more-memory-select-top no-select'>
|
|
175
|
+
Load
|
|
176
|
+
<select
|
|
177
|
+
className='theia-select'
|
|
178
|
+
onChange={onSelectChange}
|
|
179
|
+
tabIndex={0}
|
|
180
|
+
>
|
|
181
|
+
{options.map(option => (
|
|
182
|
+
<option
|
|
183
|
+
key={`mw-more-memory-select-${option}`}
|
|
184
|
+
value={option}
|
|
185
|
+
>
|
|
186
|
+
{option}
|
|
187
|
+
</option>))}
|
|
188
|
+
</select>
|
|
189
|
+
{`more bytes ${direction}`}
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
);
|
|
193
|
+
};
|