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

Make file filters extensible by turning them into an interface, instead of concrete class. #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arturaz
Copy link

@arturaz arturaz commented Apr 13, 2022

No description provided.

@yasirkula
Copy link
Owner

Thank you for the PR. How did you benefit from this change in your own projects? What did your custom IFilter implementations do differently than Filter?

@arturaz
Copy link
Author

arturaz commented Apr 13, 2022

We needed to filter based on regex, something like new Regex(".data-.+?-ourextension"). This allowed us to implement the custom filter for this case.

@arturaz
Copy link
Author

arturaz commented Apr 18, 2022

Is there any improvement that should be made to get this merged?

@yasirkula
Copy link
Owner

yasirkula commented Apr 19, 2022

I couldn't inspect most of the recent PRs in detail due to my busy schedule for a long time. About this feature, I was originally thinking about adding an event to FileBrowser to filter the files with custom C# code (regex can be applied in that event). That solution seems cleaner to me as I'd like to keep file filters as clean and simple as possible.

P.S. Actually I forgot that I've already added that event in a past release: FileBrowser.DisplayedEntriesFilter

Copy link
Owner

@yasirkula yasirkula left a comment

Choose a reason for hiding this comment

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

I've decided to merge this request. Please review my final requests and let me know if you have any questions ^^

@@ -1470,7 +1512,7 @@ public void OnSubmitButtonClicked()
{
// This is a nonexisting file
string filename = filenameInput.Substring( startIndex, filenameLength );
if( m_pickerMode != PickMode.Folders && filters[filtersDropdown.value].extensions != null )
if( m_pickerMode != PickMode.Folders && !filters[filtersDropdown.value].isAllFilesFilter )
Copy link
Owner

Choose a reason for hiding this comment

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

We can change it as follows and remove the isAllFilesFilter property: m_pickerMode != PickMode.Folders && filters[filtersDropdown.value] != allFilesFilter

@@ -2915,8 +2957,7 @@ public static bool SetDefaultFilter( string defaultFilter )

for( int i = 0; i < Instance.filters.Count; i++ )
{
HashSet<string> extensions = Instance.filters[i].extensionsSet;
if( extensions != null && extensions.Contains( defaultFilter ) )
if( Instance.filters[i].isValidExtension( defaultFilter ) )
Copy link
Owner

Choose a reason for hiding this comment

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

We can change it as follows and remove the isValidExtension property: Instance.filters[i].MatchesExtension( defaultFilter, defaultFilter.LastIndexOf( '.' ) != 0 ). Even better, the value of defaultFilter.LastIndexOf( '.' ) != 0 can be cached in a bool defaultFilterHasMultipleSuffixes variable before the for-loop.

Comment on lines 44 to +46
#region Inner Classes
public class Filter

public interface IFilter {
Copy link
Owner

Choose a reason for hiding this comment

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

Please get rid of the free space and put the curly bracket on a new line for consistency (I'm asking this since this is a small commit).

@arturaz
Copy link
Author

arturaz commented Oct 11, 2022 via email

@yasirkula
Copy link
Owner

I'm open to merging this pull request but please see my review and also merge the latest commit on the mainstream to your branch.

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

Successfully merging this pull request may close these issues.

2 participants