From bd07c52526cc5e23ce01620236ac148abb039873 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 12 Apr 2021 21:18:20 +0200 Subject: [PATCH] Close all tabs when workspace changes (#1105) fix https://github.com/ethereum/remix-project/issues/989 --- apps/remix-ide/src/app.js | 2 +- apps/remix-ide/src/app/files/fileManager.js | 9 +++++++++ apps/remix-ide/src/app/panels/file-panel.js | 2 +- apps/remix-ide/src/app/panels/tab-proxy.js | 5 +++++ libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx | 6 +++--- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index ce1919451a..eedcf7d778 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -450,7 +450,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org } await appManager.activatePlugin(['contentImport', 'theme', 'editor', 'fileManager', 'compilerMetadata', 'compilerArtefacts', 'network', 'web3Provider', 'offsetToLineColumnConverter']) - await appManager.activatePlugin(['mainPanel', 'menuicons']) + await appManager.activatePlugin(['mainPanel', 'menuicons', 'tabs']) await appManager.activatePlugin(['sidePanel']) // activating host plugin separately await appManager.activatePlugin(['home']) await appManager.activatePlugin(['hiddenPanel', 'pluginManager', 'fileExplorers', 'settings', 'contextualListener', 'terminal', 'fetchAndCompile']) diff --git a/apps/remix-ide/src/app/files/fileManager.js b/apps/remix-ide/src/app/files/fileManager.js index b1a3bdf914..932368c20b 100644 --- a/apps/remix-ide/src/app/files/fileManager.js +++ b/apps/remix-ide/src/app/files/fileManager.js @@ -398,6 +398,15 @@ class FileManager extends Plugin { return this._deps.config.get('currentFile') } + closeAllFiles () { + // TODO: Only keep `this.emit` (issue#2210) + this.emit('filesAllClosed') + this.events.emit('filesAllClosed') + for (const file in this.openedFiles) { + this.closeFile(file) + } + } + closeFile (name) { delete this.openedFiles[name] if (!Object.keys(this.openedFiles).length) { diff --git a/apps/remix-ide/src/app/panels/file-panel.js b/apps/remix-ide/src/app/panels/file-panel.js index bf5fd6ba05..7e44fc2520 100644 --- a/apps/remix-ide/src/app/panels/file-panel.js +++ b/apps/remix-ide/src/app/panels/file-panel.js @@ -225,7 +225,7 @@ module.exports = class Filepanel extends ViewPlugin { /** these are called by the react component, action is already finished whent it's called */ async setWorkspace (workspace) { - this._deps.fileManager.removeTabsOf(this._deps.fileProviders.workspace) + this._deps.fileManager.closeAllFiles() if (workspace.isLocalhost) { this.call('manager', 'activatePlugin', 'remixd') } else if (await this.call('manager', 'isActive', 'remixd')) { diff --git a/apps/remix-ide/src/app/panels/tab-proxy.js b/apps/remix-ide/src/app/panels/tab-proxy.js index 0bdef0c2ec..179a37065c 100644 --- a/apps/remix-ide/src/app/panels/tab-proxy.js +++ b/apps/remix-ide/src/app/panels/tab-proxy.js @@ -37,6 +37,11 @@ export class TabProxy extends Plugin { this.updateImgStyles() }) + fileManager.events.on('filesAllClosed', () => { + this.call('manager', 'activatePlugin', 'home') + this._view.filetabs.active = 'home' + }) + fileManager.events.on('fileRemoved', (name) => { const workspace = this.fileManager.currentWorkspace() diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index dbde392b20..79ff47d672 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -223,7 +223,7 @@ export const Workspace = (props: WorkspaceProps) => { } const setWorkspace = async (name) => { - props.setWorkspace({ name, isLocalhost: name === LOCALHOST }) + await props.setWorkspace({ name, isLocalhost: name === LOCALHOST }) if (name === LOCALHOST) { props.workspace.clearWorkspace() } else if (name === NO_WORKSPACE) { @@ -238,8 +238,8 @@ export const Workspace = (props: WorkspaceProps) => { } const remixdExplorer = { - hide: () => { - if (state.currentWorkspace === LOCALHOST) setWorkspace(NO_WORKSPACE) + hide: async () => { + await setWorkspace(NO_WORKSPACE) props.fileManager.setMode('browser') setState(prevState => { return { ...prevState, hideRemixdExplorer: true, loadingLocalhost: false }