Merge pull request #935 from ethereum/fileExplorers

[Gist File explorer] Fix file loading
pull/3094/head
yann300 7 years ago committed by GitHub
commit 9aa16f7e1c
  1. 10
      src/app.js
  2. 4
      src/app/contract/publishOnSwarm.js
  3. 19
      src/app/files/basicReadOnlyExplorer.js
  4. 1
      src/app/files/file-explorer.js
  5. 2
      src/app/panels/file-panel.js
  6. 1
      src/app/tabs/settings-tab.js

@ -409,14 +409,16 @@ function run () {
}) })
// Add files received from remote instance (i.e. another browser-solidity) // Add files received from remote instance (i.e. another browser-solidity)
function loadFiles (filesSet) { function loadFiles (filesSet, fileProvider) {
if (!fileProvider) fileProvider = 'browser'
for (var f in filesSet) { for (var f in filesSet) {
var name = helper.createNonClashingName(f, filesProviders['browser']) var name = helper.createNonClashingName(f, filesProviders[fileProvider])
if (helper.checkSpecialChars(name)) { if (helper.checkSpecialChars(name)) {
modalDialogCustom.alert('Special characters are not allowed') modalDialogCustom.alert('Special characters are not allowed')
return return
} }
filesProviders['browser'].set(name, filesSet[f].content) filesProviders[fileProvider].set(name, filesSet[f].content)
} }
fileManager.switchFile() fileManager.switchFile()
} }
@ -444,7 +446,7 @@ function run () {
modalDialogCustom.alert('Gist load error: ' + response.data.message) modalDialogCustom.alert('Gist load error: ' + response.data.message)
return return
} }
loadFiles(response.data.files) loadFiles(response.data.files, 'gist')
} }
} }
}) })

@ -7,10 +7,6 @@ module.exports = (contract, appAPI, cb, swarmVerifiedPublishCallBack) => {
// gather list of files to publish // gather list of files to publish
var sources = [] var sources = []
try {
contract.metadata = JSON.stringify(JSON.parse(contract.metadata), null, '\t')
} catch (e) {}
sources.push({ sources.push({
content: contract.metadata, content: contract.metadata,
hash: contract.metadataHash hash: contract.metadataHash

@ -1,11 +1,12 @@
'use strict' 'use strict'
var EventManager = require('remix-lib').EventManager var EventManager = require('remix-lib').EventManager
class SwarmExplorer { class BasicReadOnlyExplorer {
constructor (type) { constructor (type) {
this.event = new EventManager() this.event = new EventManager()
this.files = {} this.files = {}
this.type = type this.type = type
this.readonly = true
} }
close (cb) { close (cb) {
@ -31,12 +32,18 @@ class SwarmExplorer {
} }
set (path, content, cb) { set (path, content, cb) {
this.addReadOnly(path, content)
if (cb) cb()
return true return true
} }
addReadOnly (path, content) { addReadOnly (path, content) {
this.files[this.type + '/' + path] = content var unprefixedPath = this.removePrefix(path)
this.event.trigger('fileAdded', [this.type + '/' + path, true]) try { // lazy try to format JSON
content = JSON.stringify(JSON.parse(content), null, '\t')
} catch (e) {}
this.files[this.type + '/' + unprefixedPath] = content
this.event.trigger('fileAdded', [this.type + '/' + unprefixedPath, true])
return true return true
} }
@ -97,6 +104,10 @@ class SwarmExplorer {
}) })
return tree return tree
} }
removePrefix (path) {
return path.indexOf(this.type + '/') === 0 ? path.replace(this.type + '/', '') : path
}
} }
module.exports = SwarmExplorer module.exports = BasicReadOnlyExplorer

@ -216,6 +216,7 @@ function fileExplorer (appAPI, files) {
} }
function editModeOn (event) { function editModeOn (event) {
if (self.files.readonly) return
var label = this var label = this
var li = getLiFrom(label) var li = getLiFrom(label)
var classes = li.className var classes = li.className

@ -345,7 +345,7 @@ function filepanel (appAPI, filesProvider) {
} }
function toGist () { function toGist () {
packageFiles(filesProvider['gist'], (error, packaged) => { packageFiles(filesProvider['browser'], (error, packaged) => {
if (error) { if (error) {
console.log(error) console.log(error)
} else { } else {

@ -72,6 +72,7 @@ function SettingsTab (container, appAPI, appEvents, opts) {
optimize.setAttribute('checked', true) optimize.setAttribute('checked', true)
appAPI.setOptimize(true, false) appAPI.setOptimize(true, false)
} else { } else {
queryParams.update({ optimize: false })
appAPI.setOptimize(false, false) appAPI.setOptimize(false, false)
} }

Loading…
Cancel
Save