Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.1k
fix: distinguish between Move to Trash and Delete Immediately when right clicking a file or folder.#1694
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
thecoolwinter merged 2 commits intoCodeEditApp:mainfromplbstl:fix/distinguish-between-trash-and-delete-file-folderMay 1, 2024
Uh oh!
There was an error while loading.Please reload this page.
Merged
fix: distinguish between Move to Trash and Delete Immediately when right clicking a file or folder.#1694
Changes from1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
NextNext commit
fix: distinguish between Move to Trash and Delete Immediately when ri…
…ght clicking a file or folder
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
commite8549bdccccce9d5fd7f0b4e675f90d5331e28d6
There are no files selected for viewing
62 changes: 53 additions & 9 deletionsCodeEdit/Features/CEWorkspace/Models/CEWorkspaceFileManager+FileManagement.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -88,29 +88,73 @@ extension CEWorkspaceFileManager { | ||
| ) | ||
| } | ||
| /// This function deletes the item or folder from the current project by moving to Trash | ||
| /// - Parameters: | ||
| /// - file: The file or folder to delete | ||
| /// - Authors: Paul Ebose | ||
| public func trash(file: CEWorkspaceFile) { | ||
| let message: String | ||
| if !file.isFolder || file.isEmptyFolder { // if its a file or an empty folder, call it by its name | ||
| message = file.name | ||
| } else { | ||
| let fileCount = fileManager.enumerator(atPath: file.url.path)?.allObjects.count | ||
| message = "the \((fileCount ?? 0) + 1) selected items" | ||
| } | ||
| let moveFileToTrashAlert = NSAlert() | ||
| moveFileToTrashAlert.messageText = "Do you want to move \(message) to Trash?" | ||
| moveFileToTrashAlert.informativeText = "This operation cannot be undone." | ||
| moveFileToTrashAlert.alertStyle = .critical | ||
| moveFileToTrashAlert.addButton(withTitle: "Move to Trash") | ||
| moveFileToTrashAlert.buttons.last?.hasDestructiveAction = true | ||
| moveFileToTrashAlert.addButton(withTitle: "Cancel") | ||
| if moveFileToTrashAlert.runModal() == .alertFirstButtonReturn { // "Move to Trash" button | ||
| if fileManager.fileExists(atPath: file.url.path) { | ||
| do { | ||
| try fileManager.trashItem(at: file.url, resultingItemURL: nil) | ||
| } catch { | ||
| fatalError(error.localizedDescription) | ||
austincondiff marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| } | ||
| } | ||
| } | ||
| /// This function deletes the item or folder from the current project by erasing immediately. | ||
| /// - Parameters: | ||
| /// - file: The file to delete | ||
| /// - confirmDelete: True to present an alert to confirm the delete. | ||
| /// - Authors: Mattijs Eikelenboom, KaiTheRedNinja., Paul Ebose *Moved from 7c27b1e* | ||
| public func delete(file: CEWorkspaceFile, confirmDelete: Bool = true) { | ||
| // This function also has to account for how the | ||
| // - file system can change outside of the editor | ||
| let messageText: String | ||
| let informativeText: String | ||
| if !file.isFolder || file.isEmptyFolder { // if its a file or an empty folder, call it by its name | ||
| messageText = "Are you sure you want to delete \"\(file.name)\"?" | ||
| informativeText = "This item will be deleted immediately. You can't undo this action." | ||
| } else { | ||
| let childrenCount = try? fileManager.contentsOfDirectory( | ||
| at: file.url, | ||
| includingPropertiesForKeys: nil | ||
| ).count | ||
| if let childrenCount { | ||
| messageText = "Are you sure you want to delete the \((childrenCount) + 1) selected items?" | ||
| informativeText = "\(childrenCount) items will be deleted immediately. You can't undo this action." | ||
| } else { | ||
| messageText = "Are you sure you want to delete the selected items?" | ||
| informativeText = "Selected items will be deleted immediately. You can't undo this action." | ||
| } | ||
| } | ||
| let deleteConfirmation = NSAlert() | ||
| deleteConfirmation.messageText = messageText | ||
| deleteConfirmation.informativeText = informativeText | ||
| deleteConfirmation.alertStyle = .critical | ||
| deleteConfirmation.addButton(withTitle: "Delete") | ||
| deleteConfirmation.buttons.last?.hasDestructiveAction = true | ||
| deleteConfirmation.addButton(withTitle: "Cancel") | ||
| if !confirmDelete || deleteConfirmation.runModal() == .alertFirstButtonReturn { // "Delete" button | ||
20 changes: 18 additions & 2 deletionsCodeEdit/Features/NavigatorArea/ProjectNavigator/OutlineView/ProjectNavigatorMenu.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.