Merge pull request #389 from ethereum/editor-naming-cleanup

Editor naming cleanup
pull/1/head
chriseth 8 years ago committed by GitHub
commit 8b4cd6b423
  1. 24
      src/app.js
  2. 52
      src/app/editor.js

@ -42,6 +42,7 @@ var run = function () {
var storage = new Storage()
var config = new Config(storage)
// Add files received from remote instance (i.e. another browser-solidity)
function loadFiles (files) {
for (var f in files) {
storage.loadFile(f, files[f].content)
@ -51,10 +52,12 @@ var run = function () {
updateFiles()
}
// Replace early callback with instant response
loadFilesCallback = function (files) {
loadFiles(files)
}
// Run if we did receive an event from remote instance while starting up
if (filesToLoad !== null) {
loadFiles(filesToLoad)
}
@ -135,6 +138,7 @@ var run = function () {
var $el = $(this)
selectTab($el)
})
var selectTab = function (el) {
var match = /[a-z]+View/.exec(el.get(0).className)
if (!match) return
@ -216,8 +220,14 @@ var run = function () {
})
})
$filesEl.on('click', '.file:not(.active)', showFileHandler)
// Switch tab
$filesEl.on('click', '.file:not(.active)', function (ev) {
ev.preventDefault()
switchToFile($(this).find('.name').text())
return false
})
// Edit name of current tab
$filesEl.on('click', '.file.active', function (ev) {
var $fileTabEl = $(this)
var originalName = $fileTabEl.find('.name').text()
@ -253,6 +263,7 @@ var run = function () {
return false
})
// Remove current tab
$filesEl.on('click', '.file .remove', function (ev) {
ev.preventDefault()
var name = $(this).parent().find('.name').text()
@ -266,17 +277,12 @@ var run = function () {
return false
})
function swicthToFile (file) {
function switchToFile (file) {
editor.setCacheFile(file)
updateFiles()
}
function showFileHandler (ev) {
ev.preventDefault()
swicthToFile($(this).find('.name').text())
return false
}
// Synchronise tab list with file names known to the editor
function updateFiles () {
var $filesEl = $('#files')
var files = editor.getFiles()
@ -489,7 +495,7 @@ var run = function () {
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
var transactionDebugger = new Debugger('#debugger', editor, compiler, executionContext.event, swicthToFile, offsetToLineColumnConverter)
var transactionDebugger = new Debugger('#debugger', editor, compiler, executionContext.event, switchToFile, offsetToLineColumnConverter)
transactionDebugger.addProvider('vm', executionContext.vm())
transactionDebugger.switchProvider('vm')
transactionDebugger.addProvider('injected', executionContext.web3())

@ -7,7 +7,6 @@ var ace = require('brace')
require('../mode-solidity.js')
function Editor (doNotLoadStorage, storage) {
var SOL_CACHE_UNTITLED = 'Untitled'
var SOL_CACHE_FILE = null
var editor = ace.edit('input')
@ -15,8 +14,6 @@ function Editor (doNotLoadStorage, storage) {
var sessions = {}
var sourceAnnotations = []
setupStuff()
this.addMarker = function (range, cssClass) {
return editor.session.addMarker(range, cssClass)
}
@ -27,20 +24,21 @@ function Editor (doNotLoadStorage, storage) {
this.newFile = function () {
var untitledCount = ''
while (storage.exists(SOL_CACHE_UNTITLED + untitledCount)) {
while (storage.exists('Untitled' + untitledCount)) {
untitledCount = (untitledCount - 0) + 1
}
SOL_CACHE_FILE = SOL_CACHE_UNTITLED + untitledCount
this.setCacheFile('Untitled' + untitledCount)
this.setCacheFileContent('')
}
this.uploadFile = function (file, callback) {
var fileReader = new FileReader()
var cacheName = file.name
var name = file.name
var self = this
fileReader.onload = function (e) {
storage.set(cacheName, e.target.result)
SOL_CACHE_FILE = cacheName
self.setCacheFile(name)
self.setCacheFileContent(e.target.result)
callback()
}
fileReader.readAsText(file)
@ -68,7 +66,7 @@ function Editor (doNotLoadStorage, storage) {
}
this.resetSession = function () {
editor.setSession(sessions[SOL_CACHE_FILE])
editor.setSession(sessions[this.getCacheFile()])
editor.focus()
}
@ -170,31 +168,31 @@ function Editor (doNotLoadStorage, storage) {
return s
}
function setupStuff () {
// Unmap ctrl-t & ctrl-f
editor.commands.bindKeys({ 'ctrl-t': null })
editor.commands.bindKeys({ 'ctrl-f': null })
// Do setup on initialisation here
if (doNotLoadStorage) {
return
}
// Unmap ctrl-t & ctrl-f
editor.commands.bindKeys({ 'ctrl-t': null })
editor.commands.bindKeys({ 'ctrl-f': null })
var files = getFiles()
if (doNotLoadStorage) {
return
}
if (files.length === 0) {
files.push(examples.ballot.name)
storage.set(examples.ballot.name, examples.ballot.content)
}
var files = getFiles()
SOL_CACHE_FILE = files[0]
if (files.length === 0) {
files.push(examples.ballot.name)
storage.set(examples.ballot.name, examples.ballot.content)
}
for (var x in files) {
sessions[files[x]] = newEditorSession(files[x])
}
this.setCacheFile(files[0])
editor.setSession(sessions[SOL_CACHE_FILE])
editor.resize(true)
for (var x in files) {
sessions[files[x]] = newEditorSession(files[x])
}
editor.setSession(sessions[this.getCacheFile()])
editor.resize(true)
}
module.exports = Editor

Loading…
Cancel
Save