@@ -18,6 +18,8 @@ import {
1818 AiOutlinePlus ,
1919 AiOutlineReload
2020} from 'react-icons/ai' ;
21+ import { SiLua } from 'react-icons/si' ;
22+ import { dirname } from '../../utils' ;
2123
2224export const FileTreeContextMenu = ( ) => {
2325 const dispatch = useAppDispatch ( ) ;
@@ -57,7 +59,7 @@ export const FileTreeContextMenu = () => {
5759 const handleCreateFile = async ( ) => {
5860 if ( ! path ) return ;
5961
60- const newFilePath = await MainProcess . createFile ( { directoryPath : path , extension : 'txt' } ) ;
62+ const newFilePath = await MainProcess . createFile ( { directoryPath : isDirectory ? path : dirname ( path ) , extension : 'txt' } ) ;
6163
6264 expandSelectedDirectory ( ) ;
6365 dispatch ( FileTreeActions . setRenamingFilePath ( newFilePath ) ) ;
@@ -67,7 +69,7 @@ export const FileTreeContextMenu = () => {
6769 const handleCreateScript = async ( ) => {
6870 if ( ! path ) return ;
6971
70- const newFilePath = await MainProcess . createFile ( { directoryPath : path , extension : 'lua' } ) ;
72+ const newFilePath = await MainProcess . createFile ( { directoryPath : isDirectory ? path : dirname ( path ) , extension : 'lua' } ) ;
7173
7274 expandSelectedDirectory ( ) ;
7375 dispatch ( FileTreeActions . setRenamingFilePath ( newFilePath ) ) ;
@@ -81,7 +83,7 @@ export const FileTreeContextMenu = () => {
8183 title : 'Unable to create directory' ,
8284 message : 'Subdirectories will cause the build to break, and are not currently supported.' ,
8385 color : 'red'
84- } )
86+ } ) ;
8587 return ;
8688 }
8789
@@ -166,13 +168,11 @@ export const FileTreeContextMenu = () => {
166168 onClose = { handleContextMenuClose }
167169 { ...menuProps }
168170 >
169- { isDirectory &&
170- < SubMenu label = { ( ) => < Text size = "xs" > < Center inline > < AiOutlinePlus /> < Space w = "xs" /> New</ Center > </ Text > } >
171- < ContextMenuItem icon = { AiOutlineFolder } onClick = { handleCreateDirectory } color = { selectedRootDirectory ? 'black' : 'dimmed' } > Directory</ ContextMenuItem >
172- < ContextMenuItem icon = { AiFillFile } onClick = { handleCreateFile } > Script</ ContextMenuItem >
173- < ContextMenuItem icon = { AiFillFile } onClick = { handleCreateScript } > File</ ContextMenuItem >
174- </ SubMenu >
175- }
171+ < SubMenu label = { ( ) => < Text size = "xs" > < Center inline > < AiOutlinePlus /> < Space w = "xs" /> New</ Center > </ Text > } >
172+ < ContextMenuItem icon = { AiOutlineFolder } onClick = { handleCreateDirectory } color = { selectedRootDirectory ? 'black' : 'dimmed' } > Directory</ ContextMenuItem >
173+ < ContextMenuItem icon = { SiLua } onClick = { handleCreateScript } > Script</ ContextMenuItem >
174+ < ContextMenuItem icon = { AiFillFile } onClick = { handleCreateFile } > File</ ContextMenuItem >
175+ </ SubMenu >
176176
177177 { isRootDirectory && < ContextMenuItem icon = { AiOutlineReload } onClick = { handleRefreshRootDirectory } > Refresh</ ContextMenuItem > }
178178 { hasChildren && < ContextMenuItem icon = { AiOutlineFolder } onClick = { toggleSelectedDirectory } > { expanded ? 'Collapse' : 'Expand' } </ ContextMenuItem > }
0 commit comments