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

Commit 1cbeed5

Browse files
committed
Add warning and link for no installed examples
1 parent b489140 commit 1cbeed5

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,18 @@ export class ExampleProvider implements vscode.TreeDataProvider<ExampleItem> {
4343
this._exmaples = null;
4444
this._exampleManager.loadExamples().then((examples) => {
4545
this._exmaples = examples;
46+
if (!this.hasAnyExamples(this._exmaples)) {
47+
// Reset the examples list to get the welcome message (defined in package.json) to appear.
48+
this._exmaples = [];
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

Lines changed: 3 additions & 0 deletions
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)