Merge pull request #1492 from ethereum/addAPIs2

Fix Editor API
pull/1/head
yann300 7 years ago committed by GitHub
commit c986305732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/app/files/fileManager.js
  2. 15
      src/app/plugin/pluginAPI.js
  3. 6
      test-browser/plugin/index.html
  4. 20
      test-browser/plugin/plugin.js

@ -79,6 +79,11 @@ class FileManager {
return null
}
currentFile () {
var self = this
return self._deps.config.get('currentFile')
}
currentPath () {
var self = this
var currentFile = self._deps.config.get('currentFile')

@ -67,7 +67,7 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
},
editor: {
getCurrentFile: (mod, cb) => {
var path = fileManager.currentPath()
var path = fileManager.currentFile()
if (!path) {
cb('no file selected')
} else {
@ -78,7 +78,7 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
var provider = fileManager.fileProviderOf(path)
if (provider) {
// TODO add approval to user for external plugin to get the content of the given `path`
provider.get(mod + '/' + path, (error, content) => {
provider.get(path, (error, content) => {
cb(error, content)
})
} else {
@ -89,7 +89,7 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
var provider = fileManager.fileProviderOf(path)
if (provider) {
// TODO add approval to user for external plugin to set the content of the given `path`
provider.set(mod + '/' + path, content, (error) => {
provider.set(path, content, (error) => {
cb(error)
})
} else {
@ -97,8 +97,15 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
}
},
highlight: (mod, lineColumnPos, filePath, hexColor, cb) => {
var position
try {
position = JSON.parse(lineColumnPos)
} catch (e) {
return cb(e.message)
}
highlighter.currentSourceLocation(null)
highlighter.currentSourceLocation(lineColumnPos, filePath, hexColor)
highlighter.currentSourceLocationFromfileName(position, filePath, hexColor)
cb()
}
}
}

@ -37,13 +37,17 @@
<body>
<div>PLUGIN</div>
<input type="text" id="filename"></input>
<input type="text" id="valuetosend"></input> <br>
<input type="text" id="valuetosend"></input> <input type="text" id="valuetosend2"></input> <br>
<input type="button" id="testmessageadd">add config</input> <br>
<input type="button" id="testmessageremove">remove config</input> <br>
<input type="button" id="testmessagerget">get config</input> <br>
<input type="button" id="testcontractcreation">oraclize contract creation</input> <br>
<input type="button" id="testaccountcreation">account creation</input> <br>
<input type="button" id="testchangetitle">change title</input> <br>
<input type="button" id="setcontentof">setcontentof</input> <br>
<input type="button" id="getcontentof">getcontentof</input> <br>
<input type="button" id="getcurrent">getcurrent</input> <br>
<input type="button" id="sethighlight">sethighlight</input> <br>
<br>
<div id='compilationdata'></div>
</body>

@ -53,4 +53,24 @@ window.onload = function () {
extension.call('app', 'updateTitle', ['changed title ' + k++],
function (error, result) { console.log(error, result) })
})
document.querySelector('input#setcontentof').addEventListener('click', function () {
extension.call('editor', 'setFile', [document.getElementById('filename').value, document.getElementById('valuetosend').value],
function (error, result) { console.log(error, result) })
})
document.querySelector('input#getcontentof').addEventListener('click', function () {
extension.call('editor', 'getFile', [document.getElementById('filename').value],
function (error, result) { console.log(error, result) })
})
document.querySelector('input#getcurrent').addEventListener('click', function () {
extension.call('editor', 'getCurrentFile', [],
function (error, result) { console.log(error, result) })
})
document.querySelector('input#sethighlight').addEventListener('click', function () {
extension.call('editor', 'highlight', [document.getElementById('filename').value, document.getElementById('valuetosend').value, document.getElementById('valuetosend2').value],
function (error, result) { console.log(error, result) })
})
}

Loading…
Cancel
Save