Merge pull request #2128 from ethereum/setFile_l

setFile
pull/1/head
Liana Husikyan 5 years ago committed by GitHub
commit 30aa20fb99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 60
      src/app/files/fileManager.js
  2. 11
      src/app/ui/tooltip.js

@ -2,9 +2,10 @@
import yo from 'yo-yo'
const EventEmitter = require('events')
var globalRegistry = require('../../global/registry')
var CompilerImport = require('../compiler/compiler-imports')
var toaster = require('../ui/tooltip')
const globalRegistry = require('../../global/registry')
const CompilerImport = require('../compiler/compiler-imports')
const toaster = require('../ui/tooltip')
const helper = require('../../lib/helper.js')
import { FileSystemApi } from 'remix-plugin'
import * as packageJson from '../../../package.json'
@ -136,30 +137,57 @@ class FileManager extends FileSystemApi {
async setFile (path, content) {
if (this.currentRequest) {
let reject = false
let savedAsAnotherFile = false
let saveAsCopy = false
let actions = (toaster) => {
return yo`<div class="container ml-1">
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => { reject = true; e.target.innerHTML = 'Canceled'; toaster.hide() }}>Cancel</button>
return yo`
<div class="container ml-1">
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
if (savedAsAnotherFile) return
savedAsAnotherFile = true
const newPath = path + '.' + this.currentRequest.from
this._setFileInternal(newPath, content)
this.switchFile(newPath)
reject = false
e.target.innerHTML = 'Accepted'
toaster.hide()
toaster.forceResolve()
}}>
Accept
</button>
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
reject = true
e.target.innerHTML = 'Canceled'
toaster.hide()
}}>
Cancel
</button>
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
if (saveAsCopy) return
const fileProvider = this.fileProviderOf(path)
if (fileProvider) {
helper.createNonClashingNameWithPrefix(path, fileProvider, '', (error, copyName) => {
if (error) {
console.log('createNonClashingNameWithPrefix', error)
copyName = path + '.' + this.currentRequest.from
}
this._setFileInternal(copyName, content)
this.switchFile(copyName)
})
}
e.target.innerHTML = 'Saved'
saveAsCopy = true
toaster.hide()
}}>Save As Copy</button>
</div>`
}}>
Save As Copy
</button>
</div>
`
}
await toaster(yo`
<div>
<i class="fas fa-exclamation-triangle text-danger mr-1"></i>
<span>
${this.currentRequest.from}<span class="text-danger"> is modyfing </span>${path}
${this.currentRequest.from}<span class="text-danger font-weight-bold"> is trying to modify </span>${path}
</span>
</div>`, actions, { time: 4000 })
</div>
`, actions, { time: 5000 })
if (reject) throw new Error(`set file operation on ${path} aborted by user.`)
if (savedAsAnotherFile) return
if (saveAsCopy) return
}
this._setFileInternal(path, content)
}

@ -23,6 +23,16 @@ class Toaster {
}, 2000)
animation(this.tooltip, css.animateTop.className)
}
/**
* Force resolve the promise to close
* the toaster ignoring timeout
*/
forceResolve () {
if (this.id) clearTimeout(this.id)
if (this.resolveFn) this.resolveFn()
}
render (tooltipText, actionElement, opts) {
opts = defaultOptions(opts)
let canShorten = true
@ -43,6 +53,7 @@ class Toaster {
return new Promise((resolve, reject) => {
const shortTooltipText = (canShorten && tooltipText.length > 201) ? tooltipText.substring(0, 200) + '...' : tooltipText
this.resolveFn = resolve
let button = tooltipText.length > 201 ? yo`
<button class="btn btn-secondary btn-sm mx-3" style="white-space: nowrap;" onclick=${() => { modal.alert(tooltipText) }}>Show full message</button>

Loading…
Cancel
Save