Skip to content

Commit e24fa52

Browse files
committed
Added FileBrowser.CustomSearchHandler event
1 parent 0852f4a commit e24fa52

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

.github/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ FileBrowser.DisplayedEntriesFilter += ( entry ) =>
153153
};
154154
```
155155

156+
You can override the search behaviour (e.g. use regex) via the **CustomSearchHandler** event:
157+
158+
```csharp
159+
FileBrowser.CustomSearchHandler += (entry, searchTerm) =>
160+
{
161+
return entry.Name.Contains(searchTerm);
162+
};
163+
```
164+
156165
You can set whether or not hidden files should be shown in the file browser via **FileBrowser.ShowHiddenFiles** (has no effect when Storage Access Framework is used on Android 10+). This value can also be changed from the "*Show hidden files*" toggle in the user interface. To change the visibility of that toggle, you can use **FileBrowser.DisplayHiddenFilesToggle**. Note that this toggle is always hidden on Android 10+ when Storage Access Framework is used or on mobile devices when device is held in portrait orientation.
157166

158167
To open files or directories in the file browser with a single click (instead of double clicking), you can set **FileBrowser.SingleClickMode** to *true*.

Plugins/SimpleFileBrowser/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Simple File Browser (v1.7.4) =
1+
= Simple File Browser (v1.7.5) =
22

33
Documentation: https://github.com/yasirkula/UnitySimpleFileBrowser
44
FAQ: https://github.com/yasirkula/UnitySimpleFileBrowser#faq

Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,21 @@ private string SearchString
692692
}
693693
}
694694

695+
private SearchPredicate m_customSearchHandler;
696+
public static event SearchPredicate CustomSearchHandler
697+
{
698+
add
699+
{
700+
Instance.m_customSearchHandler += value;
701+
m_instance.RefreshFiles(false);
702+
}
703+
remove
704+
{
705+
Instance.m_customSearchHandler -= value;
706+
m_instance.RefreshFiles(false);
707+
}
708+
}
709+
695710
private bool m_acceptNonExistingFilename = false; // Is set to true when showing save dialog for Files or FilesAndFolders, false otherwise
696711
private bool AcceptNonExistingFilename
697712
{
@@ -2130,8 +2145,16 @@ private bool FileSystemEntryMatchesFilters( in FileSystemEntry item, bool allExt
21302145
return false;
21312146
}
21322147

2133-
if( m_searchString.Length > 0 && textComparer.IndexOf( item.Name, m_searchString, textCompareOptions ) < 0 )
2134-
return false;
2148+
if (m_searchString.Length > 0)
2149+
{
2150+
if (m_customSearchHandler != null)
2151+
{
2152+
if (!m_customSearchHandler(item, m_searchString))
2153+
return false;
2154+
}
2155+
else if (textComparer.IndexOf(item.Name, m_searchString, textCompareOptions) < 0)
2156+
return false;
2157+
}
21352158

21362159
if( m_displayedEntriesFilter != null && !m_displayedEntriesFilter( item ) )
21372160
return false;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.simplefilebrowser",
33
"displayName": "Simple File Browser",
4-
"version": "1.7.4",
4+
"version": "1.7.5",
55
"documentationUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser",
66
"changelogUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)