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. 24
      src/app/editor.js

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

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

Loading…
Cancel
Save