Merge pull request #2145 from ethereum/setFile_l

added closure functions for onclick events
pull/1/head
Liana Husikyan 5 years ago committed by GitHub
commit 3742963b3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      src/app/files/fileManager.js
  2. 17
      src/app/ui/tooltip.js

@ -135,44 +135,39 @@ class FileManager extends FileSystemApi {
}
async setFile (path, content) {
let reject = false
let saveAsCopy = false
function acceptFileRewriting (e, toaster) {
reject = false
e.target.innerHTML = 'Accepted'
toaster.hide()
toaster.forceResolve()
}
function cancelFileRewriting (e, toaster) {
reject = true
e.target.innerHTML = 'Canceled'
toaster.hide()
}
const saveFileAsCopy = (e, toaster) => {
if (saveAsCopy) return
this._saveAsCopy(path, content)
saveAsCopy = true
e.target.innerHTML = 'Saved'
toaster.hide()
}
if (this.currentRequest) {
let reject = 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 = false
e.target.innerHTML = 'Accepted'
toaster.hide()
toaster.forceResolve()
}}>
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => acceptFileRewriting(e, toaster)}>
Accept
</button>
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => {
reject = true
e.target.innerHTML = 'Canceled'
toaster.hide()
}}>
<button class="btn btn-primary btn-sm m-1" onclick=${(e) => cancelFileRewriting(e, toaster)}>
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()
}}>
<button class="btn btn-primary btn-sm m-1" onclick="${(e) => saveFileAsCopy(e, toaster)}">
Save As Copy
</button>
</div>
@ -206,6 +201,20 @@ class FileManager extends FileSystemApi {
})
}
_saveAsCopy (path, content) {
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)
})
}
}
removeTabsOf (provider) {
for (var tab in this.openedFiles) {
if (this.fileProviderOf(tab).type === provider.type) {

@ -55,8 +55,17 @@ class Toaster {
const shortTooltipText = (canShorten && tooltipText.length > 201) ? tooltipText.substring(0, 200) + '...' : tooltipText
this.resolveFn = resolve
function showFullMessage () {
modal.alert(tooltipText)
}
function closeTheToaster (self) {
self.hide()
over()
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>
<button class="btn btn-secondary btn-sm mx-3" style="white-space: nowrap;" onclick=${() => showFullMessage()}>Show full message</button>
` : ``
this.tooltip = yo`
@ -67,11 +76,7 @@ class Toaster {
${actionElement}
</span>
<span style="align-self: baseline;">
<button class="fas fa-times btn-info mx-1 p-0" onclick=${() => {
this.hide()
over()
resolve()
}}></button>
<button class="fas fa-times btn-info mx-1 p-0" onclick=${() => closeTheToaster(this)}></button>
</span>
</div>`
let timeOut = () => {

Loading…
Cancel
Save