From 73948443d565818c746e5670b077d870c199cfb6 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 1 Apr 2019 10:52:39 +0200 Subject: [PATCH] warn when plugin try using setFile --- src/app/files/fileManager.js | 20 ++++++++++++++++++-- src/app/ui/tooltip.js | 21 ++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index c4cc3a9d63..ee21c03efc 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.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`
+ +
` + 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 diff --git a/src/app/ui/tooltip.js b/src/app/ui/tooltip.js index b93a637025..3634650023 100644 --- a/src/app/ui/tooltip.js +++ b/src/app/ui/tooltip.js @@ -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`
${tooltipText} ${action}
` - 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 + } }