Fix readonly files in file explorer and sync to tabs.

pull/1/head
chriseth 8 years ago
parent f303e7f7de
commit c90c063193
  1. 35
      src/app.js
  2. 11
      src/app/file-explorer.js
  3. 7
      src/app/files.js
  4. 8
      src/app/storage.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')

@ -76,11 +76,14 @@ function fileExplorer (appAPI, files) {
</span>
`
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

@ -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)

@ -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)
}
})

Loading…
Cancel
Save