From 1cbeed59db1469c2484b1c4d8c82dd2a413c7500 Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Thu, 16 Feb 2023 11:01:00 -0800 Subject: [PATCH 1/2] Add warning and link for no installed examples --- CHANGELOG.md | 3 ++- package.json | 6 ++++++ src/arduino/exampleProvider.ts | 8 ++++++++ src/views/app/components/ExampleTreeView.tsx | 3 +++ 4 files changed, 19 insertions(+), 1 deletion(-) 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..01b393e2 100644 --- a/src/arduino/exampleProvider.ts +++ b/src/arduino/exampleProvider.ts @@ -43,10 +43,18 @@ export class ExampleProvider implements vscode.TreeDataProvider { this._exmaples = null; this._exampleManager.loadExamples().then((examples) => { this._exmaples = examples; + if (!this.hasAnyExamples(this._exmaples)) { + // Reset the examples list to get the welcome message (defined in package.json) to appear. + this._exmaples = []; + } 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; From 49b0377e234902be1b3eb540dbf0c82be168c334 Mon Sep 17 00:00:00 2001 From: Ben McMorran Date: Thu, 16 Feb 2023 11:10:11 -0800 Subject: [PATCH 2/2] Fix typo --- src/arduino/exampleProvider.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/arduino/exampleProvider.ts b/src/arduino/exampleProvider.ts index 01b393e2..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,24 +28,24 @@ 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; - if (!this.hasAnyExamples(this._exmaples)) { + this._examples = examples; + if (!this.hasAnyExamples(this._examples)) { // Reset the examples list to get the welcome message (defined in package.json) to appear. - this._exmaples = []; + this._examples = []; } this._onDidChangeTreeData.fire(null); });