diff --git a/src/app/files/chromeCloudStorageSync.js b/src/app/files/chromeCloudStorageSync.js index 428b4c4bdd..05524e71e7 100644 --- a/src/app/files/chromeCloudStorageSync.js +++ b/src/app/files/chromeCloudStorageSync.js @@ -1,5 +1,6 @@ -/* global confirm, chrome */ +/* global chrome */ 'use strict' +var modalDialogCustom = require('../ui/modal-dialog-custom') module.exports = function (filesProviders) { if (typeof chrome === 'undefined' || !chrome || !chrome.storage || !chrome.storage.sync) { @@ -13,19 +14,27 @@ module.exports = function (filesProviders) { 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 "' + key + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.')) { - console.log('Overwriting', key) - filesProviders['browser'].set(key, resp[key]) - } else { - console.log('add to obj', obj, key) - filesProviders['browser'].get(key, (error, content) => { - if (error) { - console.log(error) - } else { - obj[key] = content - } - }) + + function confirmDialog (callback) { + modalDialogCustom.confirm('', 'Overwrite "' + key + '"? Click Ok to overwrite local file with file from cloud. Cancel will push your local file to the cloud.', () => { callback(true) }, () => { callback(false) }) } + + confirmDialog(function (theResult) { + if (typeof resp[key] !== 'undefined' && obj[key] !== resp[key] && theResult) { + console.log('Overwriting', key) + filesProviders['browser'].set(key, resp[key]) + } else { + console.log('add to obj', obj, key) + filesProviders['browser'].get(key, (error, content) => { + if (error) { + console.log(error) + } else { + obj[key] = content + } + }) + } + }) + done++ if (done >= count) { chrome.storage.sync.set(obj, function () { diff --git a/src/app/files/file-explorer.js b/src/app/files/file-explorer.js index d8e408b276..74d19b8bf9 100755 --- a/src/app/files/file-explorer.js +++ b/src/app/files/file-explorer.js @@ -1,4 +1,4 @@ -/* global FileReader, confirm */ +/* global FileReader */ var yo = require('yo-yo') var csjs = require('csjs-inject') var Treeview = require('ethereum-remix').ui.TreeView @@ -133,8 +133,7 @@ function fileExplorer (appAPI, files) { this.events = events var api = {} api.addFile = function addFile (file) { - var name = files.type + '/' + file.name - if (!files.exists(name) || confirm('The file ' + name + ' already exists! Would you like to overwrite it?')) { + function loadFile () { var fileReader = new FileReader() fileReader.onload = function (event) { var success = files.set(name, event.target.result) @@ -143,6 +142,13 @@ function fileExplorer (appAPI, files) { } fileReader.readAsText(file) } + + var name = files.type + '/' + file.name + if (!files.exists(name)) { + loadFile() + } else { + modalDialogCustom.confirm(null, `The file ${name} already exists! Would you like to overwrite it?`, () => { loadFile() }) + } } this.api = api @@ -193,10 +199,10 @@ function fileExplorer (appAPI, files) { var path = label.dataset.path var isFolder = !!~label.className.indexOf('folder') if (isFolder) path += '/' - if (confirm(`Do you really want to delete "${path}" ?`)) { + modalDialogCustom.confirm(null, `Do you really want to delete "${path}" ?`, () => { li.parentElement.removeChild(li) removeSubtree(files, path, isFolder) - } + }) } function editModeOn (event) { @@ -213,31 +219,38 @@ function fileExplorer (appAPI, files) { function editModeOff (event) { var label = this + function rename () { + var newPath = label.dataset.path + newPath = newPath.split('/') + newPath[newPath.length - 1] = label.innerText + newPath = newPath.join('/') + if (label.innerText === '') { + modalDialogCustom.alert('File name cannot be empty') + label.innerText = textUnderEdit + } else if (label.innerText.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) !== null) { + modalDialogCustom.alert('Special characters are not allowed') + label.innerText = textUnderEdit + } else if (!files.exists(newPath)) { + files.rename(label.dataset.path, newPath, isFolder) + } else { + modalDialogCustom.alert('File already exists.') + label.innerText = textUnderEdit + } + } + + function cancelRename () { + label.innerText = textUnderEdit + label.removeAttribute('contenteditable') + label.classList.remove(css.rename) + } + if (event.which === 13) event.preventDefault() if ((event.type === 'blur' || event.which === 27 || event.which === 13) && label.getAttribute('contenteditable')) { var isFolder = label.className.indexOf('folder') !== -1 var save = textUnderEdit !== label.innerText - if (save && event.which !== 13) save = confirm('Do you want to rename?') - if (save) { - var newPath = label.dataset.path - newPath = newPath.split('/') - newPath[newPath.length - 1] = label.innerText - newPath = newPath.join('/') - if (label.innerText === '') { - modalDialogCustom.alert('File name cannot be empty') - label.innerText = textUnderEdit - } else if (label.innerText.match(/(\/|:|\*|\?|"|<|>|\\|\||')/) !== null) { - modalDialogCustom.alert('Special characters are not allowed') - label.innerText = textUnderEdit - } else if (!files.exists(newPath)) { - files.rename(label.dataset.path, newPath, isFolder) - } else { - modalDialogCustom.alert('File already exists.') - label.innerText = textUnderEdit - } - } else label.innerText = textUnderEdit - label.removeAttribute('contenteditable') - label.classList.remove(css.rename) + if (save && event.which !== 13) { + modalDialogCustom.confirm(null, `Do you want to rename?`, () => { rename() }, () => { cancelRename() }) + } } } diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index cbd9f71f35..94356b1058 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -1,4 +1,3 @@ -/* global confirm, prompt */ var async = require('async') var $ = require('jquery') var csjs = require('csjs-inject') @@ -314,13 +313,15 @@ function filepanel (appAPI, filesProvider) { 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 (data.html_url) { + modalDialogCustom.confirm(null, `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?')) { - // package only files from the browser storage. + + function toGist () { packageFiles(filesProvider['browser'], (error, packaged) => { if (error) { console.log(error) @@ -339,30 +340,31 @@ function filepanel (appAPI, filesProvider) { } }) } + modalDialogCustom.confirm(null, `Are you very sure you want to publish all your files anonymously as a public gist on github.com?`, () => { + toGist() + }) } // ------------------ 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 - } - // package only files from the browser storage. - packageFiles(filesProvider['browser'], (error, packaged) => { - if (error) { - console.log(error) - } else { - $('