Switch File Manager API to promise based methods

pull/3094/head
Grandschtroumpf 6 years ago committed by yann300
parent 73d4fd5ad0
commit b35922b66a
  1. 47
      src/app/files/fileManager.js

@ -119,39 +119,36 @@ class FileManager {
return path ? path[1] : null
}
getCurrentFile (cb) {
var path = this.currentFile()
if (!path) {
cb('no file selected')
} else {
cb(null, path)
}
async getCurrentFile () {
const path = this.currentFile()
if (!path) throw 'no file selected'
return path
}
getFile (path, cb) {
var provider = this.fileProviderOf(path)
if (provider) {
// TODO add approval to user for external plugin to get the content of the given `path`
provider.get(path, (error, content) => {
cb(error, content)
getFile (path) {
const provider = this.fileProviderOf(path)
if (!provider) throw new Error(`${path} not available`)
// TODO: change provider to Promise
return new Promise((resolve, reject) => {
provider.get(path, (err, content) => {
if (err) reject(err)
resolve(content)
})
} else {
cb(path + ' not available')
}
})
}
setFile (path, content, cb) {
var provider = this.fileProviderOf(path)
if (provider) {
// TODO add approval to user for external plugin to set the content of the given `path`
setFile (path, content) {
const provider = this.fileProviderOf(path)
if (!provider) throw new Error(`${path} not availble`)
// TODO : Add permission
// TODO : Change Provider to Promise
return new Promise((resolve, reject) => {
provider.set(path, content, (error) => {
if (error) return cb(error)
if (error) reject(error)
this.syncEditor(path)
cb()
resolve(true)
})
} else {
cb(path + ' not available')
}
})
}
removeTabsOf (provider) {

Loading…
Cancel
Save