Update status class when window gains focus

This will keep the tree view in sync when Git operations are
performed outside of the editor.
This commit is contained in:
Kevin Sawicki
2013-01-04 15:29:34 -08:00
parent 7228e270b0
commit cde4a567e7
2 changed files with 20 additions and 7 deletions

View File

@@ -887,6 +887,13 @@ describe "TreeView", ->
it "adds a custom style", ->
expect(treeView.find('.file:contains(tree-view.txt)')).toHaveClass 'modified'
describe "when the window gains focus after the contents are restored to a clean state", ->
it "removes the custom style", ->
expect(treeView.find('.file:contains(tree-view.txt)')).toHaveClass 'modified'
fs.write modifiedFile, originalFileContent
$(window).trigger 'focus'
expect(treeView.find('.file:contains(tree-view.txt)')).not.toHaveClass 'modified'
describe "when a file is new", ->
it "adds a custom style", ->
expect(treeView.find('.file:contains(.gitignore)')).toHaveClass 'new'

View File

@@ -9,13 +9,14 @@ class FileView extends View
@content: ({file} = {}) ->
@li class: 'file entry', =>
@span file.getBaseName(), class: 'name', outlet: 'fileName'
@span "", class: 'highlight'
@span '', class: 'highlight'
file: null
initialize: ({@file, project} = {}) ->
path = @getPath()
extension = fs.extension(path)
initialize: ({@file, @project} = {}) ->
@subscribe $(window), 'focus', => @updateStatus()
extension = fs.extension(@getPath())
if fs.isCompressedExtension(extension)
@fileName.addClass('compressed-name')
else if fs.isImageExtension(extension)
@@ -25,11 +26,16 @@ class FileView extends View
else
@fileName.addClass('text-name')
if project.repo.isPathIgnored(path)
@updateStatus()
updateStatus: ->
path = @getPath()
@removeClass('ignored modified new')
if @project.repo.isPathIgnored(path)
@addClass('ignored')
else if project.repo.isPathModified(path)
else if @project.repo.isPathModified(path)
@addClass('modified')
else if project.repo.isPathNew(path)
else if @project.repo.isPathNew(path)
@addClass('new')
getPath: ->