From 75a98c3e33d22352e73c4ca66e72b4f50ee4e378 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 17:21:36 +0200 Subject: [PATCH 1/5] add `currentFile` --- src/app/files/fileManager.js | 5 +++++ src/app/plugin/pluginAPI.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 17e13486f4..eea9461749 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.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') diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index c0d1f2f389..18faeb538d 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -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 { From 33b2e3836f9fe46b4e52b3b874197fb458516064 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 17:21:59 +0200 Subject: [PATCH 2/5] fix getFile and setFile --- src/app/plugin/pluginAPI.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 18faeb538d..1d156e7026 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -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 { From 0d66c6f0500d2faff739dd48ed9baca8c26bb9b6 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 17:22:26 +0200 Subject: [PATCH 3/5] add manual testing --- test-browser/plugin/index.html | 3 +++ test-browser/plugin/plugin.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/test-browser/plugin/index.html b/test-browser/plugin/index.html index ff73cb0a23..e73ab7fc0b 100644 --- a/test-browser/plugin/index.html +++ b/test-browser/plugin/index.html @@ -44,6 +44,9 @@ oraclize contract creation
account creation
change title
+ setcontentof
+ getcontentof
+ getcurrent

diff --git a/test-browser/plugin/plugin.js b/test-browser/plugin/plugin.js index cb85e84672..55bdcb4574 100644 --- a/test-browser/plugin/plugin.js +++ b/test-browser/plugin/plugin.js @@ -53,4 +53,19 @@ 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) }) + }) } From 2702a1eaf78747eb755db9b4280cb8f8e68a5287 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 18:24:05 +0200 Subject: [PATCH 4/5] fix highlight --- src/app/plugin/pluginAPI.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 1d156e7026..fb9844efd5 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -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() } } } From acb7526224ba9bc3bb95ebbb01a6c2644ff61d26 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 7 Sep 2018 18:24:24 +0200 Subject: [PATCH 5/5] fix manual test --- test-browser/plugin/index.html | 3 ++- test-browser/plugin/plugin.js | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/test-browser/plugin/index.html b/test-browser/plugin/index.html index e73ab7fc0b..f81dc19b70 100644 --- a/test-browser/plugin/index.html +++ b/test-browser/plugin/index.html @@ -37,7 +37,7 @@
PLUGIN
-
+
add config
remove config
get config
@@ -47,6 +47,7 @@ setcontentof
getcontentof
getcurrent
+ sethighlight

diff --git a/test-browser/plugin/plugin.js b/test-browser/plugin/plugin.js index 55bdcb4574..27e1305de3 100644 --- a/test-browser/plugin/plugin.js +++ b/test-browser/plugin/plugin.js @@ -68,4 +68,9 @@ window.onload = 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) }) + }) }