Allow items to provide savePanel options.

This commit is contained in:
Jesse Grosjean
2015-06-06 22:21:51 -04:00
parent f850750707
commit f88e21cbb0
3 changed files with 9 additions and 7 deletions

View File

@@ -3,7 +3,7 @@ Pane = require '../src/pane'
PaneAxis = require '../src/pane-axis'
PaneContainer = require '../src/pane-container'
describe "Pane", ->
fdescribe "Pane", ->
deserializerDisposable = null
class Item extends Model
@@ -414,7 +414,7 @@ describe "Pane", ->
pane.getActiveItem().path = __filename
pane.getActiveItem().saveAs = jasmine.createSpy("saveAs")
pane.saveActiveItemAs()
expect(atom.showSaveDialogSync).toHaveBeenCalledWith(__filename)
expect(atom.showSaveDialogSync).toHaveBeenCalledWith(defaultPath: __filename)
expect(pane.getActiveItem().saveAs).toHaveBeenCalledWith('/selected/path')
describe "when the current item does not have a saveAs method", ->

View File

@@ -783,11 +783,12 @@ class Atom extends Model
showSaveDialog: (callback) ->
callback(showSaveDialogSync())
showSaveDialogSync: (defaultPath) ->
defaultPath ?= @project?.getPaths()[0]
showSaveDialogSync: (options={}) ->
currentWindow = @getCurrentWindow()
dialog = remote.require('dialog')
dialog.showSaveDialog currentWindow, {title: 'Save File', defaultPath}
options.title ?= 'Save File'
options.defaultPath ?= @project?.getPaths()[0]
dialog.showSaveDialog currentWindow, options
saveSync: ->
if storageKey = @constructor.getStateKey(@project?.getPaths(), @mode)

View File

@@ -492,8 +492,9 @@ class Pane extends Model
saveItemAs: (item, nextAction) ->
return unless item?.saveAs?
itemPath = item.getPath?()
newItemPath = atom.showSaveDialogSync(itemPath)
saveOptions = item.getSaveOptions?() or {}
saveOptions.defaultPath ?= item.getPath()
newItemPath = atom.showSaveDialogSync(saveOptions)
if newItemPath
try
item.saveAs(newItemPath)