From e3745a527d27d08bb569d7c8f1348bc4dee8cbce Mon Sep 17 00:00:00 2001 From: Jonathan Carter Date: Fri, 13 Mar 2020 12:08:10 -0700 Subject: [PATCH] Adding more tree commands --- CHANGELOG.md | 2 +- package.json | 35 ++++++++++++++++++++++++++++++----- src/commands.ts | 22 ++++++++++++++++------ src/tree/index.ts | 6 +++++- 4 files changed, 52 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93a134b..c0152de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## v0.0.6 (03/13/2020) - Added the `Code Tour: End Tour` command to the command palette -- Added the `Change Title`, `Change Description` and `Delete Tour` commands to the `Code Tours` tree view to enable easily managing existing tours +- Added the `'Resume Tour`, `End Tour`, `Change Title`, `Change Description` and `Delete Tour` commands to the `Code Tours` tree view to enable easily managing existing tours ## v0.0.5 (03/09/2020) diff --git a/package.json b/package.json index ae81398..1f2341a 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,7 @@ }, { "command": "codetour.resumeTour", - "title": "Resume Current Tour", + "title": "Resume Tour", "category": "Code Tour" }, { @@ -236,18 +236,43 @@ "group": "inline@3" }, { - "command": "codetour.changeTourTitle", + "command": "codetour.saveTour", + "when": "viewItem =~ /codetour.tour.recording/", + "group": "active@1" + }, + { + "command": "codetour.resumeTour", + "when": "viewItem =~ /codetour.tour(.recording)?.active/", + "group": "active@2" + }, + { + "command": "codetour.endTour", + "when": "viewItem =~ /codetour.tour(.recording)?.active/", + "group": "active@3" + }, + { + "command": "codetour.startTour", "when": "viewItem == codetour.tour", "group": "basic@1" }, + { + "command": "codetour.changeTourTitle", + "when": "viewItem =~ /^codetour.tour/", + "group": "change@1" + }, { "command": "codetour.changeTourDescription", - "when": "viewItem == codetour.tour", - "group": "basic@2" + "when": "viewItem =~ /^codetour.tour/", + "group": "change@2" }, { "command": "codetour.deleteTour", - "when": "viewItem == codetour.tour", + "when": "viewItem =~ /^codetour.tour/", + "group": "delete@1" + }, + { + "command": "codetour.deleteTourStep", + "when": "viewItem == codetour.tour.step", "group": "manage@1" } ] diff --git a/src/commands.ts b/src/commands.ts index 754ef48..3edaf05 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -205,10 +205,14 @@ export function registerCommands() { // @ts-ignore tour[property] = propertyValue; - const uri = vscode.Uri.parse(tour.id); - delete tour.id; - const tourContent = JSON.stringify(tour, null, 2); - vscode.workspace.fs.writeFile(uri, new Buffer(tourContent)); + // We don't need to persist the tour change + // if it doesn't have an id (e.g. is pending being saved) + if (tour.id) { + const uri = vscode.Uri.parse(tour.id); + delete tour.id; + const tourContent = JSON.stringify(tour, null, 2); + vscode.workspace.fs.writeFile(uri, new Buffer(tourContent)); + } } vscode.commands.registerCommand( @@ -224,8 +228,14 @@ export function registerCommands() { vscode.commands.registerCommand( `${EXTENSION_NAME}.deleteTour`, async (node: CodeTourNode) => { - const uri = vscode.Uri.parse(node.tour.id); - vscode.workspace.fs.delete(uri); + if (store.currentTour && node.tour.title === store.currentTour.title) { + await endCurrentCodeTour(); + } + + if (node.tour.id) { + const uri = vscode.Uri.parse(node.tour.id); + vscode.workspace.fs.delete(uri); + } } ); diff --git a/src/tree/index.ts b/src/tree/index.ts index b6b853f..4d1c967 100644 --- a/src/tree/index.ts +++ b/src/tree/index.ts @@ -25,7 +25,11 @@ class CodeTourTreeProvider implements TreeDataProvider, Disposable { store.subTours, store.isRecording, store.currentTour - ? store.currentTour.steps.map(step => step.description) + ? [ + store.currentTour.title, + store.currentTour.description, + store.currentTour.steps.map(step => step.description) + ] : null ], () => {