Skip to content

Commit

Permalink
Ability to remove file permanently (bypass trash) (fixes #9354)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 19, 2016
1 parent f7d57d6 commit ec85ff4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/vs/platform/contextview/browser/contextView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,18 @@ export interface IContextMenuService {
showContextMenu(delegate: IContextMenuDelegate): void;
}

export interface IEvent {
shiftKey?: boolean;
ctrlKey?: boolean;
altKey?: boolean;
metaKey?: boolean;
}

export interface IContextMenuDelegate {
getAnchor(): HTMLElement | { x: number; y: number; };
getActions(): TPromise<(IAction | ContextSubMenu)[]>;
getActionItem?(action: IAction): IActionItem;
getActionsContext?(): any;
getActionsContext?(event?: IEvent): any;
getKeyBinding?(action: IAction): Keybinding;
getMenuClassName?(): string;
onHide?(didCancel: boolean): void;
Expand Down
3 changes: 1 addition & 2 deletions src/vs/platform/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ export interface IFilesConfiguration {
autoSave: string;
autoSaveDelay: number;
eol: string;
iconTheme: string;
};
}

Expand Down Expand Up @@ -708,4 +707,4 @@ export const SUPPORTED_ENCODINGS: { [encoding: string]: { labelLong: string; lab
labelShort: 'GB 2312',
order: 45
}
};
};
10 changes: 9 additions & 1 deletion src/vs/workbench/parts/files/browser/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,21 @@ export class BaseDeleteFileAction extends BaseFileAction {
this._updateEnablement();
}

public run(): TPromise<any> {
public run(context?: any): TPromise<any> {

// Remove highlight
if (this.tree) {
this.tree.clearHighlight();
}

// Read context
if (context && context.event) {
const bypassTrash = (isMacintosh && context.event.altKey) || (!isMacintosh && context.event.shiftKey);
if (bypassTrash) {
this.useTrash = false;
}
}

let primaryButton: string;
if (this.useTrash) {
primaryButton = isWindows ? nls.localize('deleteButtonLabelRecycleBin', "&&Move to Recycle Bin") : nls.localize({ key: 'deleteButtonLabelTrash', comment: ['&& denotes a mnemonic'] }, "&&Move to Trash");
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/parts/files/browser/views/explorerViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,11 @@ export class FileController extends DefaultController {
},
getActionItem: this.state.actionProvider.getActionItem.bind(this.state.actionProvider, tree, stat),
getKeyBinding: (a): Keybinding => keybindingForAction(a.id),
getActionsContext: () => {
getActionsContext: (event) => {
return {
viewletState: this.state,
stat: stat
stat,
event
};
},
onHide: (wasCancelled?: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import severity from 'vs/base/common/severity';
import {IAction} from 'vs/base/common/actions';
import {Separator} from 'vs/base/browser/ui/actionbar/actionbar';
import dom = require('vs/base/browser/dom');
import {IContextMenuService, IContextMenuDelegate, ContextSubMenu} from 'vs/platform/contextview/browser/contextView';
import {IContextMenuService, IContextMenuDelegate, ContextSubMenu, IEvent} from 'vs/platform/contextview/browser/contextView';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IMessageService} from 'vs/platform/message/common/message';
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
Expand Down Expand Up @@ -84,8 +84,8 @@ export class ContextMenuService implements IContextMenuService {
checked: !!e.checked,
accelerator,
enabled: !!e.enabled,
click: () => {
this.runAction(e, delegate);
click: (menuItem, win, event) => {
this.runAction(e, delegate, event);
}
});

Expand All @@ -96,10 +96,10 @@ export class ContextMenuService implements IContextMenuService {
return menu;
}

private runAction(actionToRun: IAction, delegate: IContextMenuDelegate): void {
private runAction(actionToRun: IAction, delegate: IContextMenuDelegate, event: IEvent): void {
this.telemetryService.publicLog('workbenchActionExecuted', { id: actionToRun.id, from: 'contextMenu' });

const context = delegate.getActionsContext ? delegate.getActionsContext() : null;
const context = delegate.getActionsContext ? delegate.getActionsContext(event) : event;
const res = actionToRun.run(context) || TPromise.as(null);

res.done(null, e => this.messageService.show(severity.Error, e));
Expand Down

0 comments on commit ec85ff4

Please sign in to comment.