Commit c04cedd8 authored by ioedeveloper's avatar ioedeveloper

Implemented requested changes in PR comments

parent a02581f5
...@@ -456,32 +456,26 @@ class FileManager extends Plugin { ...@@ -456,32 +456,26 @@ class FileManager extends Plugin {
return this._deps.config.get('currentFile') return this._deps.config.get('currentFile')
} }
closeAllFiles () { async closeAllFiles () {
// TODO: Only keep `this.emit` (issue#2210) // TODO: Only keep `this.emit` (issue#2210)
return new Promise((resolve) => { this.emit('filesAllClosed')
this.emit('filesAllClosed') this.events.emit('filesAllClosed')
this.events.emit('filesAllClosed') for (const file in this.openedFiles) {
for (const file in this.openedFiles) { this.closeFile(file)
this.closeFile(file) }
}
resolve(true)
})
} }
closeFile (name) { async closeFile (name) {
return new Promise((resolve) => { delete this.openedFiles[name]
delete this.openedFiles[name] if (!Object.keys(this.openedFiles).length) {
if (!Object.keys(this.openedFiles).length) { this._deps.config.set('currentFile', '')
this._deps.config.set('currentFile', '')
// TODO: Only keep `this.emit` (issue#2210)
this.emit('noFileSelected')
this.events.emit('noFileSelected')
}
// TODO: Only keep `this.emit` (issue#2210) // TODO: Only keep `this.emit` (issue#2210)
this.emit('fileClosed', name) this.emit('noFileSelected')
this.events.emit('fileClosed', name) this.events.emit('noFileSelected')
resolve(true) }
}) // TODO: Only keep `this.emit` (issue#2210)
this.emit('fileClosed', name)
this.events.emit('fileClosed', name)
} }
currentPath () { currentPath () {
......
...@@ -54,7 +54,7 @@ module.exports = class Filepanel extends ViewPlugin { ...@@ -54,7 +54,7 @@ module.exports = class Filepanel extends ViewPlugin {
this.slitherHandle = new SlitherHandle() this.slitherHandle = new SlitherHandle()
this.workspaces = [] this.workspaces = []
this.appManager = appManager this.appManager = appManager
this.currentWorkspaceInfo = {} this.currentWorkspaceMetadata = {}
} }
onActivation () { onActivation () {
...@@ -84,7 +84,7 @@ module.exports = class Filepanel extends ViewPlugin { ...@@ -84,7 +84,7 @@ module.exports = class Filepanel extends ViewPlugin {
} }
getCurrentWorkspace () { getCurrentWorkspace () {
return this.currentWorkspaceInfo return this.currentWorkspaceMetadata
} }
getWorkspaces () { getWorkspaces () {
...@@ -120,7 +120,7 @@ module.exports = class Filepanel extends ViewPlugin { ...@@ -120,7 +120,7 @@ module.exports = class Filepanel extends ViewPlugin {
setWorkspace (workspace) { setWorkspace (workspace) {
const workspaceProvider = this.fileProviders.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) { workspaceDeleted (workspace) {
......
...@@ -11,31 +11,31 @@ export const listenOnPluginEvents = (filePanelPlugin) => { ...@@ -11,31 +11,31 @@ export const listenOnPluginEvents = (filePanelPlugin) => {
plugin = filePanelPlugin plugin = filePanelPlugin
plugin.on('filePanel', 'createWorkspace', (name: string) => { plugin.on('filePanel', 'createWorkspace', (name: string) => {
setTimeout(() => createWorkspace(name), 10) createWorkspace(name)
}) })
plugin.on('filePanel', 'renameWorkspace', (oldName: string, workspaceName: string) => { plugin.on('filePanel', 'renameWorkspace', (oldName: string, workspaceName: string) => {
setTimeout(() => renameWorkspace(oldName, workspaceName), 10) renameWorkspace(oldName, workspaceName)
}) })
plugin.on('filePanel', 'registerContextMenuItem', (item: action) => { plugin.on('filePanel', 'registerContextMenuItem', (item: action) => {
setTimeout(() => registerContextMenuItem(item), 10) registerContextMenuItem(item)
}) })
plugin.on('filePanel', 'removePluginActions', (plugin) => { plugin.on('filePanel', 'removePluginActions', (plugin) => {
setTimeout(() => removePluginActions(plugin), 10) removePluginActions(plugin)
}) })
plugin.on('filePanel', 'displayNewFileInput', (path) => { plugin.on('filePanel', 'displayNewFileInput', (path) => {
setTimeout(() => addInputField('file', path), 10) addInputField('file', path)
}) })
plugin.on('filePanel', 'uploadFileEvent', (dir: string, target) => { plugin.on('filePanel', 'uploadFileEvent', (dir: string, target) => {
setTimeout(() => uploadFile(target, dir), 10) uploadFile(target, dir)
}) })
plugin.on('remixd', 'rootFolderChanged', async (path: string) => { plugin.on('remixd', 'rootFolderChanged', async (path: string) => {
setTimeout(() => rootFolderChanged(path), 10) rootFolderChanged(path)
}) })
} }
...@@ -43,74 +43,66 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp ...@@ -43,74 +43,66 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
dispatch = reducerDispatch dispatch = reducerDispatch
provider.event.on('fileAdded', (filePath: string) => { provider.event.on('fileAdded', (filePath: string) => {
setTimeout(() => fileAdded(filePath), 10) fileAdded(filePath)
}) })
provider.event.on('folderAdded', (folderPath: string) => { provider.event.on('folderAdded', (folderPath: string) => {
if (folderPath.indexOf('/.workspaces') === 0) return if (folderPath.indexOf('/.workspaces') === 0) return
setTimeout(() => folderAdded(folderPath), 10) folderAdded(folderPath)
}) })
provider.event.on('fileRemoved', (removePath: string) => { provider.event.on('fileRemoved', (removePath: string) => {
setTimeout(() => fileRemoved(removePath), 10) fileRemoved(removePath)
}) })
provider.event.on('fileRenamed', (oldPath: string) => { provider.event.on('fileRenamed', (oldPath: string) => {
setTimeout(() => fileRenamed(oldPath), 10) fileRenamed(oldPath)
}) })
provider.event.on('disconnected', () => { provider.event.on('disconnected', async () => {
setTimeout(async () => { plugin.fileManager.setMode('browser')
plugin.fileManager.setMode('browser') dispatch(setMode('browser'))
dispatch(setMode('browser')) dispatch(loadLocalhostError('Remixd disconnected!'))
dispatch(loadLocalhostError('Remixd disconnected!')) const workspaceProvider = plugin.fileProviders.workspace
const workspaceProvider = plugin.fileProviders.workspace
await switchToWorkspace(workspaceProvider.workspace) await switchToWorkspace(workspaceProvider.workspace)
}, 10)
}) })
provider.event.on('connected', () => { provider.event.on('connected', () => {
setTimeout(() => { plugin.fileManager.setMode('localhost')
plugin.fileManager.setMode('localhost') dispatch(setMode('localhost'))
dispatch(setMode('localhost')) fetchWorkspaceDirectory('/')
fetchWorkspaceDirectory('/') dispatch(loadLocalhostSuccess())
dispatch(loadLocalhostSuccess())
}, 10)
}) })
provider.event.on('loadingLocalhost', () => { provider.event.on('loadingLocalhost', async () => {
setTimeout(async () => { await switchToWorkspace(LOCALHOST)
await switchToWorkspace(LOCALHOST) dispatch(loadLocalhostRequest())
dispatch(loadLocalhostRequest())
}, 10)
}) })
provider.event.on('fileExternallyChanged', (path: string, content: string) => { provider.event.on('fileExternallyChanged', (path: string, content: string) => {
setTimeout(() => { const config = plugin.registry.get('config').api
const config = plugin.registry.get('config').api const editor = plugin.registry.get('editor').api
const editor = plugin.registry.get('editor').api
if (config.get('currentFile') === path && editor.currentContent() !== content) {
if (config.get('currentFile') === path && editor.currentContent() !== content) { if (provider.isReadOnly(path)) return editor.setText(content)
if (provider.isReadOnly(path)) return editor.setText(content) dispatch(displayNotification(
dispatch(displayNotification( path + ' changed',
path + ' changed', 'This file has been changed outside of Remix IDE.',
'This file has been changed outside of Remix IDE.', 'Replace by the new content', 'Keep the content displayed in Remix',
'Replace by the new content', 'Keep the content displayed in Remix', () => {
() => { editor.setText(content)
editor.setText(content) }
} ))
)) }
}
}, 10)
}) })
provider.event.on('fileRenamedError', () => { 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) => { 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) => { ...@@ -214,7 +214,6 @@ export const copyFile = async (src: string, dest: string) => {
try { try {
fileManager.copyFile(src, dest) fileManager.copyFile(src, dest)
} catch (error) { } catch (error) {
console.log('Oops! An error ocurred while performing copyFile operation.' + error)
dispatch(displayPopUp('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) => { ...@@ -225,7 +224,6 @@ export const copyFolder = async (src: string, dest: string) => {
try { try {
fileManager.copyDir(src, dest) fileManager.copyDir(src, dest)
} catch (error) { } catch (error) {
console.log('Oops! An error ocurred while performing copyDir operation.' + error)
dispatch(displayPopUp('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) => { ...@@ -235,8 +233,7 @@ export const runScript = async (path: string) => {
provider.get(path, (error, content: string) => { provider.get(path, (error, content: string) => {
if (error) { if (error) {
dispatch(displayPopUp(error)) return dispatch(displayPopUp(error))
return console.log(error)
} }
plugin.call('scriptRunner', 'execute', content) plugin.call('scriptRunner', 'execute', content)
}) })
...@@ -282,12 +279,11 @@ const getWorkspaces = async (): Promise<string[]> | undefined => { ...@@ -282,12 +279,11 @@ const getWorkspaces = async (): Promise<string[]> | undefined => {
plugin.setWorkspaces(workspaces) plugin.setWorkspaces(workspaces)
return workspaces return workspaces
} catch (e) { } 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) console.log(e)
} }
} }
const packageGistFiles = async (directory) => { const packageGistFiles = (directory) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const workspaceProvider = plugin.fileProviders.workspace const workspaceProvider = plugin.fileProviders.workspace
const isFile = workspaceProvider.isFile(directory) const isFile = workspaceProvider.isFile(directory)
......
...@@ -19,9 +19,9 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => { ...@@ -19,9 +19,9 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => {
export const addInputField = async (type: 'file' | 'folder', path: string) => { export const addInputField = async (type: 'file' | 'folder', path: string) => {
const provider = plugin.fileManager.currentFileProvider() const provider = plugin.fileManager.currentFileProvider()
const promise = new Promise((resolve) => { const promise = new Promise((resolve, reject) => {
provider.resolveDirectory(path, (error, fileTree) => { provider.resolveDirectory(path, (error, fileTree) => {
if (error) console.error(error) if (error) reject(error)
resolve(fileTree) resolve(fileTree)
}) })
...@@ -216,8 +216,7 @@ export const uploadFile = async (target, targetFolder: string) => { ...@@ -216,8 +216,7 @@ export const uploadFile = async (target, targetFolder: string) => {
fileReader.onload = async function (event) { fileReader.onload = async function (event) {
if (checkSpecialChars(file.name)) { if (checkSpecialChars(file.name)) {
dispatch(displayNotification('File Upload Failed', 'Special characters are not allowed', 'Close', null, async () => {})) return dispatch(displayNotification('File Upload Failed', 'Special characters are not allowed', 'Close', null, async () => {}))
return
} }
const success = await workspaceProvider.set(name, event.target.result) const success = await workspaceProvider.set(name, event.target.result)
......
...@@ -320,14 +320,14 @@ export const FileExplorer = (props: FileExplorerProps) => { ...@@ -320,14 +320,14 @@ export const FileExplorer = (props: FileExplorerProps) => {
if (state.focusEdit.isNew) { if (state.focusEdit.isNew) {
if (hasReservedKeyword(content)) { if (hasReservedKeyword(content)) {
props.dispatchRemoveInputField(parentFolder) 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 { } else {
state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content)) state.focusEdit.type === 'file' ? createNewFile(joinPath(parentFolder, content)) : createNewFolder(joinPath(parentFolder, content))
props.dispatchRemoveInputField(parentFolder) props.dispatchRemoveInputField(parentFolder)
} }
} else { } else {
if (hasReservedKeyword(content)) { 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 { } else {
if (state.focusEdit.element) { if (state.focusEdit.element) {
const oldPath: string = state.focusEdit.element const oldPath: string = state.focusEdit.element
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment