Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit fdd3133

Browse files
authored
Merge pull request #1594 from microsoft/dev/bemcmorr/warn-no-examples
Add warning and link for no installed examples
2 parents 75a0cc4 + ca36bc2 commit fdd3133

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ All notable changes to this project will be documented in this file.
1010
### Added
1111

1212
- [Arduino CLI](https://arduino.github.io/arduino-cli/0.30/) version 0.30.0 is now bundled with the extension [#1584](https://github.com/microsoft/vscode-arduino/pull/1584). To use the bundled version of Arduino CLI, `arduino.useArduinoCli` should be `true`, and `arduino.path` and `arduino.commandPath` should be empty or unset. Additionally, prompts will appear to switch to the bundled version whenever the legacy Arduino IDE is used or manually specified Arduino tools cannot be found.
13-
- A warning will appear in the Board Configuration view when no boards are installed. This warning links to the Board Manager view to install boards. [#1592](https://github.com/microsoft/vscode-arduino/pull/1584)
13+
- A warning will appear in the Board Configuration view when no boards are installed. This warning links to the Board Manager view to install boards. [#1592](https://github.com/microsoft/vscode-arduino/pull/1592)
14+
- A warning will appear in the Arduino Examples view when no examples are installed. [#1594](https://github.com/microsoft/vscode-arduino/pull/1594)
1415

1516
### Changed
1617

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@
182182
}
183183
]
184184
},
185+
"viewsWelcome": [
186+
{
187+
"view": "arduinoExampleExplorer",
188+
"contents": "No examples are installed. [Find additional examples online.](https://go.microsoft.com/fwlink/?linkid=2225276)"
189+
}
190+
],
185191
"debuggers": [
186192
{
187193
"type": "arduino",

src/arduino/exampleProvider.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ExampleProvider implements vscode.TreeDataProvider<ExampleItem> {
1515
// tslint:disable-next-line:member-ordering
1616
public readonly onDidChangeTreeData: vscode.Event<null> = this._onDidChangeTreeData.event;
1717

18-
private _exmaples: IExampleNode[] = null;
18+
private _examples: IExampleNode[] = null;
1919

2020
constructor(private _exampleManager: ExampleManager, private _boardManager: BoardManager) {
2121
this._boardManager.onBoardTypeChanged(() => {
@@ -28,25 +28,33 @@ export class ExampleProvider implements vscode.TreeDataProvider<ExampleItem> {
2828
}
2929

3030
public getChildren(element?: ExampleItem): ExampleItem[] {
31-
if (!this._exmaples) {
31+
if (!this._examples) {
3232
this.loadData();
3333
return null;
3434
}
3535
if (!element) {
36-
return this.createExampleItemList(this._exmaples);
36+
return this.createExampleItemList(this._examples);
3737
} else {
3838
return this.createExampleItemList(element.getChildren());
3939
}
4040
}
4141

4242
private loadData() {
43-
this._exmaples = null;
43+
this._examples = null;
4444
this._exampleManager.loadExamples().then((examples) => {
45-
this._exmaples = examples;
45+
this._examples = examples;
46+
if (!this.hasAnyExamples(this._examples)) {
47+
// Reset the examples list to get the welcome message (defined in package.json) to appear.
48+
this._examples = [];
49+
}
4650
this._onDidChangeTreeData.fire(null);
4751
});
4852
}
4953

54+
private hasAnyExamples(nodes?: IExampleNode[]): boolean {
55+
return nodes && (nodes.find((node) => node.isLeaf || this.hasAnyExamples(node.children)) !== undefined);
56+
}
57+
5058
private createExampleItemList(examples: IExampleNode[]): ExampleItem[] {
5159
const result = [];
5260
if (examples && examples.length) {

src/views/app/components/ExampleTreeView.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { connect } from "react-redux";
77
import * as actions from "../actions";
88
import * as API from "../actions/api";
99

10+
// TODO: I'm pretty sure this entire view is unused and can be removed.
11+
// See exampleProvider.ts which instead uses the built-in VS Code Tree View API.
12+
1013
interface IExampleViewProps extends React.Props<any> {
1114
examples: any[];
1215
loadExamples: () => void;

0 commit comments

Comments
 (0)