Skip to content

Commit

Permalink
explorer: adopt confirmBeforeUndo
Browse files Browse the repository at this point in the history
fixes #112706
  • Loading branch information
isidorn committed Jan 18, 2021
1 parent 74f272f commit d427dea
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/vs/editor/browser/services/bulkEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export interface IBulkEditOptions {
quotableLabel?: string;
undoRedoSource?: UndoRedoSource;
undoRedoGroupId?: number;
confirmBeforeUndo?: boolean;
}

export interface IBulkEditResult {
Expand Down
10 changes: 6 additions & 4 deletions src/vs/workbench/contrib/bulkEdit/browser/bulkEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BulkEdit {
private readonly _edits: ResourceEdit[],
private readonly _undoRedoGroup: UndoRedoGroup,
private readonly _undoRedoSource: UndoRedoSource | undefined,
private readonly _confirmBeforeUndo: boolean,
@IInstantiationService private readonly _instaService: IInstantiationService,
@ILogService private readonly _logService: ILogService,
) {
Expand Down Expand Up @@ -76,7 +77,7 @@ class BulkEdit {
}
const group = this._edits.slice(index, index + range);
if (group[0] instanceof ResourceFileEdit) {
await this._performFileEdits(<ResourceFileEdit[]>group, this._undoRedoGroup, this._undoRedoSource, progress);
await this._performFileEdits(<ResourceFileEdit[]>group, this._undoRedoGroup, this._undoRedoSource, this._confirmBeforeUndo, progress);
} else if (group[0] instanceof ResourceTextEdit) {
await this._performTextEdits(<ResourceTextEdit[]>group, this._undoRedoGroup, this._undoRedoSource, progress);
} else if (group[0] instanceof ResourceNotebookCellEdit) {
Expand All @@ -88,9 +89,9 @@ class BulkEdit {
}
}

private async _performFileEdits(edits: ResourceFileEdit[], undoRedoGroup: UndoRedoGroup, undoRedoSource: UndoRedoSource | undefined, progress: IProgress<void>) {
private async _performFileEdits(edits: ResourceFileEdit[], undoRedoGroup: UndoRedoGroup, undoRedoSource: UndoRedoSource | undefined, confirmBeforeUndo: boolean, progress: IProgress<void>) {
this._logService.debug('_performFileEdits', JSON.stringify(edits));
const model = this._instaService.createInstance(BulkFileEdits, this._label || localize('workspaceEdit', "Workspace Edit"), undoRedoGroup, undoRedoSource, progress, this._token, edits);
const model = this._instaService.createInstance(BulkFileEdits, this._label || localize('workspaceEdit', "Workspace Edit"), undoRedoGroup, undoRedoSource, confirmBeforeUndo, progress, this._token, edits);
await model.apply();
}

Expand Down Expand Up @@ -183,7 +184,8 @@ export class BulkEditService implements IBulkEditService {
options?.token ?? CancellationToken.None,
edits,
undoRedoGroup,
options?.undoRedoSource
options?.undoRedoSource,
!!options?.confirmBeforeUndo
);

try {
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/contrib/bulkEdit/browser/bulkFileEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ class FileUndoRedoElement implements IWorkspaceUndoRedoElement {

constructor(
readonly label: string,
readonly operations: IFileOperation[]
readonly operations: IFileOperation[],
readonly confirmBeforeUndo: boolean
) {
this.resources = (<URI[]>[]).concat(...operations.map(op => op.uris));
}
Expand Down Expand Up @@ -318,6 +319,7 @@ export class BulkFileEdits {
private readonly _label: string,
private readonly _undoRedoGroup: UndoRedoGroup,
private readonly _undoRedoSource: UndoRedoSource | undefined,
private readonly _confirmBeforeUndo: boolean,
private readonly _progress: IProgress<void>,
private readonly _token: CancellationToken,
private readonly _edits: ResourceFileEdit[],
Expand Down Expand Up @@ -388,6 +390,6 @@ export class BulkFileEdits {
this._progress.report(undefined);
}

this._undoRedoService.pushElement(new FileUndoRedoElement(this._label, undoOperations), this._undoRedoGroup, this._undoRedoSource);
this._undoRedoService.pushElement(new FileUndoRedoElement(this._label, undoOperations, this._confirmBeforeUndo), this._undoRedoGroup, this._undoRedoSource);
}
}
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/files/browser/explorerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class ExplorerService implements IExplorerService {
return this.view.getContext(respectMultiSelection);
}

async applyBulkEdit(edit: ResourceFileEdit[], options: { undoLabel: string, progressLabel: string }): Promise<void> {
async applyBulkEdit(edit: ResourceFileEdit[], options: { undoLabel: string, progressLabel: string, confirmBeforeUndo?: boolean }): Promise<void> {
const cancellationTokenSource = new CancellationTokenSource();
const promise = this.progressService.withProgress({
location: ProgressLocation.Window,
Expand All @@ -152,7 +152,8 @@ export class ExplorerService implements IExplorerService {
undoRedoSource: UNDO_REDO_SOURCE,
label: options.undoLabel,
progress,
token: cancellationTokenSource.token
token: cancellationTokenSource.token,
confirmBeforeUndo: options.confirmBeforeUndo
});
}, () => cancellationTokenSource.cancel());
await this.progressService.withProgress({ location: ProgressLocation.Explorer, delay: 500 }, () => promise);
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/files/browser/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,8 @@ async function openExplorerAndCreate(accessor: ServicesAccessor, isFolder: boole
const resourceToCreate = resources.joinPath(folder.resource, value);
await explorerService.applyBulkEdit([new ResourceFileEdit(undefined, resourceToCreate, { folder: isFolder })], {
undoLabel: nls.localize('createBulkEdit', "Create {0}", value),
progressLabel: nls.localize('creatingBulkEdit', "Creating {0}", value)
progressLabel: nls.localize('creatingBulkEdit', "Creating {0}", value),
confirmBeforeUndo: true
});
await refreshIfSeparator(value, explorerService);

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/files/browser/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface IExplorerService {
refresh(): Promise<void>;
setToCopy(stats: ExplorerItem[], cut: boolean): Promise<void>;
isCut(stat: ExplorerItem): boolean;
applyBulkEdit(edit: ResourceFileEdit[], options: { undoLabel: string, progressLabel: string }): Promise<void>;
applyBulkEdit(edit: ResourceFileEdit[], options: { undoLabel: string, progressLabel: string, confirmBeforeUndo?: boolean }): Promise<void>;

/**
* Selects and reveal the file element provided by the given resource if its found in the explorer.
Expand Down

0 comments on commit d427dea

Please sign in to comment.