From b00f0d27083d189d72da7afefc5646d3240ad5ef Mon Sep 17 00:00:00 2001 From: Nguyen Ngoc Long <43560378+nguyenngoclongdev@users.noreply.github.com> Date: Fri, 4 Oct 2024 03:40:30 +0000 Subject: [PATCH] fix: add 'clear-all' command --- .changeset/happy-shirts-drive.md | 5 +++++ package.json | 25 ++++++++++++++++++++++--- src/commands/clearAllAsync.ts | 30 ++++++++++++++++++++++++++++++ src/extension.ts | 10 +++++++++- src/utils/constants.ts | 8 ++++++-- 5 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 .changeset/happy-shirts-drive.md create mode 100644 src/commands/clearAllAsync.ts diff --git a/.changeset/happy-shirts-drive.md b/.changeset/happy-shirts-drive.md new file mode 100644 index 0000000..d3df12d --- /dev/null +++ b/.changeset/happy-shirts-drive.md @@ -0,0 +1,5 @@ +--- +"terminal-keeper": patch +--- + +fix: add clear all command diff --git a/package.json b/package.json index 3a19dee..d1fa89f 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,11 @@ "category": "Terminal Keeper", "title": "Generate Configuration" }, + { + "command": "terminal-keeper.clear-all", + "category": "Terminal Keeper", + "title": "Clear All" + }, { "command": "terminal-keeper.kill-all", "category": "Terminal Keeper", @@ -156,6 +161,10 @@ { "command": "terminal-keeper.copy-command-activity", "title": "Copy" + }, + { + "command": "terminal-keeper.help-and-feedback-activity", + "title": "Help & Feedback" } ], "menus": { @@ -181,19 +190,29 @@ "group": "activity@1" }, { - "command": "terminal-keeper.kill-all", + "command": "terminal-keeper.clear-all", "when": "view == terminalKeeperActivityView", "group": "activity@2" }, + { + "command": "terminal-keeper.kill-all", + "when": "view == terminalKeeperActivityView", + "group": "activity@3" + }, { "command": "terminal-keeper.save", "when": "view == terminalKeeperActivityView", - "group": "tk@1" + "group": "tk1@1" }, { "command": "terminal-keeper.remove", "when": "view == terminalKeeperActivityView", - "group": "tk@2" + "group": "tk1@2" + }, + { + "command": "terminal-keeper.help-and-feedback-activity", + "when": "view == terminalKeeperActivityView", + "group": "tk2@1" } ], "view/item/context": [ diff --git a/src/commands/clearAllAsync.ts b/src/commands/clearAllAsync.ts new file mode 100644 index 0000000..d7c612c --- /dev/null +++ b/src/commands/clearAllAsync.ts @@ -0,0 +1,30 @@ +import { commands, ProgressLocation, window } from 'vscode'; +import { constants } from '../utils/constants'; +import { showErrorMessageWithDetail } from '../utils/utils'; + +export const clearAllAsync = async (): Promise => { + try { + window.withProgress( + { + location: ProgressLocation.Window, + title: 'Terminal Keeper', + cancellable: false + }, + async (progress) => { + // If not keep existing terminals, to dispose all + progress.report({ message: 'Clear all terminals...' }); + + // Clear all existing terminal in parallel + window.terminals.forEach(async (terminal) => { + terminal.show(); + await commands.executeCommand('workbench.action.terminal.clear', terminal); + }); + + // Return a value when the task completes + return 'Clear all of the terminal completed!'; + } + ); + } catch (error) { + showErrorMessageWithDetail(constants.clearTerminalFailed, error); + } +}; diff --git a/src/extension.ts b/src/extension.ts index 88d9889..c394325 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,6 +2,7 @@ import { ExtensionContext, Uri, commands, env, window } from 'vscode'; import { activeAsync } from './commands/activeAsync'; import { activeBySessionAsync } from './commands/activeBySessionAsync'; import { activeByTerminalAsync } from './commands/activeByTerminalAsync'; +import { clearAllAsync } from './commands/clearAllAsync'; import { generateAsync } from './commands/generateAsync'; import { killAllAsync } from './commands/killAllAsync'; import { migrateAsync } from './commands/migrateAsync'; @@ -11,7 +12,7 @@ import { saveAsync } from './commands/saveAsync'; import { Configuration } from './configuration/configuration'; import { configFileVersions } from './configuration/interface'; import { TKTreeItem, TreeProvider } from './explorer/tree-provider'; -import { extCommands } from './utils/constants'; +import { constants, extCommands } from './utils/constants'; export async function activate(context: ExtensionContext) { // Init configuration @@ -45,6 +46,10 @@ export async function activate(context: ExtensionContext) { commands.registerCommand(extCommands.migrate, async (...args: any[]) => { await migrateAsync(); }), + // Clear all terminals + commands.registerCommand(extCommands.clearAll, async (...args: any[]) => { + await clearAllAsync(); + }), // Kill all terminals commands.registerCommand(extCommands.killAll, async (...args: any[]) => { await killAllAsync(); @@ -64,6 +69,9 @@ export async function activate(context: ExtensionContext) { commands.registerCommand(extCommands.collapseAllActivity, async () => { await commands.executeCommand(`workbench.actions.treeView.${activityId}.collapseAll`); }), + commands.registerCommand(extCommands.helpAndFeedbackActivity, async () => { + await env.openExternal(Uri.parse(constants.helpAndFeedbackUrl)); + }), commands.registerCommand(extCommands.sendToNewTerminalActivity, async (sessionTreeItem: TKTreeItem) => { const { sessionId, terminalArrayIndex, label, contextValue } = sessionTreeItem; if (contextValue === 'terminal-array-context') { diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 37c14ca..12dd57e 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -5,13 +5,15 @@ export const extCommands = { save: 'terminal-keeper.save', remove: 'terminal-keeper.remove', migrate: 'terminal-keeper.migrate', + clearAll: 'terminal-keeper.clear-all', killAll: 'terminal-keeper.kill-all', refresh: 'terminal-keeper.refresh-activity', activeSessionActivity: 'terminal-keeper.active-session-activity', sendToNewTerminalActivity: 'terminal-keeper.send-to-new-terminal-activity', - sendToCurrentTerminalActivity:'terminal-keeper.send-to-current-terminal-activity', + sendToCurrentTerminalActivity: 'terminal-keeper.send-to-current-terminal-activity', copyCommandActivity: 'terminal-keeper.copy-command-activity', - collapseAllActivity: 'terminal-keeper.collapse-all-activity' + collapseAllActivity: 'terminal-keeper.collapse-all-activity', + helpAndFeedbackActivity: 'terminal-keeper.help-and-feedback-activity' }; export const sysCommands = { @@ -23,6 +25,7 @@ export const sysCommands = { export const constants = { // Common defaultSession: 'default', + helpAndFeedbackUrl: 'https://github.com/nguyenngoclongdev/vs-terminal-keeper/issues', // Open the configuration file openConfigurationFailed: 'Failed to open the configuration file!', @@ -40,6 +43,7 @@ export const constants = { activeSessionFailed: 'Failed to activate the session.', activeTerminalFailed: 'Failed to activate the terminal.', killTerminalFailed: 'Failed to kill the terminals.', + clearTerminalFailed: 'Failed to clear the terminals.', workingDirNotExist: 'The terminal "{terminal}" cannot find the current working directory "{cwd}".', // Valid configuration file