Skip to content

Commit

Permalink
If multi-selection mode is activated by pressing&holding a file **in …
Browse files Browse the repository at this point in the history
…file selection mode**, folders' toggles will no longer be visible
  • Loading branch information
yasirkula committed Jan 26, 2021
1 parent 7cb0d12 commit 3d68227
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 20 deletions.
47 changes: 40 additions & 7 deletions Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ private bool AcceptNonExistingFilename
}

private PickMode m_pickerMode = PickMode.Files;
private PickMode PickerMode
internal PickMode PickerMode
{
get { return m_pickerMode; }
set
private set
{
m_pickerMode = value;

Expand Down Expand Up @@ -633,7 +633,7 @@ internal bool AllowMultiSelection
internal bool MultiSelectionToggleSelectionMode
{
get { return m_multiSelectionToggleSelectionMode; }
set
private set
{
if( m_multiSelectionToggleSelectionMode != value )
{
Expand Down Expand Up @@ -754,7 +754,7 @@ private void LateUpdate()
contextMenu.Hide();
}

#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
// Handle keyboard shortcuts
if( !EventSystem.current.currentSelectedGameObject )
{
Expand Down Expand Up @@ -1361,9 +1361,15 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
return;
}

// We want to toggle the selected states of the files even when they are double clicked
if( m_multiSelectionToggleSelectionMode )
{
// In file selection mode, we shouldn't include folders in the multi-selection
if( item.IsDirectory && m_pickerMode == PickMode.Files && !selectedFileEntries.Contains( item.Position ) )
return;

// If a file/folder is double clicked in multi-selection mode, instead of opening that file/folder, we want to toggle its selected state
isDoubleClick = false;
}

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

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

public void OnItemHeld( FileBrowserItem item )
{
if( item is FileBrowserQuickLink )
OnItemSelected( item, false );
else if( m_allowMultiSelection && ( !item.IsDirectory || m_pickerMode != PickMode.Files ) ) // Holding a folder in file selection mode should do nothing
{
if( !MultiSelectionToggleSelectionMode )
{
if( m_pickerMode == PickMode.Files )
{
// If some folders are selected in file selection mode, deselect these folders before enabling the selection toggles because otherwise,
// user won't be able to deselect the selected folders without exiting MultiSelectionToggleSelectionMode
for( int i = selectedFileEntries.Count - 1; i >= 0; i-- )
{
if( validFileEntries[selectedFileEntries[i]].IsDirectory )
selectedFileEntries.RemoveAt( i );
}
}

MultiSelectionToggleSelectionMode = true;
}

if( !selectedFileEntries.Contains( item.Position ) )
OnItemSelected( item, false );
}
}

#if !UNITY_EDITOR && UNITY_ANDROID
private void OnSAFDirectoryPicked( string rawUri, string name )
{
Expand Down
22 changes: 10 additions & 12 deletions Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,15 @@ private void Update()
{
// Item is held for a while
pressTime = Mathf.Infinity;
fileBrowser.MultiSelectionToggleSelectionMode = true;

if( !isSelected )
fileBrowser.OnItemSelected( this, false );
fileBrowser.OnItemHeld( this );
}
}
#endregion

#region Pointer Events
public void OnPointerClick( PointerEventData eventData )
{
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
if( eventData.button == PointerEventData.InputButton.Middle )
return;
else if( eventData.button == PointerEventData.InputButton.Right )
Expand Down Expand Up @@ -120,7 +117,7 @@ public void OnPointerClick( PointerEventData eventData )

public void OnPointerDown( PointerEventData eventData )
{
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
if( eventData.button != PointerEventData.InputButton.Left )
return;
#endif
Expand All @@ -130,19 +127,19 @@ public void OnPointerDown( PointerEventData eventData )

public void OnPointerUp( PointerEventData eventData )
{
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
if( eventData.button != PointerEventData.InputButton.Left )
return;
#endif

if( pressTime == Mathf.Infinity )
if( pressTime != Mathf.Infinity )
pressTime = Mathf.Infinity;
else if( fileBrowser.MultiSelectionToggleSelectionMode )
{
// We have activated MultiSelectionToggleSelectionMode with this press, processing the click would result in
// deselecting this item since its selected state would be toggled
eventData.eligibleForClick = false;
}
else
pressTime = Mathf.Infinity;
}

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

if( multiSelectionToggle ) // Quick links don't have multi selection toggle
if( multiSelectionToggle ) // Quick links don't have multi-selection toggle
{
if( fileBrowser.MultiSelectionToggleSelectionMode )
// Don't show multi-selection toggle for folders in file selection mode
if( fileBrowser.MultiSelectionToggleSelectionMode && ( !IsDirectory || fileBrowser.PickerMode != FileBrowser.PickMode.Files ) )
{
if( !multiSelectionToggle.gameObject.activeSelf )
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.yasirkula.simplefilebrowser",
"displayName": "Simple File Browser",
"version": "1.4.2",
"version": "1.4.3",
"documentationUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser",
"changelogUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/releases",
"licensesUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/blob/master/LICENSE.txt",
Expand Down

0 comments on commit 3d68227

Please sign in to comment.