Handle save in panes with new 'core:save' event

This commit is contained in:
Nathan Sobo
2013-02-28 10:48:32 -07:00
committed by probablycorey
parent 6ae684d609
commit 699e780e99
5 changed files with 45 additions and 13 deletions

View File

@@ -270,6 +270,42 @@ describe "Pane", ->
expect(containerCloseHandler).not.toHaveBeenCalled()
describe "core:save", ->
describe "when the current item has a path", ->
describe "when the current item has a save method", ->
it "saves the current item", ->
spyOn(editSession2, 'save')
pane.showItem(editSession2)
pane.trigger 'core:save'
expect(editSession2.save).toHaveBeenCalled()
describe "when the current item has no save method", ->
it "does nothing", ->
expect(pane.activeItem.save).toBeUndefined()
pane.trigger 'core:save'
describe "when the current item has no path", ->
beforeEach ->
spyOn(atom, 'showSaveDialog')
describe "when the current item has a saveAs method", ->
it "opens a save dialog and saves the current item as the selected path", ->
spyOn(editSession2, 'saveAs')
editSession2.buffer.setPath(undefined)
pane.showItem(editSession2)
pane.trigger 'core:save'
expect(atom.showSaveDialog).toHaveBeenCalled()
atom.showSaveDialog.argsForCall[0][0]('/selected/path')
expect(editSession2.saveAs).toHaveBeenCalledWith('/selected/path')
describe "when the current item has no saveAs method", ->
it "does nothing", ->
expect(pane.activeItem.saveAs).toBeUndefined()
pane.trigger 'core:save'
expect(atom.showSaveDialog).not.toHaveBeenCalled()
describe "pane:show-next-item and pane:show-previous-item", ->
it "advances forward/backward through the pane's items, looping around at either end", ->
expect(pane.activeItem).toBe view1

View File

@@ -152,7 +152,6 @@ class Editor extends View
'core:select-down': @selectDown
'core:select-to-top': @selectToTop
'core:select-to-bottom': @selectToBottom
'editor:save': @save
'editor:save-as': @saveAs
'editor:newline-below': @insertNewlineBelow
'editor:newline-above': @insertNewlineAbove
@@ -611,13 +610,6 @@ class Editor extends View
@removeClass 'soft-wrap'
$(window).off 'resize', @_setSoftWrapColumn
save: (session=@activeEditSession, onSuccess) ->
if @getPath()
session.save()
onSuccess?()
else
@saveAs(session, onSuccess)
saveAs: (session=@activeEditSession, onSuccess) ->
atom.showSaveDialog (path) =>
if path

View File

@@ -1,4 +1,5 @@
'body':
'meta-s': 'core:save'
'enter': 'core:confirm'
'escape': 'core:cancel'
'meta-w': 'core:close'

View File

@@ -2,7 +2,6 @@
'meta-T': 'editor:undo-close-session'
'.editor':
'meta-s': 'editor:save'
'meta-S': 'editor:save-as'
'enter': 'editor:newline'
'meta-enter': 'editor:newline-below'

View File

@@ -21,6 +21,7 @@ class Pane extends View
@showItem(@items[0])
@command 'core:close', @destroyActiveItem
@command 'core:save', @saveActiveItem
@command 'pane:show-next-item', @showNextItem
@command 'pane:show-previous-item', @showPreviousItem
@command 'pane:split-left', => @splitLeft()
@@ -115,14 +116,17 @@ class Pane extends View
"Don't Save", nextAction
)
saveActiveItem: =>
@saveItem(@activeItem)
saveItem: (item, nextAction) ->
if item.getPath()
if item.getPath?()
item.save()
nextAction()
else
nextAction?()
else if item.saveAs?
atom.showSaveDialog (path) ->
item.saveAs(path)
nextAction()
nextAction?()
removeItem: (item) ->
index = @items.indexOf(item)