Convert large file warning

This commit is contained in:
Wliu
2017-11-18 00:56:22 +01:00
parent c3bc4973f9
commit 8f81831ad4

View File

@@ -1158,16 +1158,17 @@ module.exports = class Workspace extends Model {
// * `uri` A {String} containing a URI.
//
// Returns a {Promise} that resolves to the {TextEditor} (or other item) for the given URI.
createItemForURI (uri, options) {
async createItemForURI (uri, options) {
if (uri != null) {
for (let opener of this.getOpeners()) {
for (const opener of this.getOpeners()) {
const item = opener(uri, options)
if (item != null) return Promise.resolve(item)
if (item != null) return item
}
}
try {
return this.openTextFile(uri, options)
const item = await this.openTextFile(uri, options)
return item
} catch (error) {
switch (error.code) {
case 'CANCELLED':
@@ -1197,7 +1198,7 @@ module.exports = class Workspace extends Model {
}
}
openTextFile (uri, options) {
async openTextFile (uri, options) {
const filePath = this.project.resolvePath(uri)
if (filePath != null) {
@@ -1214,23 +1215,37 @@ module.exports = class Workspace extends Model {
const fileSize = fs.getSizeSync(filePath)
const largeFileMode = fileSize >= (2 * 1048576) // 2MB
if (fileSize >= (this.config.get('core.warnOnLargeFileLimit') * 1048576)) { // 20MB by default
const choice = this.applicationDelegate.confirm({
let resolveConfirmFileOpenPromise, rejectConfirmFileOpenPromise = []
const confirmFileOpenPromise = new Promise((resolve, reject) => {
resolveConfirmFileOpenPromise = resolve
rejectConfirmFileOpenPromise = reject
})
if (fileSize >= (this.config.get('core.warnOnLargeFileLimit') * 1048576)) { // 40MB by default
this.applicationDelegate.confirm({
message: 'Atom will be unresponsive during the loading of very large files.',
detailedMessage: 'Do you still want to load this file?',
buttons: ['Proceed', 'Cancel']
}, response => {
if (response === 1) {
rejectConfirmFileOpenPromise()
} else {
resolveConfirmFileOpenPromise()
}
})
if (choice === 1) {
const error = new Error()
error.code = 'CANCELLED'
throw error
}
} else {
resolveConfirmFileOpenPromise()
}
return this.project.bufferForPath(filePath, options)
.then(buffer => {
return this.textEditorRegistry.build(Object.assign({buffer, largeFileMode, autoHeight: false}, options))
})
try {
await confirmFileOpenPromise
const buffer = await this.project.bufferForPath(filePath, options)
return this.textEditorRegistry.build(Object.assign({buffer, largeFileMode, autoHeight: false}, options))
} catch (e) {
const error = new Error()
error.code = 'CANCELLED'
throw error
}
}
handleGrammarUsed (grammar) {