Remove fileKey/fileNameFromKey as storage.get/set includes it now

pull/1/head
Alex Beregszaszi 8 years ago
parent 20911afccf
commit f9ad4bcb2a
  1. 33
      src/app.js
  2. 4
      src/app/config.js
  3. 3
      src/app/debugger.js
  4. 17
      src/app/editor.js
  5. 8
      src/app/renderer.js
  6. 21
      src/app/utils.js

@ -4,7 +4,6 @@
var $ = require('jquery')
var base64 = require('js-base64').Base64
var utils = require('./app/utils')
var QueryParams = require('./app/query-params')
var queryParams = new QueryParams()
var GistHandler = require('./app/gist-handler')
@ -45,11 +44,10 @@ var run = function () {
function loadFiles (files) {
for (var f in files) {
var key = utils.fileKey(f)
var content = files[f].content
storage.loadFile(key, content)
storage.loadFile(f, files[f].content)
}
editor.setCacheFile(utils.fileKey(Object.keys(files)[0]))
// Set the first file as current tab
editor.setCacheFile(Object.keys(files)[0])
updateFiles()
}
@ -100,7 +98,7 @@ var run = function () {
function check (key) {
chrome.storage.sync.get(key, function (resp) {
console.log('comparing to cloud', key, resp)
if (typeof resp[key] !== 'undefined' && obj[key] !== resp[key] && confirm('Overwrite "' + utils.fileNameFromKey(key) + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) {
if (typeof resp[key] !== 'undefined' && obj[key] !== resp[key] && confirm('Overwrite "' + key + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) {
console.log('Overwriting', key)
storage.set(key, resp[key])
updateFiles()
@ -120,9 +118,6 @@ var run = function () {
for (var y in storage.keys()) {
console.log('checking', y)
obj[y] = storage.get(y)
if (!utils.isCachedFile(y)) {
continue
}
count++
check(y)
}
@ -246,9 +241,9 @@ var run = function () {
editor.hasFile(newName)
? 'Are you sure you want to overwrite: ' + newName + ' with ' + originalName + '?'
: 'Are you sure you want to rename: ' + originalName + ' to ' + newName + '?')) {
storage.rename(utils.fileKey(originalName), utils.fileKey(newName))
editor.renameSession(utils.fileKey(originalName), utils.fileKey(newName))
editor.setCacheFile(utils.fileKey(newName))
storage.rename(originalName, newName)
editor.renameSession(originalName, newName)
editor.setCacheFile(newName)
}
updateFiles()
@ -263,16 +258,16 @@ var run = function () {
var name = $(this).parent().find('.name').text()
if (confirm('Are you sure you want to remove: ' + name + ' from local storage?')) {
storage.remove(utils.fileKey(name))
editor.removeSession(utils.fileKey(name))
editor.setNextFile(utils.fileKey(name))
storage.remove(name)
editor.removeSession(name)
editor.setNextFile(name)
updateFiles()
}
return false
})
function swicthToFile (file) {
editor.setCacheFile(utils.fileKey(file))
editor.setCacheFile(file)
updateFiles()
}
@ -290,12 +285,12 @@ var run = function () {
$('#output').empty()
for (var f in files) {
var name = utils.fileNameFromKey(files[f])
var name = files[f]
$filesEl.append($('<li class="file"><span class="name">' + name + '</span><span class="remove"><i class="fa fa-close"></i></span></li>'))
}
if (editor.cacheFileIsPresent()) {
var currentFileName = utils.fileNameFromKey(editor.getCacheFile())
var currentFileName = editor.getCacheFile()
var active = $('#files .file').filter(function () { return $(this).find('.name').text() === currentFileName })
active.addClass('active')
editor.resetSession()
@ -522,7 +517,7 @@ var run = function () {
function runCompiler () {
var files = {}
var target = utils.fileNameFromKey(editor.getCacheFile())
var target = editor.getCacheFile()
files[target] = editor.getValue()

@ -1,8 +1,6 @@
'use strict'
var utils = require('./utils')
var CONFIG_FILE = utils.fileKey('.browser-solidity.json')
var CONFIG_FILE = '.browser-solidity.json'
function Config (storage) {
this.items = {}

@ -1,7 +1,6 @@
'use strict'
var remix = require('ethereum-remix')
var utils = require('./utils')
var ace = require('brace')
var Range = ace.acequire('ace/range').Range
@ -70,7 +69,7 @@ Debugger.prototype.debug = function (txHash) {
* @param {Object} rawLocation - raw position of the source code to hightlight {start, length, file, jump}
*/
Debugger.prototype.highlight = function (lineColumnPos, rawLocation) {
var name = utils.fileNameFromKey(this.editor.getCacheFile()) // current opened tab
var name = this.editor.getCacheFile() // current opened tab
var source = this.compiler.lastCompilationResult.data.sourceList[rawLocation.file] // auto switch to that tab
this.removeCurrentMarker()
if (name !== source) {

@ -1,14 +1,13 @@
/* global FileReader */
'use strict'
var utils = require('./utils')
var examples = require('./example-contracts')
var ace = require('brace')
require('../mode-solidity.js')
function Editor (loadingFromGist, storage) {
var SOL_CACHE_UNTITLED = utils.fileKey('Untitled')
var SOL_CACHE_UNTITLED = 'Untitled'
var SOL_CACHE_FILE = null
var editor = ace.edit('input')
@ -37,7 +36,7 @@ function Editor (loadingFromGist, storage) {
this.uploadFile = function (file, callback) {
var fileReader = new FileReader()
var cacheName = utils.fileKey(file.name)
var cacheName = file.name
fileReader.onload = function (e) {
storage.set(cacheName, e.target.result)
@ -85,18 +84,18 @@ function Editor (loadingFromGist, storage) {
}
this.hasFile = function (name) {
return this.getFiles().indexOf(utils.fileKey(name)) !== -1
return this.getFiles().indexOf(name) !== -1
}
this.getFile = function (name) {
return storage.get(utils.fileKey(name))
return storage.get(name)
}
function getFiles () {
var files = []
storage.keys().forEach(function (f) {
// NOTE: as a temporary measure do not show the config file in the editor
if (utils.isCachedFile(f) && (f !== (utils.fileKey('.browser-solidity.json')))) {
if (f !== '.browser-solidity.json') {
files.push(f)
if (!sessions[f]) sessions[f] = newEditorSession(f)
}
@ -110,7 +109,7 @@ function Editor (loadingFromGist, storage) {
var filesArr = this.getFiles()
for (var f in filesArr) {
files[utils.fileNameFromKey(filesArr[f])] = {
files[filesArr[f]] = {
content: storage.get(filesArr[f])
}
}
@ -174,8 +173,8 @@ function Editor (loadingFromGist, storage) {
function setupStuff (files) {
if (files.length === 0) {
if (loadingFromGist) return
files.push(utils.fileKey(examples.ballot.name))
storage.set(utils.fileKey(examples.ballot.name), examples.ballot.content)
files.push(examples.ballot.name)
storage.set(examples.ballot.name, examples.ballot.content)
}
SOL_CACHE_FILE = files[0]

@ -55,7 +55,7 @@ Renderer.prototype.error = function (message, container, options) {
var errFile = err[1]
var errLine = parseInt(err[2], 10) - 1
var errCol = err[4] ? parseInt(err[4], 10) : 0
if (!opt.noAnnotations && (errFile === '' || errFile === utils.fileNameFromKey(self.editor.getCacheFile()))) {
if (!opt.noAnnotations && (errFile === '' || errFile === self.editor.getCacheFile())) {
self.editor.addAnnotation({
row: errLine,
column: errCol,
@ -64,9 +64,9 @@ Renderer.prototype.error = function (message, container, options) {
})
}
$error.click(function (ev) {
if (errFile !== '' && errFile !== utils.fileNameFromKey(self.editor.getCacheFile()) && self.editor.hasFile(errFile)) {
if (errFile !== '' && errFile !== self.editor.getCacheFile() && self.editor.hasFile(errFile)) {
// Switch to file
self.editor.setCacheFile(utils.fileKey(errFile))
self.editor.setCacheFile(errFile)
self.updateFiles()
}
self.editor.handleErrorClick(errLine, errCol)
@ -287,7 +287,7 @@ Renderer.prototype.contracts = function (data, source) {
var self = this
var getSource = function (contractName, source, data) {
var currentFile = utils.fileNameFromKey(self.editor.getCacheFile())
var currentFile = self.editor.getCacheFile()
return source.sources[currentFile]
}

@ -1,30 +1,9 @@
'use strict'
var SOL_CACHE_FILE_PREFIX = 'sol-cache-file-'
function getCacheFilePrefix () {
return SOL_CACHE_FILE_PREFIX
}
function isCachedFile (name) {
return name.indexOf(getCacheFilePrefix(), 0) === 0
}
function fileKey (name) {
return getCacheFilePrefix() + name
}
function fileNameFromKey (key) {
return key.replace(getCacheFilePrefix(), '')
}
function errortype (message) {
return message.match(/^(.*:[0-9]*:[0-9]* )?Warning: /) ? 'warning' : 'error'
}
module.exports = {
isCachedFile: isCachedFile,
fileKey: fileKey,
fileNameFromKey: fileNameFromKey,
errortype: errortype
}

Loading…
Cancel
Save