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

Add filename filter field to FileDialog #88673

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

vPumpking
Copy link
Contributor

@vPumpking vPumpking commented Feb 22, 2024

Added possibility to filter files and folders through a text entry.
The text entry is hidden by default, and can be opened by pressing Ctrl+F or by clicking the appropriate filter button.

Closes godotengine/godot-proposals#9099

This Pull Request features a filter bar for FileDialog.
image
It enables to search a specific term in the current folder. The matching subdirectories are first displayed alphabetically, and then the same happens to files.

2024-02-29.15-08-45.mp4

@vPumpking vPumpking requested review from a team as code owners February 22, 2024 17:41
@vPumpking vPumpking force-pushed the FileDialog-Filter branch 5 times, most recently from 4c28a4c to 347e80c Compare February 22, 2024 18:02
@AThousandShips AThousandShips added this to the 4.x milestone Feb 22, 2024
@vPumpking vPumpking force-pushed the FileDialog-Filter branch 3 times, most recently from 5fcec1b to c003b8a Compare February 22, 2024 18:28
@vPumpking
Copy link
Contributor Author

I've got an error saying that if (match and files.front()->get().to_lower().contains(filename_filter_match.to_lower())) { was a syntax error, how am i supposed to write it?

@AThousandShips
Copy link
Member

With &&, don't use and in c++

@vPumpking
Copy link
Contributor Author

With &&, don't use and in c++

That's weird because it worked with and when I tested my code

@AThousandShips
Copy link
Member

AThousandShips commented Feb 22, 2024

Yes it's an alternative syntax, but it's not allowed (and fails on MSVC)

@vPumpking vPumpking changed the title Add filename filter field to EditorFildeDialog and FileDialog Add filename filter field to EditorFileDialog and FileDialog Feb 22, 2024
@bruvzg
Copy link
Member

bruvzg commented Feb 22, 2024

That's weird because it worked with and when I tested my code

MSVC do support alternative syntax, but require inclusion of iso646.h (this is true for all compilers, but GCC will work with a lot of omitted includes). Syntax exist to support ancient encodings without some characters like & and in general should not be used.

Copy link
Member

@bruvzg bruvzg left a comment

Choose a reason for hiding this comment

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

Same for the second dialog.

Note: This feature will be impossible to implement in the native dialogs (on any of the supported platforms). But native dialogs usually have search functionality of their own.

@vPumpking vPumpking force-pushed the FileDialog-Filter branch 4 times, most recently from 48fe190 to 1b433d1 Compare February 23, 2024 09:37
@vPumpking
Copy link
Contributor Author

vPumpking commented Feb 23, 2024

Same for the second dialog.

Note: This feature will be impossible to implement in the native dialogs (on any of the supported platforms). But native dialogs usually have search functionality of their own.

@bruvzg
I'm trying to figure out why, but your suggestion broke the filter

EDIT: Fixed, my fault

@Calinou
Copy link
Member

Calinou commented Aug 5, 2024

I still can't get the autoselect behavior to work in FileDialog, I need to use Shift + Tab to focus the file list then select a file:

filedialog_no_autoselect_after_filter.mp4

This behavior only works in EditorFileDialog for me:

editorfiledialog_autoselect_after_filter.mp4

Also, this is printed in the console every time I enter a character in the file filter if there are no visible files in the current folder in EditorFileDialog (e.g. because of the file type filter):

ERROR: Index p_idx = 0 is out of bounds (items.size() = 0).
   at: select (./scene/gui/item_list.cpp:381)

@vPumpking
Copy link
Contributor Author

I still can't get the autoselect behavior to work in FileDialog, I need to use Shift + Tab to focus the file list then select a file:

filedialog_no_autoselect_after_filter.mp4

This behavior only works in EditorFileDialog for me:

editorfiledialog_autoselect_after_filter.mp4

Also, this is printed in the console every time I enter a character in the file filter if there are no visible files in the current folder in EditorFileDialog (e.g. because of the file type filter):

ERROR: Index p_idx = 0 is out of bounds (items.size() = 0).
   at: select (./scene/gui/item_list.cpp:381)

so this isn't the final commit after all 😅, sorry for that
I think I get what behavior you want for FileDialog: you want the first item to be selected every time a character is entered
but I don't think it's possible, since doing that would make the filter bar loose focus (tell me if I'm wrong) 🤔
the error when directory empty should be an easy fix though

@Calinou
Copy link
Member

Calinou commented Aug 5, 2024

I think I get what behavior you want for FileDialog: you want the first item to be selected every time a character is entered
but I don't think it's possible, since doing that would make the filter bar loose focus (tell me if I'm wrong) 🤔

The same behavior works fine in EditorFileDialog. You can have the ItemList/Tree select an item without giving focus to the ItemList/Tree in question.

@vPumpking
Copy link
Contributor Author

vPumpking commented Aug 10, 2024

as said here #88673 (comment) , I struggle figuring out why it works in editor version but not in regular one, since it's implemented the same way
EDIT:
Seems to work for me as is

2024-08-11.02-50-47.mp4

@YeldhamDev
Copy link
Member

The file focusing doesn't appear to work on the non-editor file dialog in my end. Calinou also reported the same on the dev chat.

@vPumpking
Copy link
Contributor Author

vPumpking commented Aug 18, 2024

how can I have the latest version of godot source into my branch without adding any commit from my account?

@YeldhamDev
Copy link
Member

how can I have the latest version of godot source into my branch without adding any commit from my account?

https://docs.godotengine.org/en/stable/contributing/workflow/pr_workflow.html#updating-your-branch

@vPumpking
Copy link
Contributor Author

thanks

@vPumpking
Copy link
Contributor Author

@bruvzg thanks for your help man

@vPumpking
Copy link
Contributor Author

@bruvzg as written in the review, I made the changes you recommended, but now the editor filename filter doesn't select the firdt item anymore

@vPumpking vPumpking force-pushed the FileDialog-Filter branch 3 times, most recently from d2cf3d3 to ab4e272 Compare September 28, 2024 15:08
@vPumpking vPumpking changed the title Add filename filter field to EditorFileDialog and FileDialog Add filename filter field to FileDialog Sep 29, 2024
@vPumpking
Copy link
Contributor Author

Could someone please restart the checks, it seems like a network error occured

Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

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

Works great now 🙂

Note for reviewers: EditorFileDialog changes were removed from this PR since #97344 was merged. This PR now only modifies FileDialog, which #97344 didn't modify. Therefore, this PR ensures feature parity between FileDialog and EditorFileDialog on providing a filter function.

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Oct 2, 2024
Added possibility to filter files and folders through a text entry.
@akien-mga akien-mga merged commit a70402b into godotengine:master Oct 4, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a search function to FileDialog and EditorFileDialog
9 participants