@@ -197,13 +197,11 @@ public static event FileSystemEntryFilter DisplayedEntriesFilter
197197 add
198198 {
199199 Instance . m_displayedEntriesFilter += value ;
200- m_instance . PersistFileEntrySelection ( ) ;
201200 m_instance . RefreshFiles ( false ) ;
202201 }
203202 remove
204203 {
205204 Instance . m_displayedEntriesFilter -= value ;
206- m_instance . PersistFileEntrySelection ( ) ;
207205 m_instance . RefreshFiles ( false ) ;
208206 }
209207 }
@@ -352,7 +350,6 @@ public static FileBrowser Instance
352350 #endregion
353351
354352 #region Variables
355- #pragma warning disable 0649
356353 [ Header ( "Settings" ) ]
357354 [ SerializeField ]
358355 internal int minWidth = 380 ;
@@ -507,7 +504,6 @@ public static FileBrowser Instance
507504
508505 [ SerializeField ]
509506 private FileBrowserCursorHandler resizeCursorHandler ;
510- #pragma warning restore 0649
511507
512508 internal RectTransform rectTransform ;
513509 private Canvas canvas ;
@@ -676,7 +672,7 @@ private string CurrentPath
676672 }
677673
678674 m_multiSelectionToggleSelectionMode = false ;
679- RefreshFiles ( true ) ;
675+ RefreshFiles ( true , false ) ;
680676 }
681677 }
682678
@@ -780,6 +776,7 @@ private string LastBrowsedFolder
780776 public delegate void OnSuccess ( string [ ] paths ) ;
781777 public delegate void OnCancel ( ) ;
782778 public delegate bool FileSystemEntryFilter ( FileSystemEntry entry ) ;
779+ public delegate bool SearchPredicate ( FileSystemEntry entry , string searchTerm ) ;
783780 public delegate void PermissionCallback ( Permission permission ) ;
784781#if UNITY_EDITOR || UNITY_ANDROID
785782 public delegate void AndroidSAFDirectoryPickCallback ( string rawUri , string name ) ;
@@ -962,13 +959,11 @@ private void LateUpdate()
962959#endif
963960 }
964961
965- private void OnApplicationFocus ( bool focus )
966- {
967- if ( ! focus )
968- PersistFileEntrySelection ( ) ;
969- else
970- RefreshFiles ( true ) ;
971- }
962+ private void OnApplicationFocus ( bool focus )
963+ {
964+ if ( focus )
965+ RefreshFiles ( true ) ;
966+ }
972967 #endregion
973968
974969 #region Interface Methods
@@ -1694,7 +1689,6 @@ private void OnSearchStringChanged( string newSearchString )
16941689 if ( ! canvas ) // Same as OnPathChanged
16951690 return ;
16961691
1697- PersistFileEntrySelection ( ) ;
16981692 SearchString = newSearchString ;
16991693 }
17001694
@@ -1712,7 +1706,6 @@ private void OnFilterChanged( int value )
17121706 extensionsSingleSuffixModeChanged = ( AllExtensionsHaveSingleSuffix != allExtensionsHadSingleSuffix ) ;
17131707 }
17141708
1715- PersistFileEntrySelection ( ) ;
17161709 RefreshFiles ( extensionsSingleSuffixModeChanged ) ;
17171710 }
17181711
@@ -1721,7 +1714,6 @@ private void OnShowHiddenFilesToggleChanged( bool value )
17211714 if ( ! canvas ) // Same as OnPathChanged
17221715 return ;
17231716
1724- PersistFileEntrySelection ( ) ;
17251717 RefreshFiles ( false ) ;
17261718 }
17271719
@@ -2016,10 +2008,17 @@ public void Hide()
20162008 gameObject . SetActive ( false ) ;
20172009 }
20182010
2019- public void RefreshFiles ( bool pathChanged )
2020- {
2011+ public void RefreshFiles ( bool pathChanged , bool preserveSelection = true )
2012+ {
20212013 bool allExtensionsHaveSingleSuffix = AllExtensionsHaveSingleSuffix ;
20222014
2015+ if ( preserveSelection )
2016+ {
2017+ pendingFileEntrySelection . Clear ( ) ;
2018+ for ( int i = 0 ; i < selectedFileEntries . Count ; i ++ )
2019+ pendingFileEntrySelection . Add ( validFileEntries [ selectedFileEntries [ i ] ] . Name ) ;
2020+ }
2021+
20232022 if ( pathChanged )
20242023 {
20252024 if ( ! string . IsNullOrEmpty ( m_currentPath ) )
@@ -2099,7 +2098,7 @@ public void RefreshFiles( bool pathChanged )
20992098
21002099 // Prevent the case where all the content stays offscreen after changing the search string
21012100 EnsureScrollViewIsWithinBounds ( ) ;
2102- }
2101+ }
21032102
21042103 // Returns whether or not the FileSystemEntry passes the file browser's filters and should be displayed in the files list
21052104 private bool FileSystemEntryMatchesFilters ( in FileSystemEntry item , bool allExtensionsHaveSingleSuffix )
@@ -2237,7 +2236,7 @@ private IEnumerator CreateNewFolderCoroutine()
22372236 pendingFileEntrySelection . Clear ( ) ;
22382237 pendingFileEntrySelection . Add ( folderName ) ;
22392238
2240- RefreshFiles ( true ) ;
2239+ RefreshFiles ( true , false ) ;
22412240
22422241 if ( m_pickerMode != PickMode . Files )
22432242 filenameInputField . text = folderName ;
@@ -2302,7 +2301,7 @@ public void RenameSelectedFile()
23022301 pendingFileEntrySelection . Clear ( ) ;
23032302 pendingFileEntrySelection . Add ( newName ) ;
23042303
2305- RefreshFiles ( true ) ;
2304+ RefreshFiles ( true , false ) ;
23062305
23072306 if ( ( fileInfo . IsDirectory && m_pickerMode != PickMode . Files ) || ( ! fileInfo . IsDirectory && m_pickerMode != PickMode . Folders ) )
23082307 filenameInputField . text = newName ;
@@ -2331,18 +2330,10 @@ public void DeleteSelectedFiles()
23312330 selectedFileEntries . Clear ( ) ;
23322331
23332332 MultiSelectionToggleSelectionMode = false ;
2334- RefreshFiles ( true ) ;
2333+ RefreshFiles ( true , false ) ;
23352334 } ) ;
23362335 }
23372336
2338- // Makes sure that the selection persists after Refreshing the file entries
2339- private void PersistFileEntrySelection ( )
2340- {
2341- pendingFileEntrySelection . Clear ( ) ;
2342- for ( int i = 0 ; i < selectedFileEntries . Count ; i ++ )
2343- pendingFileEntrySelection . Add ( validFileEntries [ selectedFileEntries [ i ] ] . Name ) ;
2344- }
2345-
23462337 private bool AddQuickLink ( Sprite icon , string name , string path )
23472338 {
23482339 if ( string . IsNullOrEmpty ( path ) )
0 commit comments