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