Merge pull request #1392 from ethereum/clt

close files on folder close
pull/1399/head^2
bunsenstraat 3 years ago committed by GitHub
commit d3626ccde1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      apps/remix-ide/src/app/files/fileManager.js
  2. 3
      apps/remix-ide/src/app/files/remixDProvider.js
  3. 1
      apps/remix-ide/src/app/panels/tab-proxy.js
  4. 2
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
  5. 1
      libs/remix-ui/solidity-compiler/src/lib/css/style.css
  6. 34
      libs/remixd/src/services/remixdClient.ts

@ -155,9 +155,9 @@ class FileManager extends Plugin {
* @param {string} path path of the directory * @param {string} path path of the directory
* @returns {boolean} true if path is a directory. * @returns {boolean} true if path is a directory.
*/ */
isDirectory (path) { async isDirectory (path) {
const provider = this.fileProviderOf(path) const provider = this.fileProviderOf(path)
const result = provider.isDirectory(path) const result = await provider.isDirectory(path)
return result return result
} }
@ -362,7 +362,6 @@ class FileManager extends Plugin {
path = this.limitPluginScope(path) path = this.limitPluginScope(path)
await this._handleExists(path, `Cannot remove file or directory ${path}`) await this._handleExists(path, `Cannot remove file or directory ${path}`)
const provider = this.fileProviderOf(path) const provider = this.fileProviderOf(path)
return await provider.remove(path) return await provider.remove(path)
} catch (e) { } catch (e) {
throw new Error(e) throw new Error(e)

@ -38,7 +38,7 @@ module.exports = class RemixDProvider extends FileProvider {
}) })
this._appManager.on('remixd', 'fileRenamed', (oldPath, newPath) => { this._appManager.on('remixd', 'fileRenamed', (oldPath, newPath) => {
this.event.emit('fileRemoved', oldPath, newPath) this.event.emit('fileRenamed', oldPath, newPath)
}) })
this._appManager.on('remixd', 'rootFolderChanged', () => { this._appManager.on('remixd', 'rootFolderChanged', () => {
@ -141,7 +141,6 @@ module.exports = class RemixDProvider extends FileProvider {
this._appManager.call('remixd', 'remove', { path: unprefixedpath }) this._appManager.call('remixd', 'remove', { path: unprefixedpath })
.then(result => { .then(result => {
const path = unprefixedpath const path = unprefixedpath
delete this.filesContent[path] delete this.filesContent[path]
resolve(true) resolve(true)
this.init() this.init()

@ -44,7 +44,6 @@ export class TabProxy extends Plugin {
fileManager.events.on('fileRemoved', (name) => { fileManager.events.on('fileRemoved', (name) => {
const workspace = this.fileManager.currentWorkspace() const workspace = this.fileManager.currentWorkspace()
workspace ? this.removeTab(workspace + '/' + name) : this.removeTab(this.fileManager.mode + '/' + name) workspace ? this.removeTab(workspace + '/' + name) : this.removeTab(this.fileManager.mode + '/' + name)
}) })

@ -408,7 +408,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
try { try {
await fileManager.remove(p) await fileManager.remove(p)
} catch (e) { } catch (e) {
const isDir = state.fileManager.isDirectory(p) const isDir = await state.fileManager.isDirectory(p)
toast(`Failed to remove ${isDir ? 'folder' : 'file'} ${p}.`) toast(`Failed to remove ${isDir ? 'folder' : 'file'} ${p}.`)
} }
} }

@ -103,7 +103,6 @@
} }
.remixui_container { .remixui_container {
margin: 0; margin: 0;
margin-bottom: 2%;
} }
.remixui_optimizeContainer { .remixui_optimizeContainer {
display: flex; display: flex;

@ -180,12 +180,34 @@ export class RemixdClient extends PluginClient {
if (!fs.existsSync(path)) return reject(new Error('File not found ' + path)) if (!fs.existsSync(path)) return reject(new Error('File not found ' + path))
if (!isRealPath(path)) return if (!isRealPath(path)) return
// Saving the content of the item{folder} before removing it
const ls = []
try {
const resolveList = (path) => {
if (!this._isFile(path)) {
const list = utils.resolveDirectory(path, this.currentSharedFolder)
Object.keys(list).forEach(itemPath => {
if (list[itemPath].isDirectory) {
resolveList(`${this.currentSharedFolder}/${itemPath}`)
}
ls.push(itemPath)
})
}
}
resolveList(path)
ls.push(args.path)
} catch (e) {
throw new Error(e)
}
return fs.remove(path, (error: Error) => { return fs.remove(path, (error: Error) => {
if (error) { if (error) {
console.log(error) console.log(error)
return reject(new Error('Failed to remove file/directory: ' + error)) return reject(new Error('Failed to remove file/directory: ' + error))
} }
this.emit('fileRemoved', args.path) for (const file in ls) {
this.emit('fileRemoved', ls[file])
}
resolve(true) resolve(true)
}) })
}) })
@ -194,10 +216,17 @@ export class RemixdClient extends PluginClient {
} }
} }
_isFile (path: string): boolean {
try {
return fs.statSync(path).isFile()
} catch (error) {
throw new Error(error)
}
}
isDirectory (args: SharedFolderArgs): boolean { isDirectory (args: SharedFolderArgs): boolean {
try { try {
const path = utils.absolutePath(args.path, this.currentSharedFolder) const path = utils.absolutePath(args.path, this.currentSharedFolder)
return fs.statSync(path).isDirectory() return fs.statSync(path).isDirectory()
} catch (error) { } catch (error) {
throw new Error(error) throw new Error(error)
@ -207,7 +236,6 @@ export class RemixdClient extends PluginClient {
isFile (args: SharedFolderArgs): boolean { isFile (args: SharedFolderArgs): boolean {
try { try {
const path = utils.absolutePath(args.path, this.currentSharedFolder) const path = utils.absolutePath(args.path, this.currentSharedFolder)
return fs.statSync(path).isFile() return fs.statSync(path).isFile()
} catch (error) { } catch (error) {
throw new Error(error) throw new Error(error)

Loading…
Cancel
Save