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. 61
      src/app/files/fileManager.js
  2. 17
      src/app/ui/tooltip.js

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

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

Loading…
Cancel
Save