diff --git a/ci/browser_tests.sh b/ci/browser_tests.sh index abae1828e9..aa7c886022 100755 --- a/ci/browser_tests.sh +++ b/ci/browser_tests.sh @@ -7,7 +7,7 @@ setupRemixd () { cd contracts echo 'sharing folder: ' echo $PWD - ./../node_modules/remixd/bin/remixd -s $PWD & + ./../node_modules/remixd/bin/remixd -s $PWD --remix-ide http://127.0.0.1:8080 & cd .. } diff --git a/src/app/editor/editor.js b/src/app/editor/editor.js index 8dcf48c6c9..c18e1d9efb 100644 --- a/src/app/editor/editor.js +++ b/src/app/editor/editor.js @@ -225,9 +225,8 @@ function Editor (opts = {}, localRegistry) { } this.discard = function (path) { - if (currentSession !== path) { - delete sessions[path] - } + if (sessions[path]) delete sessions[path] + if (currentSession === path) currentSession = null } this.resize = function (useWrapMode) { diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index 8b1eafc30d..730797076c 100644 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -39,6 +39,8 @@ function fileExplorer (localRegistry, files) { this.files.event.register('fileExternallyChanged', (path, file) => { if (self._deps.config.get('currentFile') === path && self._deps.editor.currentContent() && self._deps.editor.currentContent() !== file.content) { + if (this.files.isReadOnly(path)) return self._deps.editor.setText(file.content) + modalDialog(path + ' changed', remixdDialog(), { label: 'Keep the content displayed in Remix', diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 3bcdf045f3..5fe8f15846 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -40,6 +40,8 @@ class FileManager { self._deps.localhostExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) self._deps.configExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) self._deps.gistExplorer.event.register('fileRemoved', (path) => { this.fileRemovedEvent(path) }) + self._deps.localhostExplorer.event.register('errored', (event) => { this.removeTabsOf(self._deps.localhostExplorer) }) + self._deps.localhostExplorer.event.register('closed', (event) => { this.removeTabsOf(self._deps.localhostExplorer) }) } fileRenamedEvent (oldName, newName, isFolder) { @@ -92,12 +94,21 @@ class FileManager { return path ? path[1] : null } + removeTabsOf (provider) { + for (var tab in this.tabbedFiles) { + if (this.fileProviderOf(tab).type === provider.type) { + this.fileRemovedEvent(tab) + } + } + } + fileRemovedEvent (path) { var self = this + if (!this.tabbedFiles[path]) return if (path === self._deps.config.get('currentFile')) { self._deps.config.set('currentFile', '') } - self._deps.editor.discardCurrentSession() + self._deps.editor.discard(path) delete this.tabbedFiles[path] this.refreshTabs() this.switchFile() diff --git a/src/app/files/shared-folder.js b/src/app/files/shared-folder.js index bc3c57fb6a..98b833a67c 100644 --- a/src/app/files/shared-folder.js +++ b/src/app/files/shared-folder.js @@ -11,9 +11,17 @@ module.exports = class SharedFolder { this.error = { 'EEXIST': 'File already exists' } this._isReady = false this._readOnlyFiles = {} + this._readOnlyMode = false this.filesContent = {} this.files = {} + var remixdEvents = ['connecting', 'connected', 'errored', 'closed'] + remixdEvents.forEach((value) => { + remixd.event.register(value, (event) => { + this.event.trigger(value, [event]) + }) + }) + remixd.event.register('notified', (data) => { if (data.scope === 'sharedfolder') { if (data.name === 'created') { @@ -51,8 +59,12 @@ module.exports = class SharedFolder { init (cb) { this._remixd.ensureSocket((error) => { + if (error) return cb(error) this._isReady = !error - cb(error) + this._remixd.call('sharedfolder', 'folderIsReadOnly', {}, (error, result) => { + this._readOnlyMode = result + cb(error) + }) }) } @@ -103,7 +115,7 @@ module.exports = class SharedFolder { } isReadOnly (path) { - return this._readOnlyFiles[path] === 1 + return this._readOnlyMode || this._readOnlyFiles[path] === 1 } remove (path) { diff --git a/src/app/panels/editor-panel.js b/src/app/panels/editor-panel.js index 57ac7ad288..70e8bbfae0 100644 --- a/src/app/panels/editor-panel.js +++ b/src/app/panels/editor-panel.js @@ -205,7 +205,7 @@ class EditorPanel { if (Object.keys(self._deps.fileManager.tabbedFiles).length) { self._deps.fileManager.switchFile(Object.keys(self._deps.fileManager.tabbedFiles)[0]) } else { - self._deps.editor.displayEmptyReadOnlySession() + self._components.editor.displayEmptyReadOnlySession() self._deps.config.set('currentFile', '') } return false diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index 51e8caff67..b6f38b763c 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -143,24 +143,24 @@ function filepanel (localRegistry) { fileExplorer.ensureRoot() configExplorer.ensureRoot() var websocketconn = element.querySelector('.websocketconn') - self._deps.fileProviders['localhost'].remixd.event.register('connecting', (event) => { + self._deps.fileProviders['localhost'].event.register('connecting', (event) => { websocketconn.style.color = styles.colors.yellow websocketconn.setAttribute('title', 'Connecting to localhost. ' + JSON.stringify(event)) }) - self._deps.fileProviders['localhost'].remixd.event.register('connected', (event) => { + self._deps.fileProviders['localhost'].event.register('connected', (event) => { websocketconn.style.color = styles.colors.green websocketconn.setAttribute('title', 'Connected to localhost. ' + JSON.stringify(event)) fileSystemExplorer.show() }) - self._deps.fileProviders['localhost'].remixd.event.register('errored', (event) => { + self._deps.fileProviders['localhost'].event.register('errored', (event) => { websocketconn.style.color = styles.colors.red websocketconn.setAttribute('title', 'localhost connection errored. ' + JSON.stringify(event)) fileSystemExplorer.hide() }) - self._deps.fileProviders['localhost'].remixd.event.register('closed', (event) => { + self._deps.fileProviders['localhost'].event.register('closed', (event) => { websocketconn.style.color = styles.colors.black websocketconn.setAttribute('title', 'localhost connection closed. ' + JSON.stringify(event)) fileSystemExplorer.hide() diff --git a/src/app/tabs/test-tab.js b/src/app/tabs/test-tab.js index d94e469209..737ef6ef34 100644 --- a/src/app/tabs/test-tab.js +++ b/src/app/tabs/test-tab.js @@ -83,7 +83,9 @@ module.exports = class TestTab { function getTests (self, cb) { var path = self._deps.fileManager.currentPath() + if (!path) return cb(null, []) var provider = self._deps.fileManager.fileProviderOf(path) + if (!provider) return cb(null, []) var tests = [] self._deps.fileManager.filesFromPath(path, (error, files) => { if (error) return cb(error)