warn when plugin try using setFile

pull/1/head
yann300 6 years ago
parent 7bb6393bec
commit 73948443d5
  1. 20
      src/app/files/fileManager.js
  2. 21
      src/app/ui/tooltip.js

@ -1,9 +1,11 @@
'use strict'
import { ApiFactory } from 'remix-plugin'
import yo from 'yo-yo'
const EventEmitter = require('events')
var globalRegistry = require('../../global/registry')
var CompilerImport = require('../compiler/compiler-imports')
import { ApiFactory } from 'remix-plugin'
var toaster = require('../ui/tooltip')
/*
attach to files event (removed renamed)
@ -129,7 +131,21 @@ class FileManager extends ApiFactory {
})
}
setFile (path, content) {
async setFile (path, content) {
if (this.currentRequest) {
let reject = false
const actions = yo`<div class="btn-group">
<button class="btn btn-secondary btn-sm" onclick=${(e) => { reject = true; e.target.innerHTML = 'Aborted' }}>Abort</button>
</div>`
await toaster(`${this.currentRequest.from} is modyfing to ${path}`, actions, { time: 140000 })
if (reject) {
throw new Error(`set file operation on ${path} aborted by user.`)
}
}
this._setFileInternal(path, content)
}
_setFileInternal (path, content) {
const provider = this.fileProviderOf(path)
if (!provider) throw new Error(`${path} not availble`)
// TODO : Add permission

@ -6,14 +6,25 @@ var css = require('./styles/tooltip-styles')
* @param {string} tooltipText The text shown by the tooltip
* @param {HTMLElement} [action] An HTMLElement to display for action
*/
module.exports = function addTooltip (tooltipText, action) {
module.exports = function addTooltip (tooltipText, action, opts) {
opts = defaultOptions(opts)
var tooltip = yo`
<div class="${css.tooltip} bg-secondary">
<span>${tooltipText}</span>
${action}
</div>`
document.body.appendChild(tooltip)
setTimeout(function () {
document.body.removeChild(tooltip)
}, 7000)
return new Promise((resolve, reject) => {
document.body.appendChild(tooltip)
setTimeout(function () {
document.body.removeChild(tooltip)
resolve()
}, opts.time)
})
}
let defaultOptions = (opts) => {
opts = opts || {}
return {
time: opts.time || 70000
}
}

Loading…
Cancel
Save