Skip to content

Commit 0852f4a

Browse files
committed
Slight simplifications to the codebase
1 parent bce53b2 commit 0852f4a

11 files changed

Lines changed: 20 additions & 49 deletions

Plugins/SimpleFileBrowser/Scripts/EventSystemHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ namespace SimpleFileBrowser
1111
[DefaultExecutionOrder( 1000 )]
1212
public class EventSystemHandler : MonoBehaviour
1313
{
14-
#pragma warning disable 0649
1514
[SerializeField]
1615
private GameObject embeddedEventSystem;
17-
#pragma warning restore 0649
1816

1917
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
2018
private void Awake()

Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ) )

Plugins/SimpleFileBrowser/Scripts/FileBrowserAccessRestrictedPanel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace SimpleFileBrowser
1010
{
1111
public class FileBrowserAccessRestrictedPanel : MonoBehaviour
1212
{
13-
#pragma warning disable 0649
1413
[SerializeField]
1514
private HorizontalLayoutGroup contentLayoutGroup;
1615

@@ -19,7 +18,6 @@ public class FileBrowserAccessRestrictedPanel : MonoBehaviour
1918

2019
[SerializeField]
2120
private Button okButton;
22-
#pragma warning restore 0649
2321

2422
private void Awake()
2523
{

Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace SimpleFileBrowser
66
{
77
public class FileBrowserContextMenu : MonoBehaviour
88
{
9-
#pragma warning disable 0649
109
[SerializeField]
1110
private FileBrowser fileBrowser;
1211

@@ -36,7 +35,6 @@ public class FileBrowserContextMenu : MonoBehaviour
3635

3736
[SerializeField]
3837
private float minDistanceToEdges = 10f;
39-
#pragma warning restore 0649
4038

4139
private void Awake()
4240
{

Plugins/SimpleFileBrowser/Scripts/FileBrowserCursorHandler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ public class FileBrowserCursorHandler : MonoBehaviour
99
#endif
1010
{
1111
#if UNITY_EDITOR || ( !UNITY_ANDROID && !UNITY_IOS )
12-
#pragma warning disable 0649
1312
[SerializeField]
1413
private Texture2D resizeCursor;
15-
#pragma warning restore 0649
1614

1715
private bool isHovering;
1816
private bool isResizing;

Plugins/SimpleFileBrowser/Scripts/FileBrowserFileOperationConfirmationPanel.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public enum OperationType { Delete = 0, Overwrite = 1 };
1414

1515
public delegate void OnOperationConfirmed();
1616

17-
#pragma warning disable 0649
1817
[SerializeField]
1918
private VerticalLayoutGroup contentLayoutGroup;
2019

@@ -44,7 +43,6 @@ public enum OperationType { Delete = 0, Overwrite = 1 };
4443

4544
[SerializeField]
4645
private float narrowScreenWidth = 380f;
47-
#pragma warning restore 0649
4846

4947
private OnOperationConfirmed onOperationConfirmed;
5048

Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class FileBrowserItem : ListItem, IPointerClickHandler, IPointerDownHandl
1818
#region Variables
1919
protected FileBrowser fileBrowser;
2020

21-
#pragma warning disable 0649
2221
[SerializeField]
2322
private Image background;
2423

@@ -31,7 +30,6 @@ public class FileBrowserItem : ListItem, IPointerClickHandler, IPointerDownHandl
3130

3231
[SerializeField]
3332
private TextMeshProUGUI nameText;
34-
#pragma warning restore 0649
3533

3634
#pragma warning disable 0414
3735
private bool isSelected, isHidden;

Plugins/SimpleFileBrowser/Scripts/FileBrowserMovement.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace SimpleFileBrowser
66
public class FileBrowserMovement : MonoBehaviour
77
{
88
#region Variables
9-
#pragma warning disable 0649
109
private FileBrowser fileBrowser;
1110
private RectTransform canvasTR;
1211
private Camera canvasCam;
@@ -16,7 +15,6 @@ public class FileBrowserMovement : MonoBehaviour
1615

1716
[SerializeField]
1817
private RecycledListView listView;
19-
#pragma warning restore 0649
2018

2119
private Vector2 initialTouchPos = Vector2.zero;
2220
private Vector2 initialAnchoredPos, initialSizeDelta;

Plugins/SimpleFileBrowser/Scripts/FileBrowserRenamedItem.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class FileBrowserRenamedItem : MonoBehaviour
1212
{
1313
public delegate void OnRenameCompleted( string filename );
1414

15-
#pragma warning disable 0649
1615
[SerializeField]
1716
private Image background;
1817

@@ -22,7 +21,6 @@ public class FileBrowserRenamedItem : MonoBehaviour
2221
[SerializeField]
2322
private TMP_InputField nameInputField;
2423
public TMP_InputField InputField { get { return nameInputField; } }
25-
#pragma warning restore 0649
2624

2725
private OnRenameCompleted onRenameCompleted;
2826

Plugins/SimpleFileBrowser/Scripts/SimpleRecycledListView/RecycledListView.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class RecycledListView : MonoBehaviour
1111
, IPointerClickHandler
1212
#endif
1313
{
14-
#pragma warning disable 0649
1514
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
1615
[SerializeField]
1716
private FileBrowser fileBrowser;
@@ -22,7 +21,6 @@ public class RecycledListView : MonoBehaviour
2221
private RectTransform viewportTransform;
2322
[SerializeField]
2423
private RectTransform contentTransform;
25-
#pragma warning restore 0649
2624

2725
private float itemHeight, _1OverItemHeight;
2826
private float viewportHeight;

0 commit comments

Comments
 (0)