mirror of
https://github.com/atom/atom.git
synced 2026-02-14 08:35:11 -05:00
Show a warning prompt when opening files over 20MB
We still have some trouble on files this large. I want to show a progress bar, but for now this is better than freezing without any warning at all.
This commit is contained in:
@@ -323,8 +323,22 @@ class Project extends Model
|
||||
# allow ENOENT errors to create an editor for paths that dont exist
|
||||
throw error unless error.code is 'ENOENT'
|
||||
|
||||
@bufferForPath(filePath).then (buffer) =>
|
||||
@buildEditorForBuffer(buffer, options)
|
||||
absoluteFilePath = @resolvePath(filePath)
|
||||
|
||||
fileSize = fs.getSizeSync(absoluteFilePath)
|
||||
|
||||
if fileSize >= 20 * 1048576 # 20MB
|
||||
choice = atom.confirm
|
||||
message: 'Atom can have issues with files over 20MB.'
|
||||
detailedMessage: "Do you still want to try to load this?"
|
||||
buttons: ["Open", "Cancel"]
|
||||
if choice is 1
|
||||
error = new Error
|
||||
error.code = 'CANCELLED'
|
||||
throw error
|
||||
|
||||
@bufferForPath(absoluteFilePath).then (buffer) =>
|
||||
@buildEditorForBuffer(buffer, _.extend({fileSize}, options))
|
||||
|
||||
# Retrieves all the {TextBuffer}s in the project; that is, the
|
||||
# buffers for all open files.
|
||||
@@ -354,8 +368,7 @@ class Project extends Model
|
||||
# * `filePath` A {String} representing a path. If `null`, an "Untitled" buffer is created.
|
||||
#
|
||||
# Returns a promise that resolves to the {TextBuffer}.
|
||||
bufferForPath: (filePath) ->
|
||||
absoluteFilePath = @resolvePath(filePath)
|
||||
bufferForPath: (absoluteFilePath) ->
|
||||
existingBuffer = @findBufferForPath(absoluteFilePath) if absoluteFilePath
|
||||
Q(existingBuffer ? @buildBuffer(absoluteFilePath))
|
||||
|
||||
@@ -405,7 +418,7 @@ class Project extends Model
|
||||
buffer?.destroy()
|
||||
|
||||
buildEditorForBuffer: (buffer, editorOptions) ->
|
||||
largeFileMode = fs.getSizeSync(buffer.getPath()) >= 2 * 1048576 # 2MB
|
||||
largeFileMode = editorOptions.fileSize >= 2 * 1048576 # 2MB
|
||||
editor = new TextEditor(_.extend({buffer, largeFileMode, registerEditor: true}, editorOptions))
|
||||
editor
|
||||
|
||||
|
||||
@@ -429,15 +429,16 @@ class Workspace extends Model
|
||||
item ?= atom.project.open(uri, options)
|
||||
catch error
|
||||
switch error.code
|
||||
when 'EFILETOOLARGE'
|
||||
atom.notifications.addWarning("#{error.message} Large file support is being tracked at [atom/atom#307](https://github.com/atom/atom/issues/307).")
|
||||
when 'CANCELLED'
|
||||
return Q()
|
||||
when 'EACCES'
|
||||
atom.notifications.addWarning("Permission denied '#{error.path}'")
|
||||
return Q()
|
||||
when 'EPERM', 'EBUSY'
|
||||
atom.notifications.addWarning("Unable to open '#{error.path}'", detail: error.message)
|
||||
return Q()
|
||||
else
|
||||
throw error
|
||||
return Q()
|
||||
|
||||
Q(item)
|
||||
.then (item) =>
|
||||
|
||||
Reference in New Issue
Block a user