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

Add warning and link for no installed examples #1594

Merged
merged 4 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 13 additions & 5 deletions src/arduino/exampleProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ExampleProvider implements vscode.TreeDataProvider<ExampleItem> {
// tslint:disable-next-line:member-ordering
public readonly onDidChangeTreeData: vscode.Event<null> = this._onDidChangeTreeData.event;

private _exmaples: IExampleNode[] = null;
private _examples: IExampleNode[] = null;

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

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) {
Expand Down
3 changes: 3 additions & 0 deletions src/views/app/components/ExampleTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
examples: any[];
loadExamples: () => void;
Expand Down