Commit 2e6bb7e0 authored by yann300's avatar yann300 Committed by Aniket

simplify "openFile" and make it async

parent cc5378ba
...@@ -177,7 +177,7 @@ class FileManager extends Plugin { ...@@ -177,7 +177,7 @@ class FileManager extends Plugin {
} }
await this._handleExists(path, `Cannot open file ${path}`) await this._handleExists(path, `Cannot open file ${path}`)
await this._handleIsFile(path, `Cannot open file ${path}`) await this._handleIsFile(path, `Cannot open file ${path}`)
return this.openFile(path) await this.openFile(path)
} catch (e) { } catch (e) {
throw new Error(e) throw new Error(e)
} }
...@@ -601,8 +601,11 @@ class FileManager extends Plugin { ...@@ -601,8 +601,11 @@ class FileManager extends Plugin {
this.events.emit('noFileSelected') this.events.emit('noFileSelected')
} }
openFile (file) { async openFile (file) {
const _openFile = (file) => { if (!file) {
this.emit('noFileSelected')
this.events.emit('noFileSelected')
} else {
this.saveCurrentFile() this.saveCurrentFile()
let resolved let resolved
try { try {
...@@ -614,26 +617,27 @@ class FileManager extends Plugin { ...@@ -614,26 +617,27 @@ class FileManager extends Plugin {
const provider = resolved.provider const provider = resolved.provider
this._deps.config.set('currentFile', file) this._deps.config.set('currentFile', file)
this.openedFiles[file] = file this.openedFiles[file] = file
provider.get(file, (error, content) => { await (() => {
if (error) { return new Promise((resolve, reject) => {
console.log(error) provider.get(file, (error, content) => {
} else { if (error) {
if (provider.isReadOnly(file)) { console.log(error)
this.editor.openReadOnly(file, content) reject(error)
} else { } else {
this.editor.open(file, content) if (provider.isReadOnly(file)) {
} this.editor.openReadOnly(file, content)
// TODO: Only keep `this.emit` (issue#2210) } else {
this.emit('currentFileChanged', file) this.editor.open(file, content)
this.events.emit('currentFileChanged', file) }
} // TODO: Only keep `this.emit` (issue#2210)
}) this.emit('currentFileChanged', file)
} this.events.emit('currentFileChanged', file)
if (file) return _openFile(file) resolve()
else { }
this.emit('noFileSelected') })
this.events.emit('noFileSelected') })
} })()
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment