Skip to content

Commit 3d68227

Browse files
committed
If multi-selection mode is activated by pressing&holding a file **in file selection mode**, folders' toggles will no longer be visible
1 parent 7cb0d12 commit 3d68227

File tree

3 files changed

+51
-20
lines changed

3 files changed

+51
-20
lines changed

Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ private bool AcceptNonExistingFilename
596596
}
597597

598598
private PickMode m_pickerMode = PickMode.Files;
599-
private PickMode PickerMode
599+
internal PickMode PickerMode
600600
{
601601
get { return m_pickerMode; }
602-
set
602+
private set
603603
{
604604
m_pickerMode = value;
605605

@@ -633,7 +633,7 @@ internal bool AllowMultiSelection
633633
internal bool MultiSelectionToggleSelectionMode
634634
{
635635
get { return m_multiSelectionToggleSelectionMode; }
636-
set
636+
private set
637637
{
638638
if( m_multiSelectionToggleSelectionMode != value )
639639
{
@@ -754,7 +754,7 @@ private void LateUpdate()
754754
contextMenu.Hide();
755755
}
756756

757-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
757+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
758758
// Handle keyboard shortcuts
759759
if( !EventSystem.current.currentSelectedGameObject )
760760
{
@@ -1361,9 +1361,15 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
13611361
return;
13621362
}
13631363

1364-
// We want to toggle the selected states of the files even when they are double clicked
13651364
if( m_multiSelectionToggleSelectionMode )
1365+
{
1366+
// In file selection mode, we shouldn't include folders in the multi-selection
1367+
if( item.IsDirectory && m_pickerMode == PickMode.Files && !selectedFileEntries.Contains( item.Position ) )
1368+
return;
1369+
1370+
// If a file/folder is double clicked in multi-selection mode, instead of opening that file/folder, we want to toggle its selected state
13661371
isDoubleClick = false;
1372+
}
13671373

13681374
if( !isDoubleClick )
13691375
{
@@ -1374,7 +1380,7 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
13741380
}
13751381
else
13761382
{
1377-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
1383+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
13781384
// When Shift key is held, all items from the pivot item to the clicked item will be selected
13791385
if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
13801386
{
@@ -1395,7 +1401,7 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
13951401
multiSelectionPivotFileEntry = item.Position;
13961402

13971403
// When in toggle selection mode or Control key is held, individual items can be multi-selected
1398-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
1404+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
13991405
if( m_multiSelectionToggleSelectionMode || Input.GetKey( KeyCode.LeftControl ) || Input.GetKey( KeyCode.RightControl ) )
14001406
#else
14011407
if( m_multiSelectionToggleSelectionMode )
@@ -1458,6 +1464,33 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
14581464
}
14591465
}
14601466

1467+
public void OnItemHeld( FileBrowserItem item )
1468+
{
1469+
if( item is FileBrowserQuickLink )
1470+
OnItemSelected( item, false );
1471+
else if( m_allowMultiSelection && ( !item.IsDirectory || m_pickerMode != PickMode.Files ) ) // Holding a folder in file selection mode should do nothing
1472+
{
1473+
if( !MultiSelectionToggleSelectionMode )
1474+
{
1475+
if( m_pickerMode == PickMode.Files )
1476+
{
1477+
// If some folders are selected in file selection mode, deselect these folders before enabling the selection toggles because otherwise,
1478+
// user won't be able to deselect the selected folders without exiting MultiSelectionToggleSelectionMode
1479+
for( int i = selectedFileEntries.Count - 1; i >= 0; i-- )
1480+
{
1481+
if( validFileEntries[selectedFileEntries[i]].IsDirectory )
1482+
selectedFileEntries.RemoveAt( i );
1483+
}
1484+
}
1485+
1486+
MultiSelectionToggleSelectionMode = true;
1487+
}
1488+
1489+
if( !selectedFileEntries.Contains( item.Position ) )
1490+
OnItemSelected( item, false );
1491+
}
1492+
}
1493+
14611494
#if !UNITY_EDITOR && UNITY_ANDROID
14621495
private void OnSAFDirectoryPicked( string rawUri, string name )
14631496
{

Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,15 @@ private void Update()
7777
{
7878
// Item is held for a while
7979
pressTime = Mathf.Infinity;
80-
fileBrowser.MultiSelectionToggleSelectionMode = true;
81-
82-
if( !isSelected )
83-
fileBrowser.OnItemSelected( this, false );
80+
fileBrowser.OnItemHeld( this );
8481
}
8582
}
8683
#endregion
8784

8885
#region Pointer Events
8986
public void OnPointerClick( PointerEventData eventData )
9087
{
91-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
88+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
9289
if( eventData.button == PointerEventData.InputButton.Middle )
9390
return;
9491
else if( eventData.button == PointerEventData.InputButton.Right )
@@ -120,7 +117,7 @@ public void OnPointerClick( PointerEventData eventData )
120117

121118
public void OnPointerDown( PointerEventData eventData )
122119
{
123-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
120+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
124121
if( eventData.button != PointerEventData.InputButton.Left )
125122
return;
126123
#endif
@@ -130,19 +127,19 @@ public void OnPointerDown( PointerEventData eventData )
130127

131128
public void OnPointerUp( PointerEventData eventData )
132129
{
133-
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
130+
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
134131
if( eventData.button != PointerEventData.InputButton.Left )
135132
return;
136133
#endif
137134

138-
if( pressTime == Mathf.Infinity )
135+
if( pressTime != Mathf.Infinity )
136+
pressTime = Mathf.Infinity;
137+
else if( fileBrowser.MultiSelectionToggleSelectionMode )
139138
{
140139
// We have activated MultiSelectionToggleSelectionMode with this press, processing the click would result in
141140
// deselecting this item since its selected state would be toggled
142141
eventData.eligibleForClick = false;
143142
}
144-
else
145-
pressTime = Mathf.Infinity;
146143
}
147144

148145
#if UNITY_EDITOR || ( !UNITY_ANDROID && !UNITY_IOS )
@@ -168,9 +165,10 @@ public void SetSelected( bool isSelected )
168165
this.isSelected = isSelected;
169166
background.color = isSelected ? fileBrowser.selectedFileColor : fileBrowser.normalFileColor;
170167

171-
if( multiSelectionToggle ) // Quick links don't have multi selection toggle
168+
if( multiSelectionToggle ) // Quick links don't have multi-selection toggle
172169
{
173-
if( fileBrowser.MultiSelectionToggleSelectionMode )
170+
// Don't show multi-selection toggle for folders in file selection mode
171+
if( fileBrowser.MultiSelectionToggleSelectionMode && ( !IsDirectory || fileBrowser.PickerMode != FileBrowser.PickMode.Files ) )
174172
{
175173
if( !multiSelectionToggle.gameObject.activeSelf )
176174
{

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.4.2",
4+
"version": "1.4.3",
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)