Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 3a20712

Browse files
committed
Update with dev
2 parents ac940ff + 2446106 commit 3a20712

7 files changed

Lines changed: 50 additions & 69 deletions

File tree

src/view/components/Dropdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const Dropdown: React.FC<IDropdownProps> = props => {
2020
const defaultText =
2121
props.lastChosen !== ""
2222
? CONSTANTS.CURRENTLY_RUNNING(parsedPath[1])
23-
: CONSTANTS.NO_FILES_AVAILABLE;
23+
: CONSTANTS.FILES_PLACEHOLDER;
2424
return (
2525
<div>
2626
<select

src/view/components/cpx/CpxSimulator.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { sendMessage } from "../../utils/MessageUtils";
88
import "../../styles/Simulator.css";
99
import PlayLogo from "../../svgs/play_svg";
1010
import StopLogo from "../../svgs/stop_svg";
11-
import Dropdown from "../Dropdown";
1211
import ActionBar from "../simulator/ActionBar";
1312
import { BUTTON_NEUTRAL, BUTTON_PRESSED } from "./Cpx_svg_style";
1413
import { CpxImage, updatePinTouch, updateSwitch } from "./CpxImage";
@@ -30,6 +29,7 @@ interface IState {
3029
selected_file: string;
3130
cpx: ICpxState;
3231
play_button: boolean;
32+
currently_selected_file: string;
3333
}
3434

3535
const DEFAULT_CPX_STATE: ICpxState = {
@@ -63,6 +63,7 @@ class Simulator extends React.Component<{}, IState> {
6363
play_button: false,
6464
running_file: "",
6565
selected_file: "",
66+
currently_selected_file: "",
6667
};
6768

6869
this.handleClick = this.handleClick.bind(this);
@@ -72,7 +73,6 @@ class Simulator extends React.Component<{}, IState> {
7273
this.onMouseLeave = this.onMouseLeave.bind(this);
7374
this.togglePlayClick = this.togglePlayClick.bind(this);
7475
this.refreshSimulatorClick = this.refreshSimulatorClick.bind(this);
75-
this.onSelectBlur = this.onSelectBlur.bind(this);
7676
}
7777

7878
handleMessage = (event: any): void => {
@@ -98,8 +98,11 @@ class Simulator extends React.Component<{}, IState> {
9898
});
9999
break;
100100
case "activate-play":
101+
const newRunningFile = this.state.currently_selected_file;
102+
101103
this.setState({
102104
play_button: !this.state.play_button,
105+
running_file: newRunningFile,
103106
});
104107
break;
105108
case "visible-editors":
@@ -113,9 +116,16 @@ class Simulator extends React.Component<{}, IState> {
113116
break;
114117
case "current-file":
115118
console.log("Setting current file", message.state.running_file);
116-
this.setState({
117-
running_file: message.state.running_file,
118-
});
119+
if (this.state.play_button) {
120+
this.setState({
121+
currently_selected_file: message.state.running_file,
122+
});
123+
} else {
124+
this.setState({
125+
running_file: message.state.running_file,
126+
currently_selected_file: message.state.running_file,
127+
});
128+
}
119129
break;
120130
}
121131
};
@@ -136,14 +146,9 @@ class Simulator extends React.Component<{}, IState> {
136146
return (
137147
<div className="simulator">
138148
<div className="file-selector">
139-
<Dropdown
140-
label={"file-dropdown"}
141-
styleLabel={"dropdown"}
142-
lastChosen={this.state.running_file}
143-
width={300}
144-
textOptions={this.state.active_editors}
145-
onBlur={this.onSelectBlur}
146-
/>
149+
{this.state.running_file && this.state.play_button
150+
? CONSTANTS.CURRENTLY_RUNNING(this.state.running_file)
151+
: CONSTANTS.FILES_PLACEHOLDER}
147152
</div>
148153
<div className="cpx-container">
149154
<CpxImage
@@ -191,11 +196,6 @@ class Simulator extends React.Component<{}, IState> {
191196
sendMessage(WEBVIEW_MESSAGES.REFRESH_SIMULATOR, true);
192197
}
193198

194-
protected onSelectBlur(event: React.FocusEvent<HTMLSelectElement>) {
195-
this.setState({
196-
selected_file: event.currentTarget.value,
197-
});
198-
}
199199
protected onKeyEvent(event: KeyboardEvent, active: boolean) {
200200
let element;
201201
const target = event.target as SVGElement;

src/view/components/cpx/__snapshots__/Cpx.spec.tsx.snap

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,7 @@ Array [
88
<div
99
className="file-selector"
1010
>
11-
<div>
12-
<select
13-
className="dropdown"
14-
id="file-dropdown"
15-
onBlur={[Function]}
16-
>
17-
<option
18-
disabled={true}
19-
selected={true}
20-
value=""
21-
>
22-
Choose a .py file to run on the Simulator
23-
</option>
24-
</select>
25-
</div>
11+
The simulator will run the .py file you have focused on.
2612
</div>
2713
<div
2814
className="cpx-container"

src/view/components/microbit/MicrobitSimulator.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import PlayLogo from "../../svgs/play_svg";
99
import StopLogo from "../../svgs/stop_svg";
1010
import { sendMessage } from "../../utils/MessageUtils";
11-
import Dropdown from "../Dropdown";
1211
import ActionBar from "../simulator/ActionBar";
1312
import { BUTTONS_KEYS, MicrobitImage } from "./MicrobitImage";
1413

@@ -25,7 +24,8 @@ const DEFAULT_MICROBIT_STATE: IMicrobitState = {
2524

2625
interface IState {
2726
active_editors: string[];
28-
running_file: string;
27+
running_file?: string;
28+
currently_selected_file: string;
2929
play_button: boolean;
3030
selected_file: string;
3131
microbit: IMicrobitState;
@@ -44,7 +44,8 @@ export class MicrobitSimulator extends React.Component<any, IState> {
4444
play_button: false,
4545
selected_file: "",
4646
active_editors: [],
47-
running_file: "",
47+
running_file: undefined,
48+
currently_selected_file: "",
4849
};
4950
this.onKeyEvent = this.onKeyEvent.bind(this);
5051
}
@@ -71,8 +72,10 @@ export class MicrobitSimulator extends React.Component<any, IState> {
7172
});
7273
break;
7374
case "activate-play":
75+
const newRunningFile = this.state.currently_selected_file;
7476
this.setState({
7577
play_button: !this.state.play_button,
78+
running_file: newRunningFile,
7679
});
7780
break;
7881
case "visible-editors":
@@ -81,9 +84,17 @@ export class MicrobitSimulator extends React.Component<any, IState> {
8184
});
8285
break;
8386
case "current-file":
84-
this.setState({
85-
running_file: message.state.running_file,
86-
});
87+
if (this.state.play_button) {
88+
this.setState({
89+
currently_selected_file: message.state.running_file,
90+
});
91+
} else {
92+
this.setState({
93+
running_file: message.state.running_file,
94+
currently_selected_file: message.state.running_file,
95+
});
96+
}
97+
8798
break;
8899
}
89100
};
@@ -100,14 +111,9 @@ export class MicrobitSimulator extends React.Component<any, IState> {
100111
return (
101112
<div className="simulator">
102113
<div className="file-selector">
103-
<Dropdown
104-
label={"file-dropdown"}
105-
styleLabel={"dropdown"}
106-
lastChosen={this.state.running_file}
107-
width={300}
108-
textOptions={this.state.active_editors}
109-
onBlur={this.onSelectFile}
110-
/>
114+
{this.state.running_file && this.state.play_button
115+
? CONSTANTS.CURRENTLY_RUNNING(this.state.running_file)
116+
: CONSTANTS.FILES_PLACEHOLDER}
111117
</div>
112118
<div className="microbit-container">
113119
<MicrobitImage
@@ -130,6 +136,7 @@ export class MicrobitSimulator extends React.Component<any, IState> {
130136
</div>
131137
);
132138
}
139+
133140
protected togglePlayClick = () => {
134141
const button =
135142
window.document.getElementById(CONSTANTS.ID_NAME.PLAY_BUTTON) ||
@@ -142,11 +149,7 @@ export class MicrobitSimulator extends React.Component<any, IState> {
142149
state: !this.state.play_button,
143150
});
144151
};
145-
protected onSelectFile(event: React.FocusEvent<HTMLSelectElement>) {
146-
this.setState({
147-
selected_file: event.currentTarget.value,
148-
});
149-
}
152+
150153
protected refreshSimulatorClick = () => {
151154
const button = window.document.getElementById(
152155
CONSTANTS.ID_NAME.REFRESH_BUTTON

src/view/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export const CONSTANTS = {
4242
NUMERIC_SIX: "Digit6",
4343
NUMERIC_SEVEN: "Digit7",
4444
},
45-
NO_FILES_AVAILABLE: "Choose a .py file to run on the Simulator",
45+
FILES_PLACEHOLDER:
46+
"The simulator will run the .py file you have focused on.",
4647
SIMULATOR_BUTTON_WIDTH: 60,
4748
TOOLBAR_INFO: `Explore what's on the board:`,
4849
};

src/view/container/device/__snapshots__/Device.spec.tsx.snap

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,7 @@ exports[`Device component should render correctly 1`] = `
1010
<div
1111
className="file-selector"
1212
>
13-
<div>
14-
<select
15-
className="dropdown"
16-
id="file-dropdown"
17-
onBlur={[Function]}
18-
>
19-
<option
20-
disabled={true}
21-
selected={true}
22-
value=""
23-
>
24-
Choose a .py file to run on the Simulator
25-
</option>
26-
</select>
27-
</div>
13+
The simulator will run the .py file you have focused on.
2814
</div>
2915
<div
3016
className="microbit-container"

src/view/styles/Simulator.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
.file-selector {
2020
padding: 20px;
21+
width: 80%;
22+
height: 30px;
23+
border: 1px solid var(--vscode-debugToolBar-background);
24+
border-radius: 3px;
2125
}
2226

2327
.shake-pressed {
@@ -70,4 +74,5 @@
7074
}
7175
.cpx-container {
7276
width: 100%;
77+
padding-top: 10px;
7378
}

0 commit comments

Comments
 (0)