Handle save-as on pane. Replace 'editor:save-as' w/ 'core:save-as'

Pane will only show the saveAs dialog if the item has a `saveAs` method.
This commit is contained in:
Nathan Sobo
2013-02-28 18:00:04 -07:00
committed by probablycorey
parent 59a06acc0b
commit 3f9ee08e76
5 changed files with 33 additions and 10 deletions

View File

@@ -306,6 +306,27 @@ describe "Pane", ->
pane.trigger 'core:save'
expect(atom.showSaveDialog).not.toHaveBeenCalled()
describe "core:save-as", ->
beforeEach ->
spyOn(atom, 'showSaveDialog')
describe "when the current item has a saveAs method", ->
it "opens the save dialog and calls saveAs on the item with the selected path", ->
spyOn(editSession2, 'saveAs')
pane.showItem(editSession2)
pane.trigger 'core:save-as'
expect(atom.showSaveDialog).toHaveBeenCalled()
atom.showSaveDialog.argsForCall[0][0]('/selected/path')
expect(editSession2.saveAs).toHaveBeenCalledWith('/selected/path')
describe "when the current item does not have a saveAs method", ->
it "does nothing", ->
expect(pane.activeItem.saveAs).toBeUndefined()
pane.trigger 'core:save-as'
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-as': @saveAs
'editor:newline-below': @insertNewlineBelow
'editor:newline-above': @insertNewlineAbove
'editor:toggle-soft-tabs': @toggleSoftTabs
@@ -610,12 +609,6 @@ class Editor extends View
@removeClass 'soft-wrap'
$(window).off 'resize', @_setSoftWrapColumn
saveAs: (session=@activeEditSession, onSuccess) ->
atom.showSaveDialog (path) =>
if path
session.saveAs(path)
onSuccess?()
autosave: ->
@save() if @getPath()?

View File

@@ -1,5 +1,6 @@
'body':
'meta-s': 'core:save'
'meta-S': 'core:save-as'
'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-as'
'enter': 'editor:newline'
'meta-enter': 'editor:newline-below'
'meta-shift-enter': 'editor:newline-above'

View File

@@ -22,6 +22,7 @@ class Pane extends View
@command 'core:close', @destroyActiveItem
@command 'core:save', @saveActiveItem
@command 'core:save-as', @saveActiveItemAs
@command 'pane:show-next-item', @showNextItem
@command 'pane:show-previous-item', @showPreviousItem
@command 'pane:split-left', => @splitLeft()
@@ -119,12 +120,20 @@ class Pane extends View
saveActiveItem: =>
@saveItem(@activeItem)
saveActiveItemAs: =>
@saveItemAs(@activeItem)
saveItem: (item, nextAction) ->
if item.getPath?()
item.save()
nextAction?()
else if item.saveAs?
atom.showSaveDialog (path) ->
else
@saveItemAs(item, nextAction)
saveItemAs: (item, nextAction) ->
return unless item.saveAs?
atom.showSaveDialog (path) =>
if path
item.saveAs(path)
nextAction?()