Implement copyFile

pull/5370/head
ioedeveloper 4 years ago
parent 1252d7df6c
commit dea284635c
  1. 10
      apps/remix-ide/src/app/files/fileManager.js
  2. 2
      libs/remix-ui/file-explorer/src/lib/file-explorer-context-menu.tsx
  3. 24
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
  4. 2
      libs/remix-ui/file-explorer/src/lib/types/index.ts

@ -217,12 +217,14 @@ class FileManager extends Plugin {
try {
src = this.limitPluginScope(src)
dest = this.limitPluginScope(dest)
await this._handleExists(src, `Cannot copy from ${src}`)
await this._handleIsFile(src, `Cannot copy from ${src}`)
await this._handleIsFile(dest, `Cannot paste content into ${dest}`)
await this._handleExists(src, `Cannot copy from ${src}. Path does not exist.`)
await this._handleIsFile(src, `Cannot copy from ${src}. Path is not a file.`)
await this._handleExists(dest, `Cannot paste content into ${dest}. Path does not exist.`)
await this._handleIsDir(dest, `Cannot paste content into ${dest}. Path is not directory.`)
const content = await this.readFile(src)
const copiedFileName = `/Copy_${src.split('/')[src.split('/').length - 1]}`
await this.writeFile(dest, content)
await this.writeFile(dest + copiedFileName, content)
} catch (e) {
throw new Error(e)
}

@ -65,7 +65,7 @@ export const FileExplorerContextMenu = (props: FileExplorerContextMenuProps) =>
copy(path, type)
break
case 'Paste':
paste(path)
paste(path, type)
break
default:
emit && emit(item.id, path)

@ -121,7 +121,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
reservedKeywords: [name, 'gist-'],
copyElement: []
})
const [canPaste, setcanPaste] = useState(false)
const [canPaste, setCanPaste] = useState(false)
const [fileSystem, dispatch] = useReducer(fileSystemReducer, fileSystemInitialState)
const editRef = useRef(null)
@ -413,6 +413,16 @@ export const FileExplorer = (props: FileExplorerProps) => {
})
}
const copyFile = (src: string, dest: string) => {
const fileManager = state.fileManager
try {
fileManager.copyFile(src, dest)
} catch (error) {
console.log('Oops! An error ocurred while performing copyFile operation.' + error)
}
}
const publishToGist = (path?: string, type?: string) => {
modal('Create a public gist', `Are you sure you want to anonymously publish all your files in the ${name} workspace as a public gist on github.com?`, 'OK', () => toGist(path, type), 'Cancel', () => {})
}
@ -734,15 +744,19 @@ export const FileExplorer = (props: FileExplorerProps) => {
setState(prevState => {
return { ...prevState, copyElement: [...prevState.copyElement, { key: path, type }] }
})
setcanPaste(true)
setCanPaste(true)
toast('Copied to clipboard')
}
const handlePasteClick = (dest: string) => {
console.log('destination: ', dest)
const handlePasteClick = (dest: string, destType: string) => {
dest = destType === 'file' ? extractParentFromKey(dest) || props.name : dest
state.copyElement.map(({ key, type }) => {
type === 'file' ? copyFile(key, dest) : copyFile(key, dest)
})
setState(prevState => {
return { ...prevState, copyElement: [] }
})
setcanPaste(false)
setCanPaste(false)
}
const label = (file: File) => {

@ -48,5 +48,5 @@ export interface FileExplorerContextMenuProps {
type: string,
onMouseOver?: (...args) => void,
copy?: (path: string, type: string) => void
paste?: (destination: string) => void
paste?: (destination: string, type: string) => void
}

Loading…
Cancel
Save