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')

View File

@@ -30,6 +30,20 @@ describe "EventPalette", ->
else
expect(eventLi).not.toExist()
it "displays all events registerd on the window", ->
editorEvents = rootView.getActiveEditor().events()
windowEvents = $(window).events()
expect(_.isEmpty(windowEvents)).toBeFalsy()
for eventName, description of windowEvents
eventLi = palette.list.children("[data-event-name='#{eventName}']")
description = editorEvents[eventName] unless description
if description
expect(eventLi).toExist()
expect(eventLi.find('.event-name')).toHaveText(eventName)
expect(eventLi.find('.event-description')).toHaveText(description)
else
expect(eventLi).not.toExist()
it "focuses the mini-editor and selects the first event", ->
expect(palette.miniEditor.isFocused).toBeTruthy()
expect(palette.find('.event:first')).toHaveClass 'selected'

View File

@@ -28,7 +28,7 @@ class EventPalette extends SelectList
@keyBindings = _.losslessInvert(keymap.bindingsForElement(@previouslyFocusedElement))
events = []
for eventName, eventDescription of @previouslyFocusedElement.events()
for eventName, eventDescription of _.extend($(window).events(), @previouslyFocusedElement.events())
events.push({eventName, eventDescription}) if eventDescription
events = _.sortBy events, (e) -> e.eventDescription

View File

@@ -76,7 +76,10 @@ class StatusBar extends View
@gitStatusIcon.addClass('git-status octicons')
git = @buffer.getRepo()
if git?.isPathModified(path)
return unless git
status = git.getPathStatus(path)
if git.isStatusModified(status)
@gitStatusIcon.addClass('modified-status-icon')
stats = git.getDiffStats(path)
if stats.added and stats.deleted
@@ -87,7 +90,7 @@ class StatusBar extends View
@gitStatusIcon.text("-#{stats.deleted}")
else
@gitStatusIcon.text('')
else if git?.isPathNew(path)
else if git.isStatusNew(status)
@gitStatusIcon.addClass('new-status-icon')
@gitStatusIcon.text("+#{@buffer.getLineCount()}")

View File

@@ -23,17 +23,15 @@ class DirectoryView extends View
@disclosureArrow.on 'click', => @toggleExpansion()
repo = @project.repo
iconClass = 'directory-icon'
if repo?
path = @directory.getPath()
@directoryName.addClass('ignored') if repo.isPathIgnored(path)
if path is repo.getWorkingDirectory()
@directoryName.addClass('repository-icon')
else if repo.isSubmodule(path)
@directoryName.addClass('submodule-icon')
if parent
@directoryName.addClass('ignored') if repo.isPathIgnored(path)
iconClass = 'submodule-icon' if repo.isSubmodule(path)
else
@directoryName.addClass('directory-icon')
else
@directoryName.addClass('directory-icon')
iconClass = 'repository-icon' if path is repo.getWorkingDirectory()
@directoryName.addClass(iconClass)
getPath: ->
@directory.path

View File

@@ -36,10 +36,12 @@ class FileView extends View
path = @getPath()
if repo.isPathIgnored(path)
@addClass('ignored')
else if repo.isPathModified(path)
@addClass('modified')
else if repo.isPathNew(path)
@addClass('new')
else
status = repo.getPathStatus(path)
if repo.isStatusModified(status)
@addClass('modified')
else if repo.isStatusNew(status)
@addClass('new')
getPath: ->
@file.path