diff --git a/CHANGELOG.md b/CHANGELOG.md index f9ab9392..e1693bda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ All notable changes to this project will be documented in this file. ### Added - [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. -- 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) +- 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) +- A warning will appear in the Arduino Examples view when no examples are installed. [#1594](https://github.com/microsoft/vscode-arduino/pull/1594) ### Changed diff --git a/package.json b/package.json index 4730c55f..0d133c46 100644 --- a/package.json +++ b/package.json @@ -182,6 +182,12 @@ } ] }, + "viewsWelcome": [ + { + "view": "arduinoExampleExplorer", + "contents": "No examples are installed. [Find additional examples online.](https://go.microsoft.com/fwlink/?linkid=2225276)" + } + ], "debuggers": [ { "type": "arduino", diff --git a/src/arduino/exampleProvider.ts b/src/arduino/exampleProvider.ts index 9c4b0cdc..61abc677 100644 --- a/src/arduino/exampleProvider.ts +++ b/src/arduino/exampleProvider.ts @@ -15,7 +15,7 @@ export class ExampleProvider implements vscode.TreeDataProvider { // tslint:disable-next-line:member-ordering public readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; - private _exmaples: IExampleNode[] = null; + private _examples: IExampleNode[] = null; constructor(private _exampleManager: ExampleManager, private _boardManager: BoardManager) { this._boardManager.onBoardTypeChanged(() => { @@ -28,25 +28,33 @@ export class ExampleProvider implements vscode.TreeDataProvider { } public getChildren(element?: ExampleItem): ExampleItem[] { - if (!this._exmaples) { + if (!this._examples) { this.loadData(); return null; } if (!element) { - return this.createExampleItemList(this._exmaples); + return this.createExampleItemList(this._examples); } else { return this.createExampleItemList(element.getChildren()); } } private loadData() { - this._exmaples = null; + this._examples = null; this._exampleManager.loadExamples().then((examples) => { - this._exmaples = examples; + this._examples = examples; + if (!this.hasAnyExamples(this._examples)) { + // Reset the examples list to get the welcome message (defined in package.json) to appear. + this._examples = []; + } this._onDidChangeTreeData.fire(null); }); } + private hasAnyExamples(nodes?: IExampleNode[]): boolean { + return nodes && (nodes.find((node) => node.isLeaf || this.hasAnyExamples(node.children)) !== undefined); + } + private createExampleItemList(examples: IExampleNode[]): ExampleItem[] { const result = []; if (examples && examples.length) { diff --git a/src/views/app/components/ExampleTreeView.tsx b/src/views/app/components/ExampleTreeView.tsx index 27daac18..e34976fb 100644 --- a/src/views/app/components/ExampleTreeView.tsx +++ b/src/views/app/components/ExampleTreeView.tsx @@ -7,6 +7,9 @@ import { connect } from "react-redux"; import * as actions from "../actions"; import * as API from "../actions/api"; +// TODO: I'm pretty sure this entire view is unused and can be removed. +// See exampleProvider.ts which instead uses the built-in VS Code Tree View API. + interface IExampleViewProps extends React.Props { examples: any[]; loadExamples: () => void;