Add Git::checkoutHeadForEditor

This moves the logic from Editor::checkoutHead
This commit is contained in:
Kevin Sawicki
2014-08-13 15:41:50 -07:00
parent 1515690302
commit 41c62e8628
4 changed files with 21 additions and 26 deletions

View File

@@ -500,7 +500,7 @@ EditorComponent = React.createClass
'editor:fold-at-indent-level-9': => editor.foldAllAtIndentLevel(8)
'editor:toggle-line-comments': => editor.toggleLineCommentsInSelection()
'editor:log-cursor-scope': => editor.logCursorScope()
'editor:checkout-head-revision': => editor.checkoutHead()
'editor:checkout-head-revision': => atom.project.getRepo()?.checkoutHeadForEditor(editor)
'editor:copy-path': => editor.copyPathToClipboard()
'editor:move-line-up': => editor.moveLineUp()
'editor:move-line-down': => editor.moveLineDown()

View File

@@ -237,7 +237,7 @@ class EditorView extends View
'editor:fold-at-indent-level-9': => @editor.foldAllAtIndentLevel(8)
'editor:toggle-line-comments': => @toggleLineCommentsInSelection()
'editor:log-cursor-scope': => @logCursorScope()
'editor:checkout-head-revision': => @checkoutHead()
'editor:checkout-head-revision': => atom.project.getRepo()?.checkoutHeadForEditor(@editor)
'editor:copy-path': => @copyPathToClipboard()
'editor:move-line-up': => @editor.moveLineUp()
'editor:move-line-down': => @editor.moveLineDown()
@@ -344,11 +344,6 @@ class EditorView extends View
getPlaceholderText: ->
@placeholderText
# Checkout the HEAD revision of this editor's file.
checkoutHead: ->
if path = @editor.getPath()
atom.project.getRepo()?.checkoutHead(path)
configure: ->
@subscribe atom.config.observe 'editor.showLineNumbers', (showLineNumbers) => @gutter.setShowLineNumbers(showLineNumbers)
@subscribe atom.config.observe 'editor.showInvisibles', (showInvisibles) => @setShowInvisibles(showInvisibles)

View File

@@ -446,25 +446,6 @@ class Editor extends Model
# filePath - A {String} path.
saveAs: (filePath) -> @buffer.saveAs(filePath)
checkoutHead: ->
if (filePath = @getPath()) and (repo = atom.project.getRepo())
confirmed = false
if atom.config.get("editor.confirmCheckoutHead")
atom.confirm
message: "Are you sure you want to revert this file to the last Git commit?"
detailedMessage: "You are reverting: #{filePath}"
buttons:
"Revert": ->
confirmed = true
"Cancel": null
else
confirmed = true
if confirmed
@buffer.reload() if @buffer.isModified()
repo.checkoutHead(filePath)
# Copies the current file path to the native clipboard.
copyPathToClipboard: ->
if filePath = @getPath()

View File

@@ -93,6 +93,25 @@ class Git
@getPathStatus(path)
@subscribe buffer, 'destroyed', => @unsubscribe(buffer)
# Subscribes to editor view event.
checkoutHeadForEditor: (editor) ->
filePath = editor.getPath()
return unless filePath
revert = =>
editor.buffer.reload() if editor.buffer.isModified()
@checkoutHead(filePath)
if atom.config.get('editor.confirmCheckoutHead')
atom.confirm
message: "Are you sure you want to revert this file to the last Git commit?"
detailedMessage: "You are reverting: #{filePath}"
buttons:
Revert: revert
Cancel: null
else
revert()
# Public: Destroy this `Git` object. This destroys any tasks and subscriptions
# and releases the underlying libgit2 repository handle.
destroy: ->