Merge commit '0384f025dd6915d2d9771e37983dc839e49b28f7'

This commit is contained in:
Nathan Sobo
2012-07-26 14:11:29 -06:00
4 changed files with 72 additions and 2 deletions

View File

@@ -110,6 +110,27 @@ describe "Editor", ->
expect(editor.isFocused).toBeFalsy()
expect(editor).not.toHaveClass('focused')
describe "when the activeEditSession's file is modified on disk", ->
it "triggers an alert", ->
path = "/tmp/atom-changed-file.txt"
fs.write(path, "")
editSession = project.buildEditSessionForPath(path)
editor.edit(editSession)
editor.insertText("now the buffer is modified")
fileChangeHandler = jasmine.createSpy('fileChange')
editSession.buffer.file.on 'contents-change', fileChangeHandler
spyOn($native, "alert")
fs.write(path, "a file change")
waitsFor "file to trigger contents-change event", ->
fileChangeHandler.callCount > 0
runs ->
expect($native.alert).toHaveBeenCalled()
describe ".remove()", ->
it "removes subscriptions from all edit session buffers", ->
previousEditSession = editor.activeEditSession
@@ -227,6 +248,26 @@ describe "Editor", ->
editor.activeEditSession.selectToEndOfLine()
expect(editor.getSelectionView().find('.selection')).toExist()
it "triggers alert if edit session's file changed on disk", ->
path = "/tmp/atom-changed-file.txt"
fs.write(path, "")
editSession = project.buildEditSessionForPath(path)
editSession.insertText("a buffer change")
fileChangeHandler = jasmine.createSpy('fileChange')
editSession.buffer.file.on 'contents-change', fileChangeHandler
spyOn($native, "alert")
fs.write(path, "a file change")
waitsFor "file to trigger contents-change event", ->
fileChangeHandler.callCount > 0
runs ->
editor.edit(editSession)
expect($native.alert).toHaveBeenCalled()
describe ".loadNextEditSession()", ->
it "loads the next editor state and wraps to beginning when end is reached", ->
expect(editor.activeEditSession).toBe session2

View File

@@ -81,6 +81,13 @@ class Buffer
@file?.off()
@file = new File(path)
@subscribeToFile()
@file.on "contents-change", =>
if @isModified()
@modifiedOnDisk = true
@trigger "contents-change-on-disk"
else
@setText(fs.read(@file.getPath()))
@modified = false
@trigger "path-change", this
getExtension: ->
@@ -217,6 +224,9 @@ class Buffer
@setPath(path)
@trigger 'after-save'
isInConflict: ->
@isModified() and @isModifiedOnDisk()
isModifiedOnDisk: ->
@modifiedOnDisk

View File

@@ -44,7 +44,10 @@ class EditSession
@buffer.retain()
@buffer.on "path-change.edit-session-#{@id}", =>
@trigger 'buffer-path-change'
@trigger "buffer-path-change"
@buffer.on "contents-change-on-disk.edit-session-#{@id}", =>
@trigger "buffer-contents-change-on-disk"
@buffer.on "update-anchors-after-change.edit-session-#{@id}", =>
@mergeCursors()

View File

@@ -386,10 +386,26 @@ class Editor extends View
@activeEditSession = @editSessions[index]
@activeEditSession.on "buffer-path-change", => @trigger 'editor-path-change'
if @activeEditSession.buffer.isInConflict()
@showBufferConflictAlert(@activeEditSession)
@activeEditSession.on "buffer-contents-change-on-disk", =>
@showBufferConflictAlert(@activeEditSession)
@activeEditSession.on "buffer-path-change", =>
@trigger 'editor-path-change'
@trigger 'editor-path-change'
@renderWhenAttached()
showBufferConflictAlert: (editSession) ->
message = editSession.getPath()
detailedMessage = "Has changed on disk. Do you want to reload it?"
Native.alert message, detailedMessage, [
["Reload", => editSession.buffer.reload()]
["Cancel", => ],
]
activateEditSessionForPath: (path) ->
for editSession, index in @editSessions
if editSession.buffer.getPath() == path