mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Add Git status indicator to status bar
This commit is contained in:
committed by
Corey Johnson
parent
81fc8d417d
commit
c9f1064d6b
@@ -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()
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user