mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Add Git::checkoutHeadForEditor
This moves the logic from Editor::checkoutHead
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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: ->
|
||||
|
||||
Reference in New Issue
Block a user