Store Git instance in Buffer

Access it from StatusBar for checking
path status and current branch.
This commit is contained in:
Kevin Sawicki
2012-11-05 12:03:54 -08:00
parent c8258894c7
commit 3df28ab375
2 changed files with 9 additions and 9 deletions

View File

@@ -22,6 +22,7 @@ class Buffer
anchors: null
anchorRanges: null
refcount: 0
git: null
constructor: (path, @project) ->
@id = @constructor.idCounter++
@@ -85,6 +86,8 @@ class Buffer
setPath: (path) ->
return if path == @getPath()
@git = new Git(path)
@file?.off()
@file = new File(path)
@subscribeToFile()
@@ -367,10 +370,12 @@ class Buffer
line = @lineForRow(row)
console.log row, line, line.length
getGit: -> @git
checkoutHead: ->
path = @getPath()
return unless path
if new Git(path).checkoutHead(path)
if @git?.checkoutHead(path)
@trigger 'git-status-change'
_.extend(Buffer.prototype, EventEmitter)

View File

@@ -1,6 +1,5 @@
_ = require 'underscore'
{View, $$} = require 'space-pen'
Git = require 'git'
module.exports =
class StatusBar extends View
@@ -29,8 +28,6 @@ class StatusBar extends View
@span class: 'branch-label', outlet: 'branchLabel'
@span outlet: 'cursorPosition'
git: null
initialize: (@rootView, @editor) ->
@updatePathText()
@editor.on 'editor-path-change', =>
@@ -45,8 +42,6 @@ class StatusBar extends View
subscribeToBuffer: ->
@buffer?.off '.status-bar'
@buffer = @editor.getBuffer()
if path = @editor.getPath()
@git = new Git(path)
@buffer.on 'change.status-bar', => _.delay (=> @updateBufferModifiedText()), 50
@buffer.on 'after-save.status-bar', => _.delay (=> @updateStatusBar()), 50
@buffer.on 'git-status-change.status-bar', => _.delay (=> @updateStatusBar()), 50
@@ -70,7 +65,7 @@ class StatusBar extends View
@branchArea.hide()
return unless path
head = @git.getShortHead()
head = @buffer.getGit()?.getShortHead()
@branchLabel.text(head)
@branchArea.show() if head
@@ -79,9 +74,9 @@ class StatusBar extends View
@gitStatusIcon.empty()
return unless path
if @git.isPathModified(path)
if @buffer.getGit()?.isPathModified(path)
@gitStatusIcon.append $$ -> @span '\uf26d', class: 'modified-status-icon'
else if @git.isPathNew(path)
else if @buffer.getGit()?.isPathNew(path)
@gitStatusIcon.append $$ -> @span '\uf26b', class: 'new-status-icon'
updatePathText: ->