From f88e21cbb06eec1b8d5d12d2fd0452e77b754b9f Mon Sep 17 00:00:00 2001 From: Jesse Grosjean Date: Sat, 6 Jun 2015 22:21:51 -0400 Subject: [PATCH 1/5] Allow items to provide savePanel options. --- spec/pane-spec.coffee | 4 ++-- src/atom.coffee | 7 ++++--- src/pane.coffee | 5 +++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 7d6410048..51bb07e8c 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -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", -> diff --git a/src/atom.coffee b/src/atom.coffee index 0d029b61d..dde0960ab 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -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) diff --git a/src/pane.coffee b/src/pane.coffee index 38c8d9201..b38e6fa46 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -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) From 05e6d9e55d6b080f5eb66b04a334ce80888b9c26 Mon Sep 17 00:00:00 2001 From: Jesse Grosjean Date: Sat, 6 Jun 2015 22:22:47 -0400 Subject: [PATCH 2/5] Stop focusing specs on "Pane" --- spec/pane-spec.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/pane-spec.coffee b/spec/pane-spec.coffee index 51bb07e8c..ba2f02802 100644 --- a/spec/pane-spec.coffee +++ b/spec/pane-spec.coffee @@ -3,7 +3,7 @@ Pane = require '../src/pane' PaneAxis = require '../src/pane-axis' PaneContainer = require '../src/pane-container' -fdescribe "Pane", -> +describe "Pane", -> deserializerDisposable = null class Item extends Model From 656c91beb455f788adfb1006ffc041b4aabca9e6 Mon Sep 17 00:00:00 2001 From: Jesse Grosjean Date: Mon, 8 Jun 2015 16:19:39 -0400 Subject: [PATCH 3/5] Preserve previous API behavior --- src/atom.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/atom.coffee b/src/atom.coffee index dde0960ab..8903a9cef 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -784,6 +784,8 @@ class Atom extends Model callback(showSaveDialogSync()) showSaveDialogSync: (options={}) -> + if _.isString(options) + options = defaultPath: options currentWindow = @getCurrentWindow() dialog = remote.require('dialog') options.title ?= 'Save File' From 1dbfd0b5ac2379160ec73db301546556c2534c83 Mon Sep 17 00:00:00 2001 From: Jesse Grosjean Date: Mon, 8 Jun 2015 16:20:53 -0400 Subject: [PATCH 4/5] Rename to getSaveDialogOptions and document in TextEditor --- src/pane.coffee | 2 +- src/text-editor.coffee | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/pane.coffee b/src/pane.coffee index b38e6fa46..477239bdd 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -492,7 +492,7 @@ class Pane extends Model saveItemAs: (item, nextAction) -> return unless item?.saveAs? - saveOptions = item.getSaveOptions?() or {} + saveOptions = item.getSaveDialogOptions?() ? {} saveOptions.defaultPath ?= item.getPath() newItemPath = atom.showSaveDialogSync(saveOptions) if newItemPath diff --git a/src/text-editor.coffee b/src/text-editor.coffee index 9a9262e50..99e6f27cc 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -593,6 +593,16 @@ class TextEditor extends Model # Essential: Returns the {String} path of this editor's text buffer. getPath: -> @buffer.getPath() + # Private: Return [save options](http://electron.atom.io/docs/v0.27.0/api/di + # alog/#dialog.showsavedialog(%5Bbrowserwindow%5D,-%5Boptions%5D,-%5Bcallbac + # k%5D)) to be used when displaying the save dialog. + # + # Default empty options are returned now. In the future this would be the + # place to start implementing things like: https://discuss.atom.io/t + # /request-saving- file-with-correct-extension/17521 + getSaveDialogOptions: -> + {} + # Extended: Returns the {String} character set encoding of this editor's text # buffer. getEncoding: -> @buffer.getEncoding() From 6cdc555a9343f265f1b6e1a376266bd065fb3cc1 Mon Sep 17 00:00:00 2001 From: Jesse Grosjean Date: Mon, 8 Jun 2015 20:40:15 -0400 Subject: [PATCH 5/5] Clone options parameter before modifying it. --- src/atom.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/atom.coffee b/src/atom.coffee index 8903a9cef..ddc2e024d 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -786,6 +786,8 @@ class Atom extends Model showSaveDialogSync: (options={}) -> if _.isString(options) options = defaultPath: options + else + options = _.clone(options) currentWindow = @getCurrentWindow() dialog = remote.require('dialog') options.title ?= 'Save File'