Skip to content

Commit

Permalink
fix #14638
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 12, 2018
1 parent 374daab commit d4a6d84
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -76,14 +76,25 @@ 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
},
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,
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<boolean>('files.enableTrash'), recursive: options.recursive });
}

} else if (edit.newUri && !edit.oldUri) {
Expand Down Expand Up @@ -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
) {

}
Expand Down Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtHostDocumentsShape>() {
Expand Down

0 comments on commit d4a6d84

Please sign in to comment.