From 66fac74eda27bbd0d9fa9f4692ecec303a28872a Mon Sep 17 00:00:00 2001 From: Gordon Date: Thu, 27 May 2021 22:25:27 +0100 Subject: [PATCH] Add archive command --- CHANGELOG.md | 1 + README.md | 3 ++- ext-src/extension.ts | 48 +++++++++++++++++++++++++++++++++++++++++++- package.json | 9 +++++++-- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea0e32f..61e8d51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 0.10.0 * Added task archive, tasks can now be sent to the archive folder and restored from the archive folder +* Added commands to archive and restore multiple tasks * Fixed debounced updates on burndown chart # 0.9.3 diff --git a/README.md b/README.md index 10e4d8f..31cf971 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,8 @@ The following commands are available: - `Kanbn: Open board` will open open the Kanbn board. - `Kanbn: Open burndown chart` will open a burndown chart. - `Kanbn: Add task` will open the task editor. -- `Kanbn: Restore task` will restore tasks from the archive. +- `Kanbn: Archive tasks` will send tasks to the archive. +- `Kanbn: Restore tasks` will restore tasks from the archive. ## Configuration settings diff --git a/ext-src/extension.ts b/ext-src/extension.ts index 1421b32..5ea9858 100644 --- a/ext-src/extension.ts +++ b/ext-src/extension.ts @@ -136,9 +136,55 @@ export async function activate(context: vscode.ExtensionContext) { }) ); + // Register a command to archive tasks. + context.subscriptions.push( + vscode.commands.registerCommand("kanbn.archiveTasks", async () => { + // If no workspace folder is opened, we can't archive tasks + if (vscode.workspace.workspaceFolders === undefined) { + vscode.window.showErrorMessage("You need to open a workspace before sending tasks to the archive."); + return; + } + + // Set the node process directory and import kanbn + process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath); + const kanbn = await import("@basementuniverse/kanbn/src/main"); + + // Get a list of tracked tasks + let tasks: string[] = []; + try { + tasks = [...(await kanbn.findTrackedTasks())]; + } catch (e) {} + if (tasks.length === 0) { + vscode.window.showInformationMessage("There are no tasks to archive."); + return; + } + + // Prompt for a selection of tasks to archive + const archiveTaskIds = await vscode.window.showQuickPick( + tasks, + { + placeHolder: 'Select tasks to archive...', + canPickMany: true, + } + ); + if (archiveTaskIds !== undefined && archiveTaskIds.length > 0) { + for (let archiveTaskId of archiveTaskIds) { + await kanbn.archiveTask(archiveTaskId); + } + KanbnBoardPanel.update(); + kanbnStatusBarItem.update(); + if (vscode.workspace.getConfiguration("kanbn").get("showTaskNotifications")) { + vscode.window.showInformationMessage( + `Archived ${archiveTaskIds.length} task${archiveTaskIds.length === 1 ? '' : 's'}.` + ); + } + } + }) + ); + // Register a command to restore a task from the archive. context.subscriptions.push( - vscode.commands.registerCommand("kanbn.restoreTask", async () => { + vscode.commands.registerCommand("kanbn.restoreTasks", async () => { // If no workspace folder is opened, we can't restore tasks from the archive if (vscode.workspace.workspaceFolders === undefined) { vscode.window.showErrorMessage("You need to open a workspace before restoring tasks from the archive."); diff --git a/package.json b/package.json index 1994e0a..1ba62f3 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,13 @@ "category": "Kanbn" }, { - "command": "kanbn.restoreTask", - "title": "Restore task", + "command": "kanbn.archiveTasks", + "title": "Archive tasks", + "category": "Kanbn" + }, + { + "command": "kanbn.restoreTasks", + "title": "Restore tasks", "category": "Kanbn" } ],