Skip to content

Conversation

knotbin
Copy link
Contributor

@knotbin knotbin commented May 1, 2024

Description

The delete function shows a warning before deleting files with the amount of files being deleted. It initially used fileManager.contentsOfDirectory() which only performs a shallow search and ignores files nested into folders it finds, producing an incorrect count of files. My change uses enumerator instead to get a deeper search of files and produce a correct file count in the warning.

Related Issues

Checklist

  • I read and understood the contributing guide as well as the code of conduct
  • The issues this PR addresses are related to each other
  • My changes generate no new warnings
  • My code builds and runs on my machine
  • My changes are all related to the related issue above
  • I documented my code

Screenshots

@thecoolwinter
Copy link
Collaborator

How well does this perform if the folder contains many files, like a node_modules folder? I'd be willing to sacrifice exact file count for speed if a case like that is slow.

@knotbin
Copy link
Contributor Author

knotbin commented May 1, 2024

How well does this perform if the folder contains many files, like a node_modules folder? I'd be willing to sacrifice exact file count for speed if a case like that is slow.

the wait time is basically non existant, and I think accuracy is very valuable, in this case a user would have thought they were only deleting 20 files when they were actually deleting thousands.

Screen.20Recording.202024-05-01.20at.206.mp4

@knotbin
Copy link
Contributor Author

knotbin commented May 2, 2024

@thecoolwinter does this look good to you?

@thecoolwinter
Copy link
Collaborator

Screen.Recording.2024-05-03.at.10.54.52.AM.mov

I'm thinking about this type of case, where there's many many nested directories. I do see your point about accuracy, but to keep the UI from ever beach-balling it should have an upper limit. Could we make this slightly more complicated and add a time limit to the enumerator? Something like:

let enumerator = fileManager.enumerator(atPath: file.url.path)
let start = CACurrentMediaTime()
var childrenCount = 0
var timedOut = false

// max out at half a second of loading, a little lag but (hopefully) rare.
while enumerator?.nextObject() != nil {
    childrenCount += 1

    if CACurrentMediaTime() - start > 0.5 {
        timedOut = true
        break
    }
}

if timedOut {
    messageText = "Failed to count items in time, this may be a large directory. Are you sure you want to delete the selected items?"
...

I have no idea if that compiles but you get what I mean.

@knotbin
Copy link
Contributor Author

knotbin commented May 3, 2024

That sounds like a good limit to me, I just made that change.

@tom-ludwig tom-ludwig marked this pull request as draft May 4, 2024 15:15
@tom-ludwig tom-ludwig marked this pull request as ready for review May 4, 2024 15:44
@tom-ludwig
Copy link
Member

Is it really important for developers to know how many files are deleted?

@knotbin
Copy link
Contributor Author

knotbin commented May 4, 2024

I believe when someone deletes things, they should be informed what is being deleted so they don't accidentally delete more than they intended, especially in the "Delete Permanently" option. we already count and show the amount of files, we might as well do it accurately.

@austincondiff
Copy link
Collaborator

austincondiff commented May 4, 2024

I agree with @activcoding, The name of the folder being deleted is much more important than the count. Finder shows the following alert when deleting immediately...

image

Then it opens a small window which tells you the items remaining. We could do this in the activity viewer when it is finished. @armartinez is working on that now.

@knotbin
Copy link
Contributor Author

knotbin commented May 4, 2024

so should I change it to not say the item count and just the file name?

@austincondiff
Copy link
Collaborator

I see that Xcode has this alert.
image
...which has the count. I wonder if the count is included here because in Xcode you can just remove references.
For the record VS Code and Nova does not display the count.
@thecoolwinter, @activcoding, @knotbin What do y'all think?

@thecoolwinter
Copy link
Collaborator

thecoolwinter commented May 4, 2024

@austincondiff theres also a chance it's using spotlight metadata to get that count but yeah could be because it's using Xcodes logical representation rather than the file system

@knotbin
Copy link
Contributor Author

knotbin commented May 4, 2024

I think if we want to be as close to Xcode UI as possible, we should display the count.

@tom-ludwig
Copy link
Member

I think the best warning message would be: “Are you sure you want to delete “Folder” with all of its subdirectories?”

@knotbin
Copy link
Contributor Author

knotbin commented May 4, 2024

@austincondiff what do you think?

thecoolwinter
thecoolwinter previously approved these changes May 4, 2024
Copy link
Collaborator

@thecoolwinter thecoolwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me

@thecoolwinter
Copy link
Collaborator

thecoolwinter commented May 4, 2024

I think the best warning message would be: “Are you sure you want to delete “Folder” with all of its subdirectories?”

That's more descriptive, but having a big number display might make a user think twice before accidentally deleting an important directory. I agree with @knotbin's point that more accuracy for file count helps avoid errors.

@austincondiff
Copy link
Collaborator

@thecoolwinter while I agree that we need something descriptive, it doesn't necessarily need to recursively get the number all children. Can you imagine if a child was a node_modules folder? In this case, some arbitrary number isn't going to provide much information.

As a user, I might expect to see a message indicating what is about to be deleted. Currently, we only indicate a number. In my opinion, a number is not as good of an identifier as a name is.

Now, if a user selects multiple items, then it will only count the top-level items and use this in place of the name.

image

@knotbin
Copy link
Contributor Author

knotbin commented May 5, 2024

Okay @austincondiff, I'll implement that.

@knotbin
Copy link
Contributor Author

knotbin commented May 6, 2024

@austincondiff @activcoding does this look good to you?

@austincondiff
Copy link
Collaborator

austincondiff commented May 6, 2024

When only one file or folder is going to be deleted immediately, it should read…

Are you sure you want to delete
"CodeEdit-test"?

This item will be deleted immediately.
You can't undo this action.

When more than one file or folders is going to be deleted, it should read…

Are you sure you want to delete
the 2 selected items?

2 items will be deleted immediately. You can't undo this action.

Replace 2 with the number of selected items not including items in each selected folder.

Note

Moving to the trash should not warn users.

Sorry to pivot like this here. We typically shouldn’t plan features in the PR process, but this wasn’t properly thought all the way through.

@knotbin
Copy link
Contributor Author

knotbin commented May 6, 2024

currently you cannot select multiple files in the navigator @austincondiff so that would not be a possibility

@knotbin
Copy link
Contributor Author

knotbin commented May 6, 2024

I made it so there is no warning when you move to trash

@austincondiff
Copy link
Collaborator

We should probably add the ability to select multiple items in the project navigator, for example if the user wanted to delete multiple items at once. If multiple items are selected, we should disable all non-applicable items in the context menu. This should be handled in a separate PR though.

@knotbin knotbin requested a review from austincondiff May 6, 2024 15:28
Copy link
Collaborator

@austincondiff austincondiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks great! Thanks for putting up with all the back and forth!

@knotbin
Copy link
Contributor Author

knotbin commented May 6, 2024

No problem! Glad we sorted it all out!

Copy link
Member

@tom-ludwig tom-ludwig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers well done!

@thecoolwinter thecoolwinter merged commit cfc5dbc into CodeEditApp:main May 6, 2024
@thecoolwinter thecoolwinter added the bug Something isn't working label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working navigator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐞 deleteConfimartion alert shows incorrect count when deleting a nested folder
4 participants