From cde4a567e79ca0d937bd256b866bafc4fe39656a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 4 Jan 2013 15:29:34 -0800 Subject: [PATCH] Update status class when window gains focus This will keep the tree view in sync when Git operations are performed outside of the editor. --- .../tree-view/spec/tree-view-spec.coffee | 7 +++++++ src/packages/tree-view/src/file-view.coffee | 20 ++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/packages/tree-view/spec/tree-view-spec.coffee b/src/packages/tree-view/spec/tree-view-spec.coffee index 611f4d9d7..664022285 100644 --- a/src/packages/tree-view/spec/tree-view-spec.coffee +++ b/src/packages/tree-view/spec/tree-view-spec.coffee @@ -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' diff --git a/src/packages/tree-view/src/file-view.coffee b/src/packages/tree-view/src/file-view.coffee index bb149a455..0c81ec85a 100644 --- a/src/packages/tree-view/src/file-view.coffee +++ b/src/packages/tree-view/src/file-view.coffee @@ -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: ->