From 699e780e99429a2290ffd94c7ab17e85fef78dc4 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 28 Feb 2013 10:48:32 -0700 Subject: [PATCH] Handle save in panes with new 'core:save' event --- spec/app/pane-spec.coffee | 36 ++++++++++++++++++++++++++++++++++++ src/app/editor.coffee | 8 -------- src/app/keymaps/atom.cson | 1 + src/app/keymaps/editor.cson | 1 - src/app/pane.coffee | 12 ++++++++---- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/spec/app/pane-spec.coffee b/spec/app/pane-spec.coffee index 7285ab778..96973f95e 100644 --- a/spec/app/pane-spec.coffee +++ b/spec/app/pane-spec.coffee @@ -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 diff --git a/src/app/editor.coffee b/src/app/editor.coffee index 85cc1298a..f9b65b835 100644 --- a/src/app/editor.coffee +++ b/src/app/editor.coffee @@ -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 diff --git a/src/app/keymaps/atom.cson b/src/app/keymaps/atom.cson index 4dbe961a1..eb6b1628e 100644 --- a/src/app/keymaps/atom.cson +++ b/src/app/keymaps/atom.cson @@ -1,4 +1,5 @@ 'body': + 'meta-s': 'core:save' 'enter': 'core:confirm' 'escape': 'core:cancel' 'meta-w': 'core:close' diff --git a/src/app/keymaps/editor.cson b/src/app/keymaps/editor.cson index e30e84e9b..fc8c859d4 100644 --- a/src/app/keymaps/editor.cson +++ b/src/app/keymaps/editor.cson @@ -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' diff --git a/src/app/pane.coffee b/src/app/pane.coffee index 6829b33df..3295daa20 100644 --- a/src/app/pane.coffee +++ b/src/app/pane.coffee @@ -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)