From c9f1064d6bc5eddf6a73bfacdeaf7b94dfda0bf7 Mon Sep 17 00:00:00 2001 From: Corey Johnson & Kevin Sawicki Date: Fri, 2 Nov 2012 14:04:25 -0700 Subject: [PATCH] Add Git status indicator to status bar --- spec/app/status-bar-spec.coffee | 22 +++++++++++++++++++++- src/app/status-bar.coffee | 23 +++++++++++++++++------ static/status-bar.css | 16 +++++----------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/spec/app/status-bar-spec.coffee b/spec/app/status-bar-spec.coffee index 589e365e3..d625def9a 100644 --- a/spec/app/status-bar-spec.coffee +++ b/spec/app/status-bar-spec.coffee @@ -103,7 +103,7 @@ describe "StatusBar", -> editor.setCursorScreenPosition([1, 2]) expect(statusBar.cursorPosition.text()).toBe '2,3' - describe "branch label", -> + describe "git branch label", -> beforeEach -> fs.remove('/tmp/.git') if fs.isDirectory('/tmp/.git') rootView.attachToDom() @@ -119,3 +119,23 @@ describe "StatusBar", -> rootView.open(path) expect(statusBar.branchArea).toBeHidden() expect(statusBar.branchLabel.text()).toBe '' + + describe "git status label", -> + [repo, path, originalPathText, newPath] = [] + + beforeEach -> + path = require.resolve('fixtures/git/working-dir/file.txt') + originalPathText = fs.read(path) + rootView.attachToDom() + + afterEach -> + fs.write(path, originalPathText) + + it "displays the modified icon for a changed file", -> + fs.write(path, "i've changed for the worse") + rootView.open(path) + expect(statusBar.gitStatusIcon).toBeVisible() + + it "doesn't display the modified icon for an unchanged file", -> + rootView.open(path) + expect(statusBar.gitStatusIcon).toBeHidden() diff --git a/src/app/status-bar.coffee b/src/app/status-bar.coffee index 3561460da..056128cb7 100644 --- a/src/app/status-bar.coffee +++ b/src/app/status-bar.coffee @@ -20,8 +20,9 @@ class StatusBar extends View @content: -> @div class: 'status-bar', => @div class: 'file-info', => - @div class: 'current-path', outlet: 'currentPath' - @div class: 'buffer-modified', outlet: 'bufferModified' + @span '\uf252', class: 'octicons git-status', outlet: 'gitStatusIcon' + @span class: 'current-path', outlet: 'currentPath' + @span class: 'buffer-modified', outlet: 'bufferModified' @div class: 'cursor-position', => @span outlet: 'branchArea', => @span '\uf020', class: 'octicons' @@ -34,7 +35,6 @@ class StatusBar extends View @subscribeToBuffer() @updatePathText() - @updateBranchText() @updateCursorPositionText() @editor.on 'cursor-move', => _.defer => @updateCursorPositionText() @@ -44,11 +44,13 @@ class StatusBar extends View @buffer?.off '.status-bar' @buffer = @editor.getBuffer() @buffer.on 'change.status-bar', => _.defer => @updateBufferModifiedText() - @buffer.on 'after-save.status-bar', => _.defer => - @updateBranchText() - @updateBufferModifiedText() + @buffer.on 'after-save.status-bar', => _.defer => @updateStatusBar() + @updateStatusBar() + + updateStatusBar: -> @updateBranchText() @updateBufferModifiedText() + @updateStatusText() updateBufferModifiedText: -> if @buffer.isModified() @@ -68,6 +70,15 @@ class StatusBar extends View else @branchArea.hide() + updateStatusText: -> + if path = @editor.getPath() + modified = new Git(path).isModified(path) + + if modified + @gitStatusIcon.show() + else + @gitStatusIcon.hide() + updatePathText: -> if path = @editor.getPath() @currentPath.text(@rootView.project.relativize(path)) diff --git a/static/status-bar.css b/static/status-bar.css index 66edb9f8a..a9909617d 100644 --- a/static/status-bar.css +++ b/static/status-bar.css @@ -10,30 +10,24 @@ display: inline-block; } -.status-bar .file-info .current-path { - float: left; - display: inline-block; -} - -.status-bar .file-info .buffer-modified { - float: right; - display: inline-block; -} - .status-bar .cursor-position { position: absolute; right: 5px; top: 5px; } +.status-bar .file-info .git-status { + color: #FAF05C; +} + .status-bar .octicons { font-family: 'Octicons Regular'; font-size: 14px; width: 14px; height: 14px; + padding-right: 2px; } .status-bar .branch-label { - padding-left: 2px; padding-right: 10px; }