From c90c063193d74dcaaecbff78d0f05286841761e2 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 19 Apr 2017 18:58:08 +0200 Subject: [PATCH] Fix readonly files in file explorer and sync to tabs. --- src/app.js | 35 ++++++++++------------------------- src/app/file-explorer.js | 11 +++++------ src/app/files.js | 7 +------ src/app/storage.js | 8 ++++---- 4 files changed, 20 insertions(+), 41 deletions(-) diff --git a/src/app.js b/src/app.js index 5e83e92658..b738b7fbe8 100644 --- a/src/app.js +++ b/src/app.js @@ -161,21 +161,6 @@ var run = function () { var editor = new Editor(document.getElementById('input')) // ---------------- FilePanel -------------------- - /**************************************************************************** - var sources = { - 'test/client/credit.sol': '', - 'src/voting.sol': '', - 'src/leasing.sol': '', - 'src/gmbh/contract.sol': false, - 'src/gmbh/test.sol': false, - 'src/gmbh/company.sol': false, - 'src/gmbh/node_modules/ballot.sol': false, - 'src/ug/finance.sol': false, - 'app/solidity/mode.sol': true, - 'app/ethereum/constitution.sol': true - } - Object.keys(sources).forEach(function (key) { files.set(key, sources[key]) }) - /****************************************************************************/ var css = csjs` .filepanel { display : flex; @@ -215,7 +200,7 @@ var run = function () { }) api.register('focus', function (path) { [...window.files.querySelectorAll('.file .name')].forEach(function (span) { - if (span.innerText === path) switchToFile(path) // @TODO: scroll into view + if (span.innerText === path) switchToFile(path) }) }) files.event.register('fileRenamed', function (oldName, newName) { @@ -224,7 +209,15 @@ var run = function () { }) }) files.event.register('fileRemoved', function (path) { - if (path === ui.get('currentFile')) ui.set('currentFile', '') + editor.discard(path) + if (path === ui.get('currentFile')) { + ui.set('currentFile', '') + switchToNextFile() + } + refreshTabs() + }) + files.event.register('fileAdded', function (path) { + refreshTabs() }) // ------------------ gist publish -------------- @@ -342,10 +335,6 @@ var run = function () { if (confirm('Are you sure you want to remove: ' + name + ' from local storage?')) { if (!files.remove(name)) { alert('Error while removing file') - } else { - ui.set('currentFile', '') - switchToNextFile() - editor.discard(name) } } return false @@ -394,10 +383,6 @@ var run = function () { } $('#input').toggle(currentFileOpen) $('#output').toggle(currentFileOpen) - - $filesEl.animate({ left: Math.max((0 - activeFilePos() + (FILE_SCROLL_DELTA / 2)), 0) + 'px' }, 'slow', function () { - reAdjust() - }) } var $scrollerRight = $('.scroller-right') diff --git a/src/app/file-explorer.js b/src/app/file-explorer.js index c234e260ac..e61638e06f 100755 --- a/src/app/file-explorer.js +++ b/src/app/file-explorer.js @@ -76,11 +76,14 @@ function fileExplorer (appAPI, files) { ` - appUI.register('currentFile', fileFocus) + appUI.register('fileChanged', (changedFiles) => { + if (changedFiles[0] == 'currentFile') { + fileFocus(files.get('currentfile')) + } + }) fileEvents.register('fileRemoved', fileRemoved) fileEvents.register('fileRenamed', fileRenamed) fileEvents.register('fileAdded', fileAdded) - fileEvents.register('fileChanged', fileChanged) var filepath = null var focusElement = null @@ -216,8 +219,6 @@ function fileExplorer (appAPI, files) { }) } - function fileChanged (filepath) { } - function fileFocus (path) { if (filepath === path) return filepath = path @@ -253,8 +254,6 @@ function fileExplorer (appAPI, files) { el.className = css.fileexplorer element.parentElement.replaceChild(el, element) element = el - fileFocus(filepath) - appAPI.switchToFile(filepath) } element.api = api diff --git a/src/app/files.js b/src/app/files.js index 3bea4d177b..3cf567f8ee 100644 --- a/src/app/files.js +++ b/src/app/files.js @@ -138,12 +138,7 @@ function Files (storage) { var tree = {} var self = this - storage.keys().forEach(function (path) { - // NOTE: as a temporary measure do not show the config file - if (path === '.remix.config') { - return - } - + Object.keys(this.list()).forEach(function (path) { hashmapize(tree, path, { '/readonly': self.isReadOnly(path), '/content': self.get(path) diff --git a/src/app/storage.js b/src/app/storage.js index ba965c4af8..b8795f2989 100644 --- a/src/app/storage.js +++ b/src/app/storage.js @@ -39,17 +39,17 @@ function Storage (prefix) { this.keys = function () { return safeKeys() - // filter any names not including sol: + // filter any names not including the prefix .filter(function (item) { return item.indexOf(prefix, 0) === 0 }) - // remove sol: from filename - .map(function (item) { return item.replace(/^sol:/, '') }) + // remove prefix from filename + .map(function (item) { return item.substr(prefix.length) }) } // on startup, upgrade the old storage layout safeKeys().forEach(function (name) { if (name.indexOf('sol-cache-file-', 0) === 0) { var content = window.localStorage.getItem(name) - window.localStorage.setItem(name.replace(/^sol-cache-file-/, prefix), content) + window.localStorage.setItem(name.replace(/^sol-cache-file-/, 'sol:'), content) window.localStorage.removeItem(name) } })