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,9 +617,12 @@ class FileManager extends Plugin { ...@@ -614,9 +617,12 @@ 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
await (() => {
return new Promise((resolve, reject) => {
provider.get(file, (error, content) => { provider.get(file, (error, content) => {
if (error) { if (error) {
console.log(error) console.log(error)
reject(error)
} else { } else {
if (provider.isReadOnly(file)) { if (provider.isReadOnly(file)) {
this.editor.openReadOnly(file, content) this.editor.openReadOnly(file, content)
...@@ -626,13 +632,11 @@ class FileManager extends Plugin { ...@@ -626,13 +632,11 @@ class FileManager extends Plugin {
// TODO: Only keep `this.emit` (issue#2210) // TODO: Only keep `this.emit` (issue#2210)
this.emit('currentFileChanged', file) this.emit('currentFileChanged', file)
this.events.emit('currentFileChanged', file) this.events.emit('currentFileChanged', file)
resolve()
} }
}) })
} })
if (file) return _openFile(file) })()
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