From ceafac1362ed10329c25723e75e064839402535c Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Sun, 28 May 2023 21:46:44 +0800 Subject: [PATCH 1/2] Add confirmation dialog before deleting a topic - Replace the previous deleteTopic command with a new callback function. - Use vscode.window.showWarningMessage to display a confirmation dialog. - Execute the delete operation only if the user confirms. --- src/extension.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index ab59ccb..5580ecd 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -270,9 +270,21 @@ function activate(context: vscode.ExtensionContext) { }); context.subscriptions.push(yourTreeView); - vscode.commands.registerCommand('devchat-topicview.deleteTopic', (item: TopicTreeItem) => { - TopicManager.getInstance().deleteTopic(item.id); - }); + const topicDeleteCallback = async (item: TopicTreeItem) => { + const confirm = 'Delete'; + const cancel = 'Cancel'; + const result = await vscode.window.showWarningMessage( + `Are you sure you want to delete the topic "${item.label}"?`, + { modal: true }, + confirm, + cancel + ); + + if (result === confirm) { + TopicManager.getInstance().deleteTopic(item.id); + } + } + vscode.commands.registerCommand('devchat-topicview.deleteTopic', topicDeleteCallback); context.subscriptions.push( vscode.languages.registerCodeActionsProvider( @@ -300,7 +312,7 @@ function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand('devchat-topicview.deleteSelectedTopic', () => { const selectedItem = yourTreeDataProvider.selectedItem; if (selectedItem) { - TopicManager.getInstance().deleteTopic(selectedItem.id); + topicDeleteCallback(selectedItem); } else { vscode.window.showErrorMessage('No item selected'); } From 44f3db43b2add785219d4b374048e47f63eaf302 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Sun, 28 May 2023 22:01:32 +0800 Subject: [PATCH 2/2] Truncate topic label to 20 characters in delete confirmation dialog - Check if item.label exists and use item.label.label or 'Unknown Topic'. - Truncate the label to 20 characters and add ellipsis if needed. - Update the confirmation message to display the truncated label. --- src/extension.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 5580ecd..a4dd23f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -273,8 +273,10 @@ function activate(context: vscode.ExtensionContext) { const topicDeleteCallback = async (item: TopicTreeItem) => { const confirm = 'Delete'; const cancel = 'Cancel'; + const label = typeof item.label === 'string' ? item.label : item.label!.label; + const truncatedLabel = label.substring(0, 20) + (label.length > 20 ? '...' : ''); const result = await vscode.window.showWarningMessage( - `Are you sure you want to delete the topic "${item.label}"?`, + `Are you sure you want to delete the topic "${truncatedLabel}"?`, { modal: true }, confirm, cancel @@ -283,7 +285,7 @@ function activate(context: vscode.ExtensionContext) { if (result === confirm) { TopicManager.getInstance().deleteTopic(item.id); } - } + }; vscode.commands.registerCommand('devchat-topicview.deleteTopic', topicDeleteCallback); context.subscriptions.push(