diff --git a/package.json b/package.json index 47dddcb964..963a24e815 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "http-server": "0.9.0", "jquery": "^2.2.0", "js-base64": "^2.1.9", + "minixhr": "^3.2.2", "mkdirp": "^0.5.1", "nightwatch": "^0.9.3", "notify-error": "^1.2.0", diff --git a/src/app.js b/src/app.js index 36c9558f64..95b160a811 100644 --- a/src/app.js +++ b/src/app.js @@ -328,6 +328,9 @@ function run () { }, setText: function (text) { editor.setText(text) + }, + packageFiles: (cb) => { + packageFiles(cb) } } var filePanel = new FilePanel(FilePanelAPI, filesProviders) @@ -543,9 +546,6 @@ function run () { executionContextProvider: () => { return executionContext.getProvider() }, - packageFiles: (cb) => { - packageFiles(cb) - }, getContracts: () => { if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) { return compiler.lastCompilationResult.data.contracts diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index a973e6f5f6..e78021df72 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -1,11 +1,13 @@ - +/* global confirm, prompt */ var csjs = require('csjs-inject') var yo = require('yo-yo') - +var minixhr = require('minixhr') // simple and small cross-browser XMLHttpRequest (XHR) var EventManager = require('ethereum-remix').lib.EventManager var FileExplorer = require('../files/file-explorer') var modalDialog = require('../ui/modaldialog') var modalDialogCustom = require('../ui/modal-dialog-custom') +var QueryParams = require('../../lib/query-params') +var queryParams = new QueryParams() module.exports = filepanel @@ -36,6 +38,24 @@ var css = csjs` .newFile i:hover { color : orange; } + .gist { + padding : 10px; + } + .gist i { + cursor : pointer; + } + .gist i:hover { + color : orange; + } + .copyFiles { + padding : 10px; + } + .copyFiles i { + cursor : pointer; + } + .copyFiles i:hover { + color : orange; + } .connectToLocalhost { padding : 10px; } @@ -106,7 +126,7 @@ function filepanel (appAPI, filesProvider) {
- + ${canUpload ? yo` ` : ''} + publishToGist(appAPI)}> + + + + + @@ -250,4 +276,62 @@ function filepanel (appAPI, filesProvider) { }}) } } + + // ------------------ gist publish -------------- + + function publishToGist () { + function cb (data) { + if (data instanceof Error) { + console.log('fail', data.message) + modalDialogCustom.alert('Failed to create gist: ' + (data || 'Unknown transport error')) + } else { + data = JSON.parse(data) + if (data.html_url && confirm('Created a gist at ' + data.html_url + ' Would you like to open it in a new window?')) { + window.open(data.html_url, '_blank') + } + } + } + if (confirm('Are you sure you want to publish all your files anonymously as a public gist on github.com?')) { + appAPI.packageFiles((error, packaged) => { + if (error) { + console.log(error) + } else { + var description = 'Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=' + queryParams.get().version + '&optimize=' + queryParams.get().optimize + '&gist=' + console.log(packaged) + minixhr({ + url: 'https://api.github.com/gists', + method: 'POST', + data: JSON.stringify({ + description: description, + public: true, + files: packaged + }) + }, cb) + } + }) + } + } + + // ------------------ copy files -------------- + + function copyFiles () { + var target = prompt( + 'To which other browser-solidity instance do you want to copy over all files?', + 'https://ethereum.github.io/browser-solidity/' + ) + if (target === null) { + return + } + appAPI.packageFiles((error, packaged) => { + if (error) { + console.log(error) + } else { + $('