From 3d682274a50dc6f8871e7f1e7b947b00308def9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Yasir=20KULA?= Date: Tue, 26 Jan 2021 15:38:47 +0300 Subject: [PATCH] If multi-selection mode is activated by pressing&holding a file **in file selection mode**, folders' toggles will no longer be visible --- .../SimpleFileBrowser/Scripts/FileBrowser.cs | 47 ++++++++++++++++--- .../Scripts/FileBrowserItem.cs | 22 ++++----- package.json | 2 +- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs index 26f8cb7..849216e 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs @@ -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; @@ -633,7 +633,7 @@ internal bool AllowMultiSelection internal bool MultiSelectionToggleSelectionMode { get { return m_multiSelectionToggleSelectionMode; } - set + private set { if( m_multiSelectionToggleSelectionMode != value ) { @@ -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 ) { @@ -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 ) { @@ -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 ) ) { @@ -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 ) @@ -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 ) { diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs index a0981de..6246d21 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs @@ -77,10 +77,7 @@ 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 @@ -88,7 +85,7 @@ private void Update() #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 ) @@ -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 @@ -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 ) @@ -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 ) { diff --git a/package.json b/package.json index e834e23..346cc28 100644 --- a/package.json +++ b/package.json @@ -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",