|
|
|
@ -16,7 +16,7 @@ import './css/file-explorer.css' |
|
|
|
|
const queryParams = new QueryParams() |
|
|
|
|
|
|
|
|
|
export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
const { filesProvider, name, registry, plugin, focusRoot } = props |
|
|
|
|
const { filesProvider, name, registry, plugin, focusRoot, contextMenuItems } = props |
|
|
|
|
const [state, setState] = useState({ |
|
|
|
|
focusElement: [{ |
|
|
|
|
key: name, |
|
|
|
@ -76,36 +76,42 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
const accessToken = config.get('settings/gist-access-token') |
|
|
|
|
const files = await fetchDirectoryContent(name) |
|
|
|
|
const actions = [{ |
|
|
|
|
id: 'newFile', |
|
|
|
|
name: 'New File', |
|
|
|
|
type: ['folder'], |
|
|
|
|
path: [], |
|
|
|
|
extension: [], |
|
|
|
|
pattern: [] |
|
|
|
|
}, { |
|
|
|
|
id: 'newFolder', |
|
|
|
|
name: 'New Folder', |
|
|
|
|
type: ['folder'], |
|
|
|
|
path: [], |
|
|
|
|
extension: [], |
|
|
|
|
pattern: [] |
|
|
|
|
}, { |
|
|
|
|
id: 'rename', |
|
|
|
|
name: 'Rename', |
|
|
|
|
type: ['file', 'folder'], |
|
|
|
|
path: [], |
|
|
|
|
extension: [], |
|
|
|
|
pattern: [] |
|
|
|
|
}, { |
|
|
|
|
id: 'delete', |
|
|
|
|
name: 'Delete', |
|
|
|
|
type: ['file', 'folder'], |
|
|
|
|
path: [], |
|
|
|
|
extension: [], |
|
|
|
|
pattern: [] |
|
|
|
|
}, { |
|
|
|
|
id: 'pushChangesToGist', |
|
|
|
|
name: 'Push changes to gist', |
|
|
|
|
type: [], |
|
|
|
|
path: [], |
|
|
|
|
extension: [], |
|
|
|
|
pattern: ['^browser/gists/([0-9]|[a-z])*$'] |
|
|
|
|
}, { |
|
|
|
|
id: 'run', |
|
|
|
|
name: 'Run', |
|
|
|
|
type: [], |
|
|
|
|
path: [], |
|
|
|
@ -165,6 +171,17 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
} |
|
|
|
|
}, [focusRoot]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
if (contextMenuItems) { |
|
|
|
|
setState(prevState => { |
|
|
|
|
// filter duplicate items
|
|
|
|
|
const items = contextMenuItems.filter(({ name }) => prevState.actions.findIndex(action => action.name === name) === -1) |
|
|
|
|
|
|
|
|
|
return { ...prevState, actions: [...prevState.actions, ...items] } |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, [contextMenuItems]) |
|
|
|
|
|
|
|
|
|
const resolveDirectory = async (folderPath, dir: File[], isChild = false): Promise<File[]> => { |
|
|
|
|
if (!isChild && (state.focusEdit.element === 'browser/blank') && state.focusEdit.isNew && (dir.findIndex(({ path }) => path === 'browser/blank') === -1)) { |
|
|
|
|
dir = state.focusEdit.type === 'file' ? [...dir, { |
|
|
|
@ -603,6 +620,10 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const emitContextMenuEvent = (id: string, path: string) => { |
|
|
|
|
plugin.emit(id, path) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleHideModal = () => { |
|
|
|
|
setState(prevState => { |
|
|
|
|
return { ...prevState, modalOptions: { ...state.modalOptions, hide: true } } |
|
|
|
@ -839,6 +860,7 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
deletePath={deletePath} |
|
|
|
|
renamePath={editModeOn} |
|
|
|
|
publishToGist={publishToGist} |
|
|
|
|
emit={emitContextMenuEvent} |
|
|
|
|
pageX={state.focusContext.x} |
|
|
|
|
pageY={state.focusContext.y} |
|
|
|
|
path={file.path} |
|
|
|
@ -875,6 +897,7 @@ export const FileExplorer = (props: FileExplorerProps) => { |
|
|
|
|
deletePath={deletePath} |
|
|
|
|
renamePath={editModeOn} |
|
|
|
|
runScript={runScript} |
|
|
|
|
emit={emitContextMenuEvent} |
|
|
|
|
pageX={state.focusContext.x} |
|
|
|
|
pageY={state.focusContext.y} |
|
|
|
|
path={file.path} |
|
|
|
|