Add additional batch action confirmations

This commit is contained in:
Richard Willis 2020-06-03 08:34:51 +01:00
Родитель 93810ba6dc
Коммит 1f059b667a
5 изменённых файлов: 64 добавлений и 38 удалений

Просмотреть файл

@ -32,7 +32,7 @@ This extension contributes the following settings:
- `gradle.focusTaskInExplorer`: Focus the task in the explorer when running a task
- `gradle.javaDebug`: Debug JavaExec tasks (see below for usage)
- `gradle.debug`: Show extra debug info in the output panel
- `gradle.ignoreDaemonStopWarning`: Ignore the warning message when stopping the Gradle daemon/s
- `gradle.disableConfirmations`: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc)
To provide better compatibility with the [Java language support extension](https://github.com/redhat-developer/vscode-java), this extension supports the following settings:

Просмотреть файл

@ -564,11 +564,11 @@
"scope": "window",
"description": "Show extra debug information in the output panel"
},
"gradle.ignoreDaemonStopWarning": {
"gradle.disableConfirmations": {
"type": "boolean",
"default": false,
"scope": "window",
"description": "Ignore the warning message when stopping the Gradle daemon/s"
"description": "Disable the warning confirm messages when performing batch actions"
},
"gradle.focusTaskInExplorer": {
"type": "boolean",

Просмотреть файл

@ -11,13 +11,12 @@ import {
import { logger } from '../logger';
import { invalidateTasksCache, GradleTaskDefinition } from '../tasks';
import { Extension } from '../extension';
import { getIgnoreDaemonStopWarning } from '../config';
import { StopDaemonsReply } from '../proto/gradle_pb';
import {
isJavaLanguageSupportExtensionActivated,
JAVA_CONFIGURATION_UPDATE_COMMAND,
} from '../compat';
import { getTaskArgs } from '../input';
import { getTaskArgs, confirmModal } from '../input';
import {
COMMAND_SHOW_TASKS,
COMMAND_RUN_TASK,
@ -192,26 +191,14 @@ function registerRefreshDaemonStatusCommand(): vscode.Disposable {
);
}
async function cancelStopDaemons(): Promise<boolean | undefined> {
const ignoreWarning = getIgnoreDaemonStopWarning();
if (!ignoreWarning) {
const DAEMON_STOP_OPTION_CONFIRM = 'Yes';
const result = await vscode.window.showWarningMessage(
'Are you sure you want to stop the daemon/s?',
{ modal: true },
DAEMON_STOP_OPTION_CONFIRM
);
if (result !== DAEMON_STOP_OPTION_CONFIRM) {
return true;
}
}
}
function registerStopDaemons(): vscode.Disposable {
return vscode.commands.registerCommand(
COMMAND_STOP_DAEMONS,
async (): Promise<void> => {
if (!vscode.workspace.workspaceFolders || (await cancelStopDaemons())) {
if (
!vscode.workspace.workspaceFolders ||
!(await confirmModal('Are you sure you want to stop the daemons?'))
) {
return;
}
try {
@ -236,7 +223,7 @@ function registerStopDaemon(): vscode.Disposable {
return vscode.commands.registerCommand(
COMMAND_STOP_DAEMON,
async (treeItem: GradleDaemonTreeItem): Promise<void> => {
if (await cancelStopDaemons()) {
if (!(await confirmModal('Are you sure you want to stop the daemon?'))) {
return;
}
const pid = treeItem.pid;
@ -427,29 +414,54 @@ function registerCloseTaskTerminalsCommand(): vscode.Disposable {
function registerCloseAllTaskTerminalsCommand(): vscode.Disposable {
return vscode.commands.registerCommand(
COMMAND_CLOSE_ALL_TASK_TERMINALS,
() => {
async () => {
const taskTerminalsStore = Extension.getInstance().getTaskTerminalsStore();
Array.from(taskTerminalsStore.getData().keys()).forEach((key) => {
const terminalsSet = taskTerminalsStore.getItem(key);
if (terminalsSet) {
Array.from(terminalsSet).forEach((terminal) => terminal.dispose());
}
});
taskTerminalsStore.clear();
if (
taskTerminalsStore.getData().size &&
(await confirmModal(
'Are you sure you want to close all task terminals?'
))
) {
Array.from(taskTerminalsStore.getData().keys()).forEach((key) => {
const terminalsSet = taskTerminalsStore.getItem(key);
if (terminalsSet) {
Array.from(terminalsSet).forEach((terminal) => terminal.dispose());
}
});
taskTerminalsStore.clear();
}
}
);
}
function registerClearAllRecentTasksCommand(): vscode.Disposable {
return vscode.commands.registerCommand(COMMAND_CLEAR_ALL_RECENT_TASKS, () => {
Extension.getInstance().getRecentTasksStore().clear();
});
return vscode.commands.registerCommand(
COMMAND_CLEAR_ALL_RECENT_TASKS,
async () => {
const recentTasksStore = Extension.getInstance().getRecentTasksStore();
if (
recentTasksStore.getData().size &&
(await confirmModal('Are you sure you want to clear the recent tasks?'))
) {
recentTasksStore.clear();
}
}
);
}
function registerClearAllPinnedTasksCommand(): vscode.Disposable {
return vscode.commands.registerCommand(COMMAND_CLEAR_ALL_PINNED_TASKS, () => {
Extension.getInstance().getPinnedTasksStore().clear();
});
return vscode.commands.registerCommand(
COMMAND_CLEAR_ALL_PINNED_TASKS,
async () => {
const pinnedTasksStore = Extension.getInstance().getPinnedTasksStore();
if (
pinnedTasksStore.getData().size &&
(await confirmModal('Are you sure you want to clear the pinned tasks?'))
) {
pinnedTasksStore.clear();
}
}
);
}
function registerRemoveRecentTaskCommand(): vscode.Disposable {

Просмотреть файл

@ -49,10 +49,10 @@ export function getConfigIsDebugEnabled(): boolean {
.get<boolean>('debug', false);
}
export function getIgnoreDaemonStopWarning(): boolean {
export function getDisableConfirmations(): boolean {
return vscode.workspace
.getConfiguration('gradle')
.get<boolean>('ignoreDaemonStopWarning', false);
.get<boolean>('disableConfirmations', false);
}
export function getConfigFocusTaskInExplorer(): boolean {

Просмотреть файл

@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { TaskArgs } from '../stores/types';
import { getDisableConfirmations } from '../config';
export function getTaskArgs(): Thenable<TaskArgs | undefined> {
return vscode.window
@ -13,3 +14,16 @@ export function getTaskArgs(): Thenable<TaskArgs | undefined> {
}
});
}
export async function confirmModal(message: string): Promise<boolean> {
if (getDisableConfirmations()) {
return true;
}
const CONFIRM = 'Yes';
const result = await vscode.window.showWarningMessage(
message,
{ modal: true },
CONFIRM
);
return result === CONFIRM;
}