-
Notifications
You must be signed in to change notification settings - Fork 75
feat: improve multiple deletion process #1846
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
base: main
Are you sure you want to change the base?
Changes from all commits
9622e8b
ff9640f
c5faa41
6fab3de
8652e7d
d25c042
f5fd7d8
f9188c6
30ac8f0
50787d3
66e10e8
ece21e7
d844cc7
e42effc
d2ca4b2
1e3aa50
66a5d61
15be2f1
a409fa3
5698837
344e9dd
fef68db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,54 +102,114 @@ class ContentNavigator implements SubscriptionProvider { | |
| commands.registerCommand( | ||
| `${SAS}.deleteResource`, | ||
| async (item: ContentItem) => { | ||
| this.getTreeViewSelections(item).forEach( | ||
| async (resource: ContentItem) => { | ||
| if (!resource.contextValue.includes("delete")) { | ||
| return; | ||
| } | ||
| const isContainer = getIsContainer(resource); | ||
| const hasUnsavedFiles = isContainer | ||
| ? await this.contentDataProvider.checkFolderDirty(resource) | ||
| : false; | ||
| const moveToRecycleBin = | ||
| this.contentDataProvider.canRecycleResource(resource); | ||
| const selections = this.getTreeViewSelections(item); | ||
|
|
||
| if ( | ||
| !moveToRecycleBin && | ||
| !(await window.showWarningMessage( | ||
| l10n.t(Messages.DeleteWarningMessage, { | ||
| name: resource.name, | ||
| }), | ||
| { modal: true }, | ||
| Messages.DeleteButtonLabel, | ||
| )) | ||
| ) { | ||
| return; | ||
| } else if (moveToRecycleBin && hasUnsavedFiles) { | ||
| if ( | ||
| !(await window.showWarningMessage( | ||
| l10n.t(Messages.RecycleDirtyFolderWarning, { | ||
| name: resource.name, | ||
| }), | ||
| { modal: true }, | ||
| Messages.MoveToRecycleBinLabel, | ||
| )) | ||
| ) { | ||
| return; | ||
| } | ||
| } | ||
| const deleteResult = moveToRecycleBin | ||
| ? await this.contentDataProvider.recycleResource(resource) | ||
| : await this.contentDataProvider.deleteResource(resource); | ||
| if (!deleteResult) { | ||
| window.showErrorMessage( | ||
| isContainer | ||
| ? Messages.FolderDeletionError | ||
| : Messages.FileDeletionError, | ||
| ); | ||
| } | ||
| }, | ||
| const deletableItems = selections.filter((resource: ContentItem) => | ||
| resource.contextValue?.includes("delete"), | ||
| ); | ||
|
|
||
| if (deletableItems.length === 0) { | ||
| return; | ||
| } | ||
|
|
||
| // Close all open files first and handle unsaved changes | ||
| // If user cancels the save dialog, abort the deletion | ||
| if ( | ||
| !(await this.contentDataProvider.closeResourceFiles(deletableItems)) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const recyclableItems = deletableItems.filter( | ||
| (resource: ContentItem) => | ||
| this.contentDataProvider.canRecycleResource(resource), | ||
| ); | ||
| const permanentDelete = | ||
| deletableItems.length > recyclableItems.length; | ||
|
|
||
| let hasUnsavedFiles = false; | ||
| for (const resource of deletableItems) { | ||
| const isContainer = getIsContainer(resource); | ||
| if ( | ||
| isContainer && | ||
| (await this.contentDataProvider.checkFolderDirty(resource)) | ||
| ) { | ||
| hasUnsavedFiles = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| let confirmed = false; | ||
| if (deletableItems.length === 1) { | ||
| const resource = deletableItems[0]; | ||
| const isContainer = getIsContainer(resource); | ||
| const canRecycle = | ||
| this.contentDataProvider.canRecycleResource(resource); | ||
| const itemHasUnsavedFiles = isContainer | ||
| ? await this.contentDataProvider.checkFolderDirty(resource) | ||
| : false; | ||
|
Comment on lines
+148
to
+150
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this different than |
||
|
|
||
| if (!canRecycle) { | ||
| confirmed = !!(await window.showWarningMessage( | ||
| l10n.t(Messages.DeleteWarningMessage, { | ||
| name: resource.name, | ||
| }), | ||
| { modal: true }, | ||
| Messages.DeleteButtonLabel, | ||
| )); | ||
| } else if (itemHasUnsavedFiles) { | ||
| confirmed = !!(await window.showWarningMessage( | ||
| l10n.t(Messages.DirtyFolderWarning), | ||
| { modal: true }, | ||
| canRecycle | ||
| ? Messages.MoveToRecycleBinLabel | ||
| : Messages.DeleteButtonLabel, | ||
| )); | ||
| } else { | ||
| confirmed = true; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we default to |
||
| } | ||
| } else { | ||
| if (permanentDelete) { | ||
| confirmed = !!(await window.showWarningMessage( | ||
| l10n.t(Messages.DeleteMultipleWarningMessage, { | ||
| count: deletableItems.length, | ||
| }), | ||
| { modal: true }, | ||
| Messages.DeleteButtonLabel, | ||
| )); | ||
| } else if (hasUnsavedFiles) { | ||
| confirmed = !!(await window.showWarningMessage( | ||
| l10n.t(Messages.DirtyFolderWarning), | ||
| { modal: true }, | ||
| permanentDelete | ||
| ? Messages.DeleteButtonLabel | ||
| : Messages.MoveToRecycleBinLabel, | ||
| )); | ||
| } else { | ||
| confirmed = true; | ||
| } | ||
| } | ||
|
|
||
| if (!confirmed) { | ||
| return; | ||
| } | ||
|
|
||
| for (const resource of deletableItems) { | ||
| const isContainer = getIsContainer(resource); | ||
| const canRecycle = | ||
| this.contentDataProvider.canRecycleResource(resource); | ||
| const deleteResult = canRecycle | ||
| ? await this.contentDataProvider.recycleResource(resource) | ||
| : await this.contentDataProvider.deleteResource(resource); | ||
|
|
||
| if (!deleteResult) { | ||
| window.showErrorMessage( | ||
| isContainer | ||
| ? Messages.FolderDeletionError | ||
| : Messages.FileDeletionError, | ||
| ); | ||
| } | ||
| } | ||
| }, | ||
| ), | ||
| commands.registerCommand( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to understand this a bit more. From my general understanding, I would suspect
permanentDeletemeans we have something that cannot be recycled. Could this be simplified to something like...