Skip to content

Commit f3a78d3

Browse files
committed
Move dialog details to description row in custom dialog
fixes microsoft#85057
1 parent 5db448e commit f3a78d3

File tree

4 files changed

+59
-28
lines changed

4 files changed

+59
-28
lines changed

src/vs/platform/dialogs/common/dialogs.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,8 @@ export const enum ConfirmResult {
257257
}
258258

259259
const MAX_CONFIRM_FILES = 10;
260-
export function getConfirmMessage(start: string, fileNamesOrResources: readonly (string | URI)[]): string {
261-
const message = [start];
262-
message.push('');
260+
export function getFileNamesMessage(fileNamesOrResources: readonly (string | URI)[]): string {
261+
const message: string[] = [];
263262
message.push(...fileNamesOrResources.slice(0, MAX_CONFIRM_FILES).map(fileNameOrResource => typeof fileNameOrResource === 'string' ? fileNameOrResource : basename(fileNameOrResource)));
264263

265264
if (fileNamesOrResources.length > MAX_CONFIRM_FILES) {

src/vs/workbench/contrib/files/browser/fileActions.ts

+43-17
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { IModelService } from 'vs/editor/common/services/modelService';
3333
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
3434
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
3535
import { Schemas } from 'vs/base/common/network';
36-
import { IDialogService, IConfirmationResult, getConfirmMessage, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
36+
import { IDialogService, IConfirmationResult, getFileNamesMessage, IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
3737
import { INotificationService, Severity } from 'vs/platform/notification/common/notification';
3838
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3939
import { Constants } from 'vs/base/common/uint';
@@ -199,11 +199,17 @@ async function deleteFiles(textFileService: ITextFileService, dialogService: IDi
199199

200200
// Confirm for moving to trash
201201
else if (useTrash) {
202-
const message = getMoveToTrashMessage(distinctElements);
202+
let { message, detail } = getMoveToTrashMessage(distinctElements);
203+
detail += detail ? '\n' : '';
204+
if (isWindows) {
205+
detail += nls.localize('undoBin', "You can restore from the Recycle Bin.");
206+
} else {
207+
detail += nls.localize('undoTrash', "You can restore from the Trash.");
208+
}
203209

204210
confirmDeletePromise = dialogService.confirm({
205211
message,
206-
detail: isWindows ? nls.localize('undoBin', "You can restore from the Recycle Bin.") : nls.localize('undoTrash', "You can restore from the Trash."),
212+
detail,
207213
primaryButton,
208214
checkbox: {
209215
label: nls.localize('doNotAskAgain', "Do not ask me again")
@@ -214,10 +220,12 @@ async function deleteFiles(textFileService: ITextFileService, dialogService: IDi
214220

215221
// Confirm for deleting permanently
216222
else {
217-
const message = getDeleteMessage(distinctElements);
223+
let { message, detail } = getDeleteMessage(distinctElements);
224+
detail += detail ? '\n' : '';
225+
detail += nls.localize('irreversible', "This action is irreversible!");
218226
confirmDeletePromise = dialogService.confirm({
219227
message,
220-
detail: nls.localize('irreversible', "This action is irreversible!"),
228+
detail,
221229
primaryButton,
222230
type: 'warning'
223231
});
@@ -280,44 +288,62 @@ async function deleteFiles(textFileService: ITextFileService, dialogService: IDi
280288
});
281289
}
282290

283-
function getMoveToTrashMessage(distinctElements: ExplorerItem[]): string {
291+
function getMoveToTrashMessage(distinctElements: ExplorerItem[]): { message: string, detail: string } {
284292
if (containsBothDirectoryAndFile(distinctElements)) {
285-
return getConfirmMessage(nls.localize('confirmMoveTrashMessageFilesAndDirectories', "Are you sure you want to delete the following {0} files/directories and their contents?", distinctElements.length), distinctElements.map(e => e.resource));
293+
return {
294+
message: nls.localize('confirmMoveTrashMessageFilesAndDirectories', "Are you sure you want to delete the following {0} files/directories and their contents?", distinctElements.length),
295+
detail: getFileNamesMessage(distinctElements.map(e => e.resource))
296+
};
286297
}
287298

288299
if (distinctElements.length > 1) {
289300
if (distinctElements[0].isDirectory) {
290-
return getConfirmMessage(nls.localize('confirmMoveTrashMessageMultipleDirectories', "Are you sure you want to delete the following {0} directories and their contents?", distinctElements.length), distinctElements.map(e => e.resource));
301+
return {
302+
message: nls.localize('confirmMoveTrashMessageMultipleDirectories', "Are you sure you want to delete the following {0} directories and their contents?", distinctElements.length),
303+
detail: getFileNamesMessage(distinctElements.map(e => e.resource))
304+
};
291305
}
292306

293-
return getConfirmMessage(nls.localize('confirmMoveTrashMessageMultiple', "Are you sure you want to delete the following {0} files?", distinctElements.length), distinctElements.map(e => e.resource));
307+
return {
308+
message: nls.localize('confirmMoveTrashMessageMultiple', "Are you sure you want to delete the following {0} files?", distinctElements.length),
309+
detail: getFileNamesMessage(distinctElements.map(e => e.resource))
310+
};
294311
}
295312

296313
if (distinctElements[0].isDirectory) {
297-
return nls.localize('confirmMoveTrashMessageFolder', "Are you sure you want to delete '{0}' and its contents?", distinctElements[0].name);
314+
return { message: nls.localize('confirmMoveTrashMessageFolder', "Are you sure you want to delete '{0}' and its contents?", distinctElements[0].name), detail: '' };
298315
}
299316

300-
return nls.localize('confirmMoveTrashMessageFile', "Are you sure you want to delete '{0}'?", distinctElements[0].name);
317+
return { message: nls.localize('confirmMoveTrashMessageFile', "Are you sure you want to delete '{0}'?", distinctElements[0].name), detail: '' };
301318
}
302319

303-
function getDeleteMessage(distinctElements: ExplorerItem[]): string {
320+
function getDeleteMessage(distinctElements: ExplorerItem[]): { message: string, detail: string } {
304321
if (containsBothDirectoryAndFile(distinctElements)) {
305-
return getConfirmMessage(nls.localize('confirmDeleteMessageFilesAndDirectories', "Are you sure you want to permanently delete the following {0} files/directories and their contents?", distinctElements.length), distinctElements.map(e => e.resource));
322+
return {
323+
message: nls.localize('confirmDeleteMessageFilesAndDirectories', "Are you sure you want to permanently delete the following {0} files/directories and their contents?", distinctElements.length),
324+
detail: getFileNamesMessage(distinctElements.map(e => e.resource))
325+
};
306326
}
307327

308328
if (distinctElements.length > 1) {
309329
if (distinctElements[0].isDirectory) {
310-
return getConfirmMessage(nls.localize('confirmDeleteMessageMultipleDirectories', "Are you sure you want to permanently delete the following {0} directories and their contents?", distinctElements.length), distinctElements.map(e => e.resource));
330+
return {
331+
message: nls.localize('confirmDeleteMessageMultipleDirectories', "Are you sure you want to permanently delete the following {0} directories and their contents?", distinctElements.length),
332+
detail: getFileNamesMessage(distinctElements.map(e => e.resource))
333+
};
311334
}
312335

313-
return getConfirmMessage(nls.localize('confirmDeleteMessageMultiple', "Are you sure you want to permanently delete the following {0} files?", distinctElements.length), distinctElements.map(e => e.resource));
336+
return {
337+
message: nls.localize('confirmDeleteMessageMultiple', "Are you sure you want to permanently delete the following {0} files?", distinctElements.length),
338+
detail: getFileNamesMessage(distinctElements.map(e => e.resource))
339+
};
314340
}
315341

316342
if (distinctElements[0].isDirectory) {
317-
return nls.localize('confirmDeleteMessageFolder', "Are you sure you want to permanently delete '{0}' and its contents?", distinctElements[0].name);
343+
return { message: nls.localize('confirmDeleteMessageFolder', "Are you sure you want to permanently delete '{0}' and its contents?", distinctElements[0].name), detail: '' };
318344
}
319345

320-
return nls.localize('confirmDeleteMessageFile', "Are you sure you want to permanently delete '{0}'?", distinctElements[0].name);
346+
return { message: nls.localize('confirmDeleteMessageFile', "Are you sure you want to permanently delete '{0}'?", distinctElements[0].name), detail: '' };
321347
}
322348

323349
function containsBothDirectoryAndFile(distinctElements: ExplorerItem[]): boolean {

src/vs/workbench/contrib/files/browser/views/explorerViewer.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { IDragAndDropData, DataTransfers } from 'vs/base/browser/dnd';
3636
import { Schemas } from 'vs/base/common/network';
3737
import { DesktopDragAndDropData, ExternalElementsDragAndDropData, ElementsDragAndDropData } from 'vs/base/browser/ui/list/listView';
3838
import { isMacintosh, isWeb } from 'vs/base/common/platform';
39-
import { IDialogService, IConfirmation, getConfirmMessage } from 'vs/platform/dialogs/common/dialogs';
39+
import { IDialogService, IConfirmation, getFileNamesMessage } from 'vs/platform/dialogs/common/dialogs';
4040
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
4141
import { IHostService } from 'vs/workbench/services/host/browser/host';
4242
import { IWorkspaceEditingService } from 'vs/workbench/services/workspaces/common/workspaceEditing';
@@ -971,11 +971,15 @@ export class FileDragAndDrop implements ITreeDragAndDrop<ExplorerItem> {
971971
// Handle confirm setting
972972
const confirmDragAndDrop = !isCopy && this.configurationService.getValue<boolean>(FileDragAndDrop.CONFIRM_DND_SETTING_KEY);
973973
if (confirmDragAndDrop) {
974+
const message = items.length > 1 && items.every(s => s.isRoot) ? localize('confirmRootsMove', "Are you sure you want to change the order of multiple root folders in your workspace?")
975+
: items.length > 1 ? localize('confirmMultiMove', "Are you sure you want to move the following {0} files into '{1}'?", items.length, target.name)
976+
: items[0].isRoot ? localize('confirmRootMove', "Are you sure you want to change the order of root folder '{0}' in your workspace?", items[0].name)
977+
: localize('confirmMove', "Are you sure you want to move '{0}' into '{1}'?", items[0].name, target.name);
978+
const detail = items.length > 1 && !items.every(s => s.isRoot) ? getFileNamesMessage(items.map(i => i.resource)) : undefined;
979+
974980
const confirmation = await this.dialogService.confirm({
975-
message: items.length > 1 && items.every(s => s.isRoot) ? localize('confirmRootsMove', "Are you sure you want to change the order of multiple root folders in your workspace?")
976-
: items.length > 1 ? getConfirmMessage(localize('confirmMultiMove', "Are you sure you want to move the following {0} files into '{1}'?", items.length, target.name), items.map(s => s.resource))
977-
: items[0].isRoot ? localize('confirmRootMove', "Are you sure you want to change the order of root folder '{0}' in your workspace?", items[0].name)
978-
: localize('confirmMove', "Are you sure you want to move '{0}' into '{1}'?", items[0].name, target.name),
981+
message,
982+
detail,
979983
checkbox: {
980984
label: localize('doNotAskAgain', "Do not ask me again")
981985
},

src/vs/workbench/services/dialogs/browser/abstractFileDialogService.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as nls from 'vs/nls';
77
import { IWindowOpenable } from 'vs/platform/windows/common/windows';
8-
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, FileFilter, IFileDialogService, IDialogService, ConfirmResult, getConfirmMessage } from 'vs/platform/dialogs/common/dialogs';
8+
import { IPickAndOpenOptions, ISaveDialogOptions, IOpenDialogOptions, FileFilter, IFileDialogService, IDialogService, ConfirmResult, getFileNamesMessage } from 'vs/platform/dialogs/common/dialogs';
99
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
1010
import { IHistoryService } from 'vs/workbench/services/history/common/history';
1111
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
@@ -90,10 +90,12 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
9090
}
9191

9292
let message: string;
93+
let detail = nls.localize('saveChangesDetail', "Your changes will be lost if you don't save them.");
9394
if (fileNamesOrResources.length === 1) {
9495
message = nls.localize('saveChangesMessage', "Do you want to save the changes you made to {0}?", typeof fileNamesOrResources[0] === 'string' ? fileNamesOrResources[0] : resources.basename(fileNamesOrResources[0]));
9596
} else {
96-
message = getConfirmMessage(nls.localize('saveChangesMessages', "Do you want to save the changes to the following {0} files?", fileNamesOrResources.length), fileNamesOrResources);
97+
message = nls.localize('saveChangesMessages', "Do you want to save the changes to the following {0} files?", fileNamesOrResources.length);
98+
detail = getFileNamesMessage(fileNamesOrResources) + '\n' + detail;
9799
}
98100

99101
const buttons: string[] = [
@@ -104,7 +106,7 @@ export abstract class AbstractFileDialogService implements IFileDialogService {
104106

105107
const { choice } = await this.dialogService.show(Severity.Warning, message, buttons, {
106108
cancelId: 2,
107-
detail: nls.localize('saveChangesDetail', "Your changes will be lost if you don't save them.")
109+
detail
108110
});
109111

110112
switch (choice) {

0 commit comments

Comments
 (0)