Skip to content

Commit cfc5dbc

Browse files
authored
delete warning message uses enumerator instead of shallow search (#1699)
1 parent 4b848fd commit cfc5dbc

File tree

1 file changed

+8
-46
lines changed

1 file changed

+8
-46
lines changed

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFileManager+FileManagement.swift

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,11 @@ extension CEWorkspaceFileManager {
9393
/// - file: The file or folder to delete
9494
/// - Authors: Paul Ebose
9595
public func trash(file: CEWorkspaceFile) {
96-
let message: String
97-
98-
if !file.isFolder || file.isEmptyFolder { // if its a file or an empty folder, call it by its name
99-
message = file.name
100-
} else {
101-
let fileCount = fileManager.enumerator(atPath: file.url.path)?.allObjects.count
102-
message = "the \((fileCount ?? 0) + 1) selected items"
103-
}
104-
105-
let moveFileToTrashAlert = NSAlert()
106-
moveFileToTrashAlert.messageText = "Do you want to move \(message) to Trash?"
107-
moveFileToTrashAlert.informativeText = "This operation cannot be undone."
108-
moveFileToTrashAlert.alertStyle = .critical
109-
moveFileToTrashAlert.addButton(withTitle: "Move to Trash")
110-
moveFileToTrashAlert.buttons.last?.hasDestructiveAction = true
111-
moveFileToTrashAlert.addButton(withTitle: "Cancel")
112-
113-
if moveFileToTrashAlert.runModal() == .alertFirstButtonReturn { // "Move to Trash" button
114-
if fileManager.fileExists(atPath: file.url.path) {
115-
do {
116-
try fileManager.trashItem(at: file.url, resultingItemURL: nil)
117-
} catch {
118-
print(error.localizedDescription)
119-
}
96+
if fileManager.fileExists(atPath: file.url.path) {
97+
do {
98+
try fileManager.trashItem(at: file.url, resultingItemURL: nil)
99+
} catch {
100+
print(error.localizedDescription)
120101
}
121102
}
122103
}
@@ -129,30 +110,11 @@ extension CEWorkspaceFileManager {
129110
public func delete(file: CEWorkspaceFile, confirmDelete: Bool = true) {
130111
// This function also has to account for how the
131112
// - file system can change outside of the editor
132-
let messageText: String
133-
let informativeText: String
134-
135-
if !file.isFolder || file.isEmptyFolder { // if its a file or an empty folder, call it by its name
136-
messageText = "Are you sure you want to delete \"\(file.name)\"?"
137-
informativeText = "This item will be deleted immediately. You can't undo this action."
138-
} else {
139-
let childrenCount = try? fileManager.contentsOfDirectory(
140-
at: file.url,
141-
includingPropertiesForKeys: nil
142-
).count
143-
144-
if let childrenCount {
145-
messageText = "Are you sure you want to delete the \((childrenCount) + 1) selected items?"
146-
informativeText = "\(childrenCount) items will be deleted immediately. You can't undo this action."
147-
} else {
148-
messageText = "Are you sure you want to delete the selected items?"
149-
informativeText = "Selected items will be deleted immediately. You can't undo this action."
150-
}
151-
}
113+
let fileName = file.name
152114

153115
let deleteConfirmation = NSAlert()
154-
deleteConfirmation.messageText = messageText
155-
deleteConfirmation.informativeText = informativeText
116+
deleteConfirmation.messageText = "Do you want to delete “\(fileName)”?"
117+
deleteConfirmation.informativeText = "This item will be deleted immediately. You can't undo this action."
156118
deleteConfirmation.alertStyle = .critical
157119
deleteConfirmation.addButton(withTitle: "Delete")
158120
deleteConfirmation.buttons.last?.hasDestructiveAction = true

0 commit comments

Comments
 (0)