Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add completely delete file option #4326

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core-browser/src/core-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ export const corePreferenceSchema: PreferenceSchema = {
default: EXPLORER_DEFAULTS.confirmMove,
description: '%preference.explorer.confirm.delete%',
},
// 'explorer.confirmCompletelyDelete': {
// type: 'boolean',
// default: EXPLORER_DEFAULTS.confirmMove,
// description: '%preference.explorer.confirm.delete%',
// },
'explorer.fileTree.baseIndent': {
type: 'number',
default: FILE_TREE_DEFAULTS.baseIndent,
Expand Down Expand Up @@ -312,6 +317,7 @@ export interface CoreConfiguration {
'workbench.refactoringChanges.showPreviewStrategy': string;
'workbench.quickOpen.preserveInput': boolean;
'explorer.confirmDelete': boolean;
// 'explorer.confirmCompletelyDelete': boolean;
'explorer.fileTree.baseIndent': number;
'explorer.fileTree.indent': number;
'explorer.autoReveal': boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,15 @@ export class FileTreeAPI implements IFileTreeAPI {
return;
}

async delete(uri: URI) {
async delete(uri: URI, completelyDelete?: boolean) {
try {
await this.workspaceEditService.apply({
edits: [
{
oldResource: uri,
options: {},
options: {
completelyDelete,
},
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,24 @@ export class FileTreeModelService {
if (uris.length === 0) {
return;
}
if (this.corePreferences['explorer.confirmDelete']) {

// 完全删除文件
if (this.corePreferences['explorer.confirmCompletelyDelete']) {
const ok = localize('file.confirm.completelyDelete.ok');
const cancel = localize('file.confirm.completelyDelete.cancel');
const deleteFilesMessage = `[ ${uris
.slice(0, 5)
.map((uri) => uri.displayName)
.join(',')}${uris.length > 5 ? ' ...' : ''} ]`;

const confirm = await this.dialogService.warning(
formatLocalize('file.confirm.completelyDelete', deleteFilesMessage),
[cancel, ok],
);
if (confirm !== ok) {
return;
}
} else if (this.corePreferences['explorer.confirmDelete']) {
const ok = localize('file.confirm.delete.ok');
const cancel = localize('file.confirm.delete.cancel');
const deleteFilesMessage = `[ ${uris
Expand Down Expand Up @@ -1025,7 +1042,7 @@ export class FileTreeModelService {
roots.forEach((root) => {
this.loadingDecoration.addTarget(root.node);
toPromise.push(
this.deleteFile(root.node, root.path).then((v) => {
this.deleteFile(root.node, root.path, !!this.corePreferences['explorer.confirmCompletelyDelete']).then((v) => {
this.loadingDecoration.removeTarget(root.node);
return v;
}),
Expand All @@ -1039,10 +1056,10 @@ export class FileTreeModelService {
}
}

async deleteFile(node: File | Directory, path: URI | string): Promise<boolean> {
async deleteFile(node: File | Directory, path: URI | string, completelyDelete?: boolean): Promise<boolean> {
const uri = typeof path === 'string' ? new URI(path) : (path as URI);

const error = await this.fileTreeAPI.delete(uri);
const error = await this.fileTreeAPI.delete(uri, completelyDelete);
if (error) {
this.messageService.error(error);
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/file-tree-next/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IFileTreeAPI {
copyFile(from: URI, to: URI): Promise<FileStat | string | void>;
createFile(newUri: URI, content?: string): Promise<string | void>;
createDirectory(newUri: URI): Promise<string | void>;
delete(uri: URI): Promise<string | void>;
delete(uri: URI, completelyDelete?: boolean): Promise<string | void>;
mvFiles(oldUri: IMoveFileMetadata[], newUri: URI): Promise<string[] | void>;
mv(oldUri: URI, newUri: URI, isDirectory?: boolean): Promise<string | void>;
resolveChildren(
Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/src/common/en-US.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export const localizationBundle = {
'file.confirm.delete': 'Are you sure you want to delete the following files?\n{0}',
'file.confirm.delete.ok': 'Move to trash',
'file.confirm.delete.cancel': 'Cancel',
'file.confirm.completelyDelete': 'Are you sure you want to completely delete the following files?\n{0}',
'file.confirm.completelyDelete.ok': 'Completely delete',
'file.confirm.completelyDelete.cancel': 'Cancel',
'file.confirm.move': 'Are you sure you want to move file {0} to {1}?',
'file.confirm.move.ok': 'Move',
'file.confirm.move.cancel': 'Cancel',
Expand Down
3 changes: 3 additions & 0 deletions packages/i18n/src/common/zh-CN.lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export const localizationBundle = {
'file.confirm.delete': '确定删除下面列的文件?\n{0}',
'file.confirm.delete.ok': '移入回收站',
'file.confirm.delete.cancel': '取消',
'file.confirm.completelyDelete': '确定彻底删除下面列的文件?\n{0}',
'file.confirm.completelyDelete.ok': '彻底删除',
'file.confirm.completelyDelete.cancel': '取消',
'file.confirm.move': '确定移动文件 {0} 到 {1} ?',
'file.confirm.move.ok': '移动',
'file.confirm.move.cancel': '取消',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class ResourceFileEdit implements IResourceFileEdit {
copy?: boolean;
ignoreIfExists?: boolean | undefined;
content?: string;
completelyDelete?: boolean | undefined;
} = {};

constructor(edit: IResourceFileEdit) {
Expand Down Expand Up @@ -297,7 +298,10 @@ export class ResourceFileEdit implements IResourceFileEdit {
try {
// Electron Windows 下 moveToTrash 大量文件会导致IDE卡死,如果检测到这个情况就不使用 moveToTrash
await workspaceFS.delete([this.oldResource], {
useTrash: !(isWindows && this.oldResource.path.name === 'node_modules'),
useTrash:
options.completelyDelete !== undefined
? !options.completelyDelete // 如果 completelyDelete 被定义,使用其相反值
: !(isWindows && this.oldResource.path.name === 'node_modules'), // 否则使用原有逻辑,
});
// 默认recursive
await editorService.close(this.oldResource, true);
Expand Down
1 change: 1 addition & 0 deletions packages/workspace-edit/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface IResourceFileEdit {
isDirectory?: boolean;
copy?: boolean;
content?: string;
completelyDelete?: boolean | undefined;
};
}

Expand Down
Loading