Commit a545296b authored by ioedeveloper's avatar ioedeveloper

Moved getFile, setFile and switchFile to new API

parent 0e7e1e5f
...@@ -419,7 +419,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -419,7 +419,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
if (error) console.error(error) if (error) console.error(error)
if (Object.keys(filesList).length === 0) { if (Object.keys(filesList).length === 0) {
for (let file in examples) { for (let file in examples) {
fileManager.setFile(examples[file].name, examples[file].content) fileManager.writeFile(examples[file].name, examples[file].content)
} }
} }
}) })
......
...@@ -112,7 +112,7 @@ class ContextView { ...@@ -112,7 +112,7 @@ class ContextView {
if (provider) { if (provider) {
provider.exists(filename, (error, exist) => { provider.exists(filename, (error, exist) => {
if (error) return console.log(error) if (error) return console.log(error)
this._deps.fileManager.switchFile(filename) this._deps.fileManager.open(filename)
jumpToLine(lineColumn) jumpToLine(lineColumn)
}) })
} }
......
...@@ -40,7 +40,7 @@ class SourceHighlighter { ...@@ -40,7 +40,7 @@ class SourceHighlighter {
if (lineColumnPos) { if (lineColumnPos) {
this.source = filePath this.source = filePath
if (this._deps.config.get('currentFile') !== this.source) { if (this._deps.config.get('currentFile') !== this.source) {
this._deps.fileManager.switchFile(this.source) this._deps.fileManager.open(this.source)
} }
const css = csjs` const css = csjs`
......
...@@ -60,7 +60,7 @@ function fileExplorer (localRegistry, files, menuItems) { ...@@ -60,7 +60,7 @@ function fileExplorer (localRegistry, files, menuItems) {
} }
self.events.register('focus', function (path) { self.events.register('focus', function (path) {
self._deps.fileManager.switchFile(path) self._deps.fileManager.open(path)
}) })
self._components.registry.put({ api: self, name: `fileexplorer/${self.files.type}` }) self._components.registry.put({ api: self, name: `fileexplorer/${self.files.type}` })
...@@ -584,7 +584,7 @@ fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') { ...@@ -584,7 +584,7 @@ fileExplorer.prototype.createNewFile = function (parentFolder = 'browser') {
if (!self.files.set(newName, '')) { if (!self.files.set(newName, '')) {
tooltip('Failed to create file ' + newName) tooltip('Failed to create file ' + newName)
} else { } else {
self._deps.fileManager.switchFile(newName) self._deps.fileManager.open(newName)
if (newName.includes('_test.sol')) { if (newName.includes('_test.sol')) {
self.events.trigger('newTestFileCreated', [newName]) self.events.trigger('newTestFileCreated', [newName])
} }
......
...@@ -23,7 +23,7 @@ const profile = { ...@@ -23,7 +23,7 @@ const profile = {
icon: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB3aWR0aD0iMTc5MiIgaGVpZ2h0PSIxNzkyIiB2aWV3Qm94PSIwIDAgMTc5MiAxNzkyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNjk2IDM4NHE0MCAwIDY4IDI4dDI4IDY4djEyMTZxMCA0MC0yOCA2OHQtNjggMjhoLTk2MHEtNDAgMC02OC0yOHQtMjgtNjh2LTI4OGgtNTQ0cS00MCAwLTY4LTI4dC0yOC02OHYtNjcycTAtNDAgMjAtODh0NDgtNzZsNDA4LTQwOHEyOC0yOCA3Ni00OHQ4OC0yMGg0MTZxNDAgMCA2OCAyOHQyOCA2OHYzMjhxNjgtNDAgMTI4LTQwaDQxNnptLTU0NCAyMTNsLTI5OSAyOTloMjk5di0yOTl6bS02NDAtMzg0bC0yOTkgMjk5aDI5OXYtMjk5em0xOTYgNjQ3bDMxNi0zMTZ2LTQxNmgtMzg0djQxNnEwIDQwLTI4IDY4dC02OCAyOGgtNDE2djY0MGg1MTJ2LTI1NnEwLTQwIDIwLTg4dDQ4LTc2em05NTYgODA0di0xMTUyaC0zODR2NDE2cTAgNDAtMjggNjh0LTY4IDI4aC00MTZ2NjQwaDg5NnoiLz48L3N2Zz4=', icon: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB3aWR0aD0iMTc5MiIgaGVpZ2h0PSIxNzkyIiB2aWV3Qm94PSIwIDAgMTc5MiAxNzkyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0xNjk2IDM4NHE0MCAwIDY4IDI4dDI4IDY4djEyMTZxMCA0MC0yOCA2OHQtNjggMjhoLTk2MHEtNDAgMC02OC0yOHQtMjgtNjh2LTI4OGgtNTQ0cS00MCAwLTY4LTI4dC0yOC02OHYtNjcycTAtNDAgMjAtODh0NDgtNzZsNDA4LTQwOHEyOC0yOCA3Ni00OHQ4OC0yMGg0MTZxNDAgMCA2OCAyOHQyOCA2OHYzMjhxNjgtNDAgMTI4LTQwaDQxNnptLTU0NCAyMTNsLTI5OSAyOTloMjk5di0yOTl6bS02NDAtMzg0bC0yOTkgMjk5aDI5OXYtMjk5em0xOTYgNjQ3bDMxNi0zMTZ2LTQxNmgtMzg0djQxNnEwIDQwLTI4IDY4dC02OCAyOGgtNDE2djY0MGg1MTJ2LTI1NnEwLTQwIDIwLTg4dDQ4LTc2em05NTYgODA0di0xMTUyaC0zODR2NDE2cTAgNDAtMjggNjh0LTY4IDI4aC00MTZ2NjQwaDg5NnoiLz48L3N2Zz4=',
permission: true, permission: true,
version: packageJson.version, version: packageJson.version,
methods: ['setFile', 'switchFile', 'file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'unlink', 'rename', 'readdir', 'rmdir'], methods: ['file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'unlink', 'rename', 'readdir', 'rmdir'],
kind: 'file-system' kind: 'file-system'
} }
...@@ -76,7 +76,7 @@ class FileManager extends Plugin { ...@@ -76,7 +76,7 @@ class FileManager extends Plugin {
} }
/** /**
* Emit error based on error code * Emits error based on error code
* @param {object} error error { code, message } * @param {object} error error { code, message }
*/ */
_handleError (error) { _handleError (error) {
...@@ -129,10 +129,9 @@ class FileManager extends Plugin { ...@@ -129,10 +129,9 @@ class FileManager extends Plugin {
* @returns {boolean} true if path is a file. * @returns {boolean} true if path is a file.
*/ */
isFile (path) { isFile (path) {
const extension = path.split('.').pop() const extension = path.split('/').pop()
const splitExtension = extension.split('/')
return extension && extension.indexOf('.') > -1
return !!extension && splitExtension.length === 1 && splitExtension[0] === extension
} }
/** /**
...@@ -165,7 +164,7 @@ class FileManager extends Plugin { ...@@ -165,7 +164,7 @@ class FileManager extends Plugin {
readFile (path) { readFile (path) {
this._handleExists(path, `Cannot read file ${path}`) this._handleExists(path, `Cannot read file ${path}`)
this._handleIsFile(path, `Cannot read file ${path}`) this._handleIsFile(path, `Cannot read file ${path}`)
this.getFile(path) return this.getFile(path)
} }
/** /**
......
...@@ -34,7 +34,7 @@ export class TabProxy { ...@@ -34,7 +34,7 @@ export class TabProxy {
return return
} }
this.addTab(file, '', () => { this.addTab(file, '', () => {
this.fileManager.switchFile(file) this.fileManager.open(file)
this.event.emit('switchFile', file) this.event.emit('switchFile', file)
}, },
() => { () => {
...@@ -47,7 +47,7 @@ export class TabProxy { ...@@ -47,7 +47,7 @@ export class TabProxy {
if (isFolder) return if (isFolder) return
// should change the tab title too // should change the tab title too
this.addTab(newName, '', () => { this.addTab(newName, '', () => {
this.fileManager.switchFile(newName) this.fileManager.open(newName)
this.event.emit('switchFile', newName) this.event.emit('switchFile', newName)
}, },
() => { () => {
......
...@@ -319,7 +319,7 @@ class Recorder { ...@@ -319,7 +319,7 @@ class Recorder {
helper.createNonClashingName(newFile, fileProvider, (error, newFile) => { helper.createNonClashingName(newFile, fileProvider, (error, newFile) => {
if (error) return cb('Failed to create file. ' + newFile + ' ' + error) if (error) return cb('Failed to create file. ' + newFile + ' ' + error)
if (!fileProvider.set(newFile, txJSON)) return cb('Failed to create file ' + newFile) if (!fileProvider.set(newFile, txJSON)) return cb('Failed to create file ' + newFile)
this.fileManager.switchFile(newFile) this.fileManager.open(newFile)
}) })
}) })
} }
......
...@@ -19,7 +19,7 @@ class TestTabLogic { ...@@ -19,7 +19,7 @@ class TestTabLogic {
// This should be updated to pass complete path, if test file comes from different directory/path // This should be updated to pass complete path, if test file comes from different directory/path
const fileNameToImport = splittedFileName[splittedFileName.length - 1] const fileNameToImport = splittedFileName[splittedFileName.length - 1]
if (!fileProvider.set(newFile, this.generateTestContractSample(fileNameToImport))) return modalDialogCustom.alert('Failed to create test file ' + newFile) if (!fileProvider.set(newFile, this.generateTestContractSample(fileNameToImport))) return modalDialogCustom.alert('Failed to create test file ' + newFile)
this.fileManager.switchFile(newFile) this.fileManager.open(newFile)
}) })
} }
......
...@@ -41,7 +41,7 @@ Renderer.prototype._errorClick = function (errFile, errLine, errCol) { ...@@ -41,7 +41,7 @@ Renderer.prototype._errorClick = function (errFile, errLine, errCol) {
if (provider) { if (provider) {
provider.exists(errFile, (error, exist) => { provider.exists(errFile, (error, exist) => {
if (error) return console.log(error) if (error) return console.log(error)
self._deps.fileManager.switchFile(errFile) self._deps.fileManager.open(errFile)
editor.gotoLine(errLine, errCol) editor.gotoLine(errLine, errCol)
}) })
} }
......
...@@ -34,7 +34,6 @@ class Toaster { ...@@ -34,7 +34,6 @@ class Toaster {
} }
render (tooltipText, actionElement, opts) { render (tooltipText, actionElement, opts) {
console.log('tooltipText: ', tooltipText)
opts = defaultOptions(opts) opts = defaultOptions(opts)
let canShorten = true let canShorten = true
if (tooltipText instanceof Element) { if (tooltipText instanceof Element) {
......
...@@ -151,7 +151,7 @@ class CmdInterpreterAPI { ...@@ -151,7 +151,7 @@ class CmdInterpreterAPI {
toolTip(`Unable to load ${url}: ${err}`) toolTip(`Unable to load ${url}: ${err}`)
if (cb) cb(err) if (cb) cb(err)
} else { } else {
self._deps.fileManager.setFile(type + '/' + cleanUrl, content) self._deps.fileManager.writeFile(type + '/' + cleanUrl, content)
try { try {
content = JSON.parse(content) content = JSON.parse(content)
async.eachOfSeries(content.sources, (value, file, callbackSource) => { async.eachOfSeries(content.sources, (value, file, callbackSource) => {
...@@ -164,7 +164,7 @@ class CmdInterpreterAPI { ...@@ -164,7 +164,7 @@ class CmdInterpreterAPI {
return callbackSource(`Cannot retrieve the content of ${url}: ${error}`) return callbackSource(`Cannot retrieve the content of ${url}: ${error}`)
} else { } else {
try { try {
await self._deps.fileManager.setFile(type + '/' + cleanUrl, content) await self._deps.fileManager.writeFile(type + '/' + cleanUrl, content)
callbackSource() callbackSource()
} catch (e) { } catch (e) {
callbackSource(e.message) callbackSource(e.message)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment