@@ -55,7 +55,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
5555 handleHide : null
5656 } ,
5757 modals : [ ] ,
58- toasterMsg : ''
58+ toasterMsg : '' ,
59+ mouseOverElement : null
5960 } )
6061 const editRef = useRef ( null )
6162
@@ -338,7 +339,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
338339 try {
339340 const exists = await fileManager . exists ( dirName )
340341
341- if ( exists ) return
342+ if ( exists ) {
343+ return modal ( 'Rename File Failed' , `A file or folder ${ extractNameFromKey ( newFolderPath ) } already exists at this location. Please choose a different name.` , {
344+ label : 'Close' ,
345+ fn : ( ) => { }
346+ } , null )
347+ }
342348 await fileManager . mkdir ( dirName )
343349 setState ( prevState => {
344350 return { ...prevState , focusElement : [ { key : newFolderPath , type : 'folder' } ] }
@@ -378,7 +384,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
378384 const exists = await fileManager . exists ( newPath )
379385
380386 if ( exists ) {
381- modal ( 'Rename File Failed' , 'File name already exists' , {
387+ modal ( 'Rename File Failed' , `A file or folder ${ extractNameFromKey ( newPath ) } already exists at this location. Please choose a different name.` , {
382388 label : 'Close' ,
383389 fn : ( ) => { }
384390 } , null )
@@ -853,6 +859,18 @@ export const FileExplorer = (props: FileExplorerProps) => {
853859 }
854860 }
855861
862+ const handleMouseOver = ( path : string ) => {
863+ setState ( prevState => {
864+ return { ...prevState , mouseOverElement : path }
865+ } )
866+ }
867+
868+ const handleMouseOut = ( ) => {
869+ setState ( prevState => {
870+ return { ...prevState , mouseOverElement : null }
871+ } )
872+ }
873+
856874 const label = ( file : File ) => {
857875 return (
858876 < div
@@ -878,6 +896,12 @@ export const FileExplorer = (props: FileExplorerProps) => {
878896 }
879897
880898 const renderFiles = ( file : File , index : number ) => {
899+ const labelClass = state . focusEdit . element === file . path
900+ ? 'bg-light' : state . focusElement . findIndex ( item => item . key === file . path ) !== - 1
901+ ? 'bg-secondary' : state . mouseOverElement === file . path
902+ ? 'bg-light border' : ( state . focusContext . element === file . path ) && ( state . focusEdit . element !== file . path )
903+ ? 'bg-light border' : ''
904+
881905 if ( file . isDirectory ) {
882906 return (
883907 < div key = { index } >
@@ -896,9 +920,17 @@ export const FileExplorer = (props: FileExplorerProps) => {
896920 e . stopPropagation ( )
897921 handleContextMenuFolder ( e . pageX , e . pageY , file . path , e . target . textContent )
898922 } }
899- labelClass = { state . focusEdit . element === file . path ? 'bg-light' : state . focusElement . findIndex ( item => item . key === file . path ) !== - 1 ? 'bg-secondary' : '' }
923+ labelClass = { labelClass }
900924 controlBehaviour = { state . ctrlKey }
901925 expand = { state . expandPath . includes ( file . path ) }
926+ onMouseOver = { ( e ) => {
927+ e . stopPropagation ( )
928+ handleMouseOver ( file . path )
929+ } }
930+ onMouseOut = { ( e ) => {
931+ e . stopPropagation ( )
932+ if ( state . mouseOverElement === file . path ) handleMouseOut ( )
933+ } }
902934 >
903935 {
904936 file . child ? < TreeView id = { `treeView${ file . path } ` } key = { index } > {
@@ -923,6 +955,10 @@ export const FileExplorer = (props: FileExplorerProps) => {
923955 pageY = { state . focusContext . y }
924956 path = { file . path }
925957 type = 'folder'
958+ onMouseOver = { ( e ) => {
959+ e . stopPropagation ( )
960+ handleMouseOver ( file . path )
961+ } }
926962 />
927963 }
928964 </ div >
@@ -944,7 +980,15 @@ export const FileExplorer = (props: FileExplorerProps) => {
944980 handleContextMenuFile ( e . pageX , e . pageY , file . path , e . target . textContent )
945981 } }
946982 icon = 'far fa-file'
947- labelClass = { state . focusEdit . element === file . path ? 'bg-light' : state . focusElement . findIndex ( item => item . key === file . path ) !== - 1 ? 'bg-secondary' : '' }
983+ labelClass = { labelClass }
984+ onMouseOver = { ( e ) => {
985+ e . stopPropagation ( )
986+ handleMouseOver ( file . path )
987+ } }
988+ onMouseOut = { ( e ) => {
989+ e . stopPropagation ( )
990+ if ( state . mouseOverElement === file . path ) handleMouseOut ( )
991+ } }
948992 />
949993 { ( ( state . focusContext . element === file . path ) && ( state . focusEdit . element !== file . path ) ) &&
950994 < FileExplorerContextMenu
@@ -960,6 +1004,10 @@ export const FileExplorer = (props: FileExplorerProps) => {
9601004 pageY = { state . focusContext . y }
9611005 path = { file . path }
9621006 type = 'file'
1007+ onMouseOver = { ( e ) => {
1008+ e . stopPropagation ( )
1009+ handleMouseOver ( file . path )
1010+ } }
9631011 />
9641012 }
9651013 </ div >
0 commit comments