From d4a6d8440f3d1d7ddca5905fb571a8d7ea208835 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Wed, 12 Sep 2018 11:28:12 +0200 Subject: [PATCH] fix #14638 --- .../fileActions.contribution.ts | 28 +++++++++++++++++-- .../electron-browser/files.contribution.ts | 5 ++++ .../electron-browser/bulkEditService.ts | 11 +++++--- .../api/mainThreadEditors.test.ts | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts b/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts index 7ef4b66b1ec..0f09493169d 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileActions.contribution.ts @@ -64,7 +64,7 @@ const MOVE_FILE_TO_TRASH_ID = 'moveFileToTrash'; KeybindingsRegistry.registerCommandAndKeybindingRule({ id: MOVE_FILE_TO_TRASH_ID, weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus, - when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext), + when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext, ContextKeyExpr.has('config.files.enableTrash')), primary: KeyCode.Delete, mac: { primary: KeyMod.CtrlCmd | KeyCode.Backspace @@ -76,7 +76,7 @@ const DELETE_FILE_ID = 'deleteFile'; KeybindingsRegistry.registerCommandAndKeybindingRule({ id: DELETE_FILE_ID, weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus, - when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext), + when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext, ContextKeyExpr.has('config.files.enableTrash')), primary: KeyMod.Shift | KeyCode.Delete, mac: { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.Backspace @@ -84,6 +84,17 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ handler: deleteFileHandler }); +KeybindingsRegistry.registerCommandAndKeybindingRule({ + id: DELETE_FILE_ID, + weight: KeybindingWeight.WorkbenchContrib + explorerCommandsWeightBonus, + when: ContextKeyExpr.and(FilesExplorerFocusCondition, ExplorerRootContext.toNegated(), ExplorerResourceNotReadonlyContext, ContextKeyExpr.not('config.files.enableTrash')), + primary: KeyCode.Delete, + mac: { + primary: KeyMod.CtrlCmd | KeyCode.Backspace + }, + handler: deleteFileHandler +}); + const COPY_FILE_ID = 'filesExplorer.copy'; KeybindingsRegistry.registerCommandAndKeybindingRule({ id: COPY_FILE_ID, @@ -474,7 +485,18 @@ MenuRegistry.appendMenuItem(MenuId.ExplorerContext, { title: nls.localize('deleteFile', "Delete Permanently"), precondition: ExplorerResourceNotReadonlyContext }, - when: ExplorerRootContext.toNegated() + when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ContextKeyExpr.has('config.files.enableTrash')) +}); + +MenuRegistry.appendMenuItem(MenuId.ExplorerContext, { + group: '7_modification', + order: 20, + command: { + id: DELETE_FILE_ID, + title: nls.localize('deleteFile', "Delete Permanently"), + precondition: ExplorerResourceNotReadonlyContext + }, + when: ContextKeyExpr.and(ExplorerRootContext.toNegated(), ContextKeyExpr.not('config.files.enableTrash')) }); // Empty Editor Group Context Menu diff --git a/src/vs/workbench/parts/files/electron-browser/files.contribution.ts b/src/vs/workbench/parts/files/electron-browser/files.contribution.ts index 10ba8288bb7..fc3c262ef51 100644 --- a/src/vs/workbench/parts/files/electron-browser/files.contribution.ts +++ b/src/vs/workbench/parts/files/electron-browser/files.contribution.ts @@ -248,6 +248,11 @@ configurationRegistry.registerConfiguration({ 'description': nls.localize('eol', "The default end of line character."), 'scope': ConfigurationScope.RESOURCE }, + 'files.enableTrash': { + 'type': 'boolean', + 'default': true, + 'description': nls.localize('useTrash', "Moves files/folders to the OS trash (recycle bin on Windows) when deleting. Disabling this will delete files/folders permanently.") + }, 'files.trimTrailingWhitespace': { 'type': 'boolean', 'default': false, diff --git a/src/vs/workbench/services/bulkEdit/electron-browser/bulkEditService.ts b/src/vs/workbench/services/bulkEdit/electron-browser/bulkEditService.ts index d9382085f1b..987e90f5742 100644 --- a/src/vs/workbench/services/bulkEdit/electron-browser/bulkEditService.ts +++ b/src/vs/workbench/services/bulkEdit/electron-browser/bulkEditService.ts @@ -25,6 +25,7 @@ import { emptyProgressRunner, IProgress, IProgressRunner } from 'vs/platform/pro import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { ILabelService } from 'vs/platform/label/common/label'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; abstract class Recording { @@ -233,7 +234,8 @@ export class BulkEdit { @ITextModelService private readonly _textModelService: ITextModelService, @IFileService private readonly _fileService: IFileService, @ITextFileService private readonly _textFileService: ITextFileService, - @ILabelService private readonly _uriLabelServie: ILabelService + @ILabelService private readonly _uriLabelServie: ILabelService, + @IConfigurationService private readonly _configurationService: IConfigurationService ) { this._editor = editor; this._progress = progress || emptyProgressRunner; @@ -316,7 +318,7 @@ export class BulkEdit { } else if (!edit.newUri && edit.oldUri) { // delete file if (!options.ignoreIfNotExists || await this._fileService.existsFile(edit.oldUri)) { - await this._textFileService.delete(edit.oldUri, { useTrash: true, recursive: options.recursive }); + await this._textFileService.delete(edit.oldUri, { useTrash: this._configurationService.getValue('files.enableTrash'), recursive: options.recursive }); } } else if (edit.newUri && !edit.oldUri) { @@ -369,7 +371,8 @@ export class BulkEditService implements IBulkEditService { @ITextModelService private readonly _textModelService: ITextModelService, @IFileService private readonly _fileService: IFileService, @ITextFileService private readonly _textFileService: ITextFileService, - @ILabelService private readonly _labelService: ILabelService + @ILabelService private readonly _labelService: ILabelService, + @IConfigurationService private readonly _configurationService: IConfigurationService ) { } @@ -400,7 +403,7 @@ export class BulkEditService implements IBulkEditService { } } - const bulkEdit = new BulkEdit(options.editor, options.progress, this._logService, this._textModelService, this._fileService, this._textFileService, this._labelService); + const bulkEdit = new BulkEdit(options.editor, options.progress, this._logService, this._textModelService, this._fileService, this._textFileService, this._labelService, this._configurationService); bulkEdit.add(edits); return TPromise.wrap(bulkEdit.perform().then(() => { diff --git a/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts b/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts index 060ed7d2a53..36b9046aed8 100644 --- a/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts +++ b/src/vs/workbench/test/electron-browser/api/mainThreadEditors.test.ts @@ -84,7 +84,7 @@ suite('MainThreadEditors', () => { } }; - const bulkEditService = new BulkEditService(new NullLogService(), modelService, new TestEditorService(), textModelService, new TestFileService(), textFileService, new LabelService(TestEnvironmentService, new TestContextService())); + const bulkEditService = new BulkEditService(new NullLogService(), modelService, new TestEditorService(), textModelService, new TestFileService(), textFileService, new LabelService(TestEnvironmentService, new TestContextService()), configService); const rpcProtocol = new TestRPCProtocol(); rpcProtocol.set(ExtHostContext.ExtHostDocuments, new class extends mock() { -- GitLab