Merge remote-tracking branch 'origin/master' into cson-snippets

This commit is contained in:
Nathan Sobo
2013-01-07 21:53:36 -07:00
15 changed files with 157 additions and 60 deletions

View File

@@ -148,7 +148,7 @@ class Editor extends View
'core:select-down': @selectDown
'core:select-to-top': @selectToTop
'core:select-to-bottom': @selectToBottom
'core:close': @close
'core:close': @destroyActiveEditSession
'editor:save': @save
'editor:newline-below': @insertNewlineBelow
'editor:toggle-soft-tabs': @toggleSoftTabs
@@ -176,6 +176,7 @@ class Editor extends View
'editor:toggle-line-comments': @toggleLineCommentsInSelection
'editor:log-cursor-scope': @logCursorScope
'editor:checkout-head-revision': @checkoutHead
'editor:close-other-editors': @destroyInactiveEditSessions
documentation = {}
for name, method of editorBindings
@@ -446,17 +447,29 @@ class Editor extends View
destroyActiveEditSession: ->
@destroyEditSessionIndex(@getActiveEditSessionIndex())
destroyEditSessionIndex: (index) ->
if @editSessions.length == 1
@remove()
else
editSession = @editSessions[index]
if index is @getActiveEditSessionIndex()
destroyEditSessionIndex: (index, callback) ->
return if @mini
editSession = @editSessions[index]
destroySession = =>
if index is @getActiveEditSessionIndex() and @editSessions.length > 1
@loadPreviousEditSession()
_.remove(@editSessions, editSession)
editSession.destroy()
@trigger 'editor:edit-session-removed', [editSession, index]
@remove() if @editSessions.length is 0
callback(index) if callback
if editSession.buffer.isModified()
@promptToSaveDirtySession(editSession, destroySession)
else
destroySession(editSession)
destroyInactiveEditSessions: ->
destroyIndex = (index) =>
index++ if @activeEditSession is @editSessions[index]
@destroyEditSessionIndex(index, destroyIndex) if @editSessions[index]
destroyIndex(0)
loadNextEditSession: ->
nextIndex = (@getActiveEditSessionIndex() + 1) % @editSessions.length
@setActiveEditSessionIndex(nextIndex)
@@ -625,14 +638,14 @@ class Editor extends View
@removeClass 'soft-wrap'
$(window).off 'resize', @_setSoftWrapColumn
save: (onSuccess) ->
save: (session=@activeEditSession, onSuccess) ->
if @getPath()
@activeEditSession.save()
session.save()
onSuccess?()
else
atom.showSaveDialog (path) =>
if path
@activeEditSession.saveAs(path)
session.saveAs(path)
onSuccess?()
autosave: ->
@@ -670,19 +683,16 @@ class Editor extends View
rootView: ->
@parents('#root-view').view()
close: ->
return if @mini
if @getBuffer().isModified()
filename = if @getPath() then fs.base(@getPath()) else "untitled buffer"
atom.confirm(
"'#{filename}' has changes, do you want to save them?"
"Your changes will be lost if you don't save them"
"Save", (=> @save(=> @destroyActiveEditSession())),
"Cancel", null
"Don't save", (=> @destroyActiveEditSession())
)
else
@destroyActiveEditSession()
promptToSaveDirtySession: (session, callback) ->
path = session.getPath()
filename = if path then fs.base(path) else "untitled buffer"
atom.confirm(
"'#{filename}' has changes, do you want to save them?"
"Your changes will be lost if you don't save them"
"Save", => @save(session, callback),
"Cancel", null
"Don't save", callback
)
remove: (selector, keepData) ->
return super if keepData

View File

@@ -1,3 +1,5 @@
$ = require 'jquery'
module.exports =
class Git
@@ -15,6 +17,9 @@ class Git
constructor: (path) ->
@repo = new GitRepository(path)
$(window).on 'focus', => @refreshIndex()
refreshIndex: -> @repo.refreshIndex()
getPath: -> @repo.getPath()
@@ -31,19 +36,25 @@ class Git
isPathIgnored: (path) ->
@repo.isIgnored(@relativize(path))
isPathModified: (path) ->
isStatusModified: (status) ->
modifiedFlags = @statusFlags.working_dir_modified |
@statusFlags.working_dir_delete |
@statusFlags.working_dir_typechange |
@statusFlags.index_modified |
@statusFlags.index_deleted |
@statusFlags.index_typechange
(@getPathStatus(path) & modifiedFlags) > 0
(status & modifiedFlags) > 0
isPathNew: (path) ->
isPathModified: (path) ->
@isStatusModified(@getPathStatus(path))
isStatusNew: (status) ->
newFlags = @statusFlags.working_dir_new |
@statusFlags.index_new
(@getPathStatus(path) & newFlags) > 0
(status & newFlags) > 0
isPathNew: (path) ->
@isStatusNew(@getPathStatus(path))
relativize: (path) ->
workingDirectory = @getWorkingDirectory()

View File

@@ -23,6 +23,7 @@
'pagedown': 'core:page-down'
'meta-S': 'window:save-all'
'meta-W': 'window:close'
'meta-+': 'window:increase-font-size'
'meta--': 'window:decrease-font-size'
'ctrl-w w': 'window:focus-next-pane'

View File

@@ -4,7 +4,6 @@
'meta-enter': 'editor:newline-below'
'tab': 'editor:indent'
'meta-d': 'editor:delete-line'
'alt-meta-w': 'editor:toggle-soft-wrap'
'ctrl-[': 'editor:fold-current-row'
'ctrl-]': 'editor:unfold-current-row'
'ctrl-{': 'editor:fold-all'
@@ -33,3 +32,4 @@
'meta-alt-p': 'editor:log-cursor-scope'
'meta-u': 'editor:upper-case'
'meta-U': 'editor:lower-case'
'alt-meta-w': 'editor:close-other-editors'

View File

@@ -29,6 +29,7 @@ windowAdditions =
@pasteboard = new Pasteboard
$(window).on 'core:close', => @close()
$(window).command 'window:close', => @close()
# This method is intended only to be run when starting a normal application
# Note: RootView assigns itself on window on initialization so that
@@ -46,7 +47,8 @@ windowAdditions =
false
shutdown: ->
@rootView.deactivate()
@rootView?.deactivate()
@rootView = null
$(window).unbind('focus')
$(window).unbind('blur')
$(window).off('before')