Implemented requested changes in PR comments

pull/5370/head
ioedeveloper 3 years ago
parent 2c7af91f8f
commit 4b3dec02a9
  1. 38
      apps/remix-ide/src/app/files/fileManager.js
  2. 6
      apps/remix-ide/src/app/panels/file-panel.js
  3. 88
      libs/remix-ui/workspace/src/lib/actions/events.ts
  4. 8
      libs/remix-ui/workspace/src/lib/actions/index.ts
  5. 7
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  6. 4
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx

@ -456,32 +456,26 @@ class FileManager extends Plugin {
return this._deps.config.get('currentFile')
}
closeAllFiles () {
async closeAllFiles () {
// TODO: Only keep `this.emit` (issue#2210)
return new Promise((resolve) => {
this.emit('filesAllClosed')
this.events.emit('filesAllClosed')
for (const file in this.openedFiles) {
this.closeFile(file)
}
resolve(true)
})
this.emit('filesAllClosed')
this.events.emit('filesAllClosed')
for (const file in this.openedFiles) {
this.closeFile(file)
}
}
closeFile (name) {
return new Promise((resolve) => {
delete this.openedFiles[name]
if (!Object.keys(this.openedFiles).length) {
this._deps.config.set('currentFile', '')
// TODO: Only keep `this.emit` (issue#2210)
this.emit('noFileSelected')
this.events.emit('noFileSelected')
}
async closeFile (name) {
delete this.openedFiles[name]
if (!Object.keys(this.openedFiles).length) {
this._deps.config.set('currentFile', '')
// TODO: Only keep `this.emit` (issue#2210)
this.emit('fileClosed', name)
this.events.emit('fileClosed', name)
resolve(true)
})
this.emit('noFileSelected')
this.events.emit('noFileSelected')
}
// TODO: Only keep `this.emit` (issue#2210)
this.emit('fileClosed', name)
this.events.emit('fileClosed', name)
}
currentPath () {

@ -54,7 +54,7 @@ module.exports = class Filepanel extends ViewPlugin {
this.slitherHandle = new SlitherHandle()
this.workspaces = []
this.appManager = appManager
this.currentWorkspaceInfo = {}
this.currentWorkspaceMetadata = {}
}
onActivation () {
@ -84,7 +84,7 @@ module.exports = class Filepanel extends ViewPlugin {
}
getCurrentWorkspace () {
return this.currentWorkspaceInfo
return this.currentWorkspaceMetadata
}
getWorkspaces () {
@ -120,7 +120,7 @@ module.exports = class Filepanel extends ViewPlugin {
setWorkspace (workspace) {
const workspaceProvider = this.fileProviders.workspace
this.currentWorkspaceInfo = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` }
this.currentWorkspaceMetadata = { name: workspace.name, isLocalhost: workspace.isLocalhost, absolutePath: `${workspaceProvider.workspacesPath}/${workspace.name}` }
}
workspaceDeleted (workspace) {

@ -11,31 +11,31 @@ export const listenOnPluginEvents = (filePanelPlugin) => {
plugin = filePanelPlugin
plugin.on('filePanel', 'createWorkspace', (name: string) => {
setTimeout(() => createWorkspace(name), 10)
createWorkspace(name)
})
plugin.on('filePanel', 'renameWorkspace', (oldName: string, workspaceName: string) => {
setTimeout(() => renameWorkspace(oldName, workspaceName), 10)
renameWorkspace(oldName, workspaceName)
})
plugin.on('filePanel', 'registerContextMenuItem', (item: action) => {
setTimeout(() => registerContextMenuItem(item), 10)
registerContextMenuItem(item)
})
plugin.on('filePanel', 'removePluginActions', (plugin) => {
setTimeout(() => removePluginActions(plugin), 10)
removePluginActions(plugin)
})
plugin.on('filePanel', 'displayNewFileInput', (path) => {
setTimeout(() => addInputField('file', path), 10)
addInputField('file', path)
})
plugin.on('filePanel', 'uploadFileEvent', (dir: string, target) => {
setTimeout(() => uploadFile(target, dir), 10)
uploadFile(target, dir)
})
plugin.on('remixd', 'rootFolderChanged', async (path: string) => {
setTimeout(() => rootFolderChanged(path), 10)
rootFolderChanged(path)
})
}
@ -43,74 +43,66 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
dispatch = reducerDispatch
provider.event.on('fileAdded', (filePath: string) => {
setTimeout(() => fileAdded(filePath), 10)
fileAdded(filePath)
})
provider.event.on('folderAdded', (folderPath: string) => {
if (folderPath.indexOf('/.workspaces') === 0) return
setTimeout(() => folderAdded(folderPath), 10)
folderAdded(folderPath)
})
provider.event.on('fileRemoved', (removePath: string) => {
setTimeout(() => fileRemoved(removePath), 10)
fileRemoved(removePath)
})
provider.event.on('fileRenamed', (oldPath: string) => {
setTimeout(() => fileRenamed(oldPath), 10)
fileRenamed(oldPath)
})
provider.event.on('disconnected', () => {
setTimeout(async () => {
plugin.fileManager.setMode('browser')
dispatch(setMode('browser'))
dispatch(loadLocalhostError('Remixd disconnected!'))
const workspaceProvider = plugin.fileProviders.workspace
provider.event.on('disconnected', async () => {
plugin.fileManager.setMode('browser')
dispatch(setMode('browser'))
dispatch(loadLocalhostError('Remixd disconnected!'))
const workspaceProvider = plugin.fileProviders.workspace
await switchToWorkspace(workspaceProvider.workspace)
}, 10)
await switchToWorkspace(workspaceProvider.workspace)
})
provider.event.on('connected', () => {
setTimeout(() => {
plugin.fileManager.setMode('localhost')
dispatch(setMode('localhost'))
fetchWorkspaceDirectory('/')
dispatch(loadLocalhostSuccess())
}, 10)
plugin.fileManager.setMode('localhost')
dispatch(setMode('localhost'))
fetchWorkspaceDirectory('/')
dispatch(loadLocalhostSuccess())
})
provider.event.on('loadingLocalhost', () => {
setTimeout(async () => {
await switchToWorkspace(LOCALHOST)
dispatch(loadLocalhostRequest())
}, 10)
provider.event.on('loadingLocalhost', async () => {
await switchToWorkspace(LOCALHOST)
dispatch(loadLocalhostRequest())
})
provider.event.on('fileExternallyChanged', (path: string, content: string) => {
setTimeout(() => {
const config = plugin.registry.get('config').api
const editor = plugin.registry.get('editor').api
if (config.get('currentFile') === path && editor.currentContent() !== content) {
if (provider.isReadOnly(path)) return editor.setText(content)
dispatch(displayNotification(
path + ' changed',
'This file has been changed outside of Remix IDE.',
'Replace by the new content', 'Keep the content displayed in Remix',
() => {
editor.setText(content)
}
))
}
}, 10)
const config = plugin.registry.get('config').api
const editor = plugin.registry.get('editor').api
if (config.get('currentFile') === path && editor.currentContent() !== content) {
if (provider.isReadOnly(path)) return editor.setText(content)
dispatch(displayNotification(
path + ' changed',
'This file has been changed outside of Remix IDE.',
'Replace by the new content', 'Keep the content displayed in Remix',
() => {
editor.setText(content)
}
))
}
})
provider.event.on('fileRenamedError', () => {
setTimeout(() => dispatch(displayNotification('File Renamed Failed', '', 'Ok', 'Cancel')), 10)
dispatch(displayNotification('File Renamed Failed', '', 'Ok', 'Cancel'))
})
provider.event.on('readOnlyModeChanged', (mode: boolean) => {
setTimeout(() => dispatch(setReadOnlyMode(mode)), 10)
dispatch(setReadOnlyMode(mode))
})
}

@ -214,7 +214,6 @@ export const copyFile = async (src: string, dest: string) => {
try {
fileManager.copyFile(src, dest)
} catch (error) {
console.log('Oops! An error ocurred while performing copyFile operation.' + error)
dispatch(displayPopUp('Oops! An error ocurred while performing copyFile operation.' + error))
}
}
@ -225,7 +224,6 @@ export const copyFolder = async (src: string, dest: string) => {
try {
fileManager.copyDir(src, dest)
} catch (error) {
console.log('Oops! An error ocurred while performing copyDir operation.' + error)
dispatch(displayPopUp('Oops! An error ocurred while performing copyDir operation.' + error))
}
}
@ -235,8 +233,7 @@ export const runScript = async (path: string) => {
provider.get(path, (error, content: string) => {
if (error) {
dispatch(displayPopUp(error))
return console.log(error)
return dispatch(displayPopUp(error))
}
plugin.call('scriptRunner', 'execute', content)
})
@ -282,12 +279,11 @@ const getWorkspaces = async (): Promise<string[]> | undefined => {
plugin.setWorkspaces(workspaces)
return workspaces
} catch (e) {
// dispatch(displayNotification('Workspaces', 'Workspaces have not been created on your system. Please use "Migrate old filesystem to workspace" on the home page to transfer your files or start by creating a new workspace in the File Explorers.', 'OK', null, () => { dispatch(hideNotification()) }, null))
console.log(e)
}
}
const packageGistFiles = async (directory) => {
const packageGistFiles = (directory) => {
return new Promise((resolve, reject) => {
const workspaceProvider = plugin.fileProviders.workspace
const isFile = workspaceProvider.isFile(directory)

@ -19,9 +19,9 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => {
export const addInputField = async (type: 'file' | 'folder', path: string) => {
const provider = plugin.fileManager.currentFileProvider()
const promise = new Promise((resolve) => {
const promise = new Promise((resolve, reject) => {
provider.resolveDirectory(path, (error, fileTree) => {
if (error) console.error(error)
if (error) reject(error)
resolve(fileTree)
})
@ -216,8 +216,7 @@ export const uploadFile = async (target, targetFolder: string) => {
fileReader.onload = async function (event) {
if (checkSpecialChars(file.name)) {
dispatch(displayNotification('File Upload Failed', 'Special characters are not allowed', 'Close', null, async () => {}))
return
return dispatch(displayNotification('File Upload Failed', 'Special characters are not allowed', 'Close', null, async () => {}))
}
const success = await workspaceProvider.set(name, event.target.result)

@ -320,14 +320,14 @@ export const FileExplorer = (props: FileExplorerProps) => {
if (state.focusEdit.isNew) {
if (hasReservedKeyword(content)) {
props.dispatchRemoveInputField(parentFolder)
props.modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, 'Close', () => {})
props.modal('Reserved Keyword', `File name contains Remix reserved keywords. '${content}'`, 'Close', () => {})
} else {
state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content))
props.dispatchRemoveInputField(parentFolder)
}
} else {
if (hasReservedKeyword(content)) {
props.modal('Reserved Keyword', `File name contains remix reserved keywords. '${content}'`, 'Close', () => {})
props.modal('Reserved Keyword', `File name contains Remix reserved keywords. '${content}'`, 'Close', () => {})
} else {
if (state.focusEdit.element) {
const oldPath: string = state.focusEdit.element

Loading…
Cancel
Save