Change Workspace::reopenItemSync to use promises

This commit is contained in:
Corey Johnson
2014-04-22 14:15:07 -07:00
parent 7b756ec3f3
commit 81df4ed238
3 changed files with 24 additions and 8 deletions

View File

@@ -179,7 +179,7 @@ fdescribe "Workspace", ->
runs ->
expect(newEditorHandler).toHaveBeenCalledWith editor
describe "::reopenItemSync()", ->
describe "::reopenItem()", ->
it "opens the uri associated with the last closed pane that isn't currently open", ->
pane = workspace.activePane
waitsForPromise ->
@@ -192,7 +192,11 @@ fdescribe "Workspace", ->
# does not reopen items with no uri
expect(workspace.activePaneItem.getUri()).toBeUndefined()
pane.destroyActiveItem()
workspace.reopenItemSync()
waitsForPromise ->
workspace.reopenItem()
runs ->
expect(workspace.activePaneItem.getUri()).not.toBeUndefined()
# destroy all items
@@ -205,7 +209,11 @@ fdescribe "Workspace", ->
# reopens items with uris
expect(workspace.activePaneItem).toBeUndefined()
workspace.reopenItemSync()
waitsForPromise ->
workspace.reopenItem()
runs ->
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('a')
# does not reopen items that are already open
@@ -214,7 +222,11 @@ fdescribe "Workspace", ->
runs ->
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('b')
workspace.reopenItemSync()
waitsForPromise ->
workspace.reopenItem()
runs ->
expect(workspace.activePaneItem.getUri()).toBe atom.project.resolve('file1')
describe "::increase/decreaseFontSize()", ->

View File

@@ -57,7 +57,7 @@ class WorkspaceView extends View
Delegator.includeInto(this)
@delegatesProperty 'fullScreen', 'destroyedItemUris', toProperty: 'model'
@delegatesMethods 'open', 'openSync', 'reopenItemSync',
@delegatesMethods 'open', 'openSync',
'saveActivePaneItem', 'saveActivePaneItemAs', 'saveAll', 'destroyActivePaneItem',
'destroyActivePane', 'increaseFontSize', 'decreaseFontSize', toProperty: 'model'
@@ -149,7 +149,7 @@ class WorkspaceView extends View
@command 'window:toggle-auto-indent', =>
atom.config.toggle("editor.autoIndent")
@command 'pane:reopen-closed-item', => @reopenItemSync()
@command 'pane:reopen-closed-item', => @getModel().reopenItem()
@command 'core:close', => if @getModel().getActivePaneItem()? then @destroyActivePaneItem() else @destroyActivePane()
@command 'core:save', => @saveActivePaneItem()

View File

@@ -167,9 +167,13 @@ class Workspace extends Model
# Public: Reopen the last-closed item's URI if it hasn't already been
# reopened.
reopenItemSync: ->
#
# Returns a promise that is resolved when the item is opened
reopenItem: ->
if uri = @destroyedItemUris.pop()
@openSync(uri)
@open(uri)
else
Q()
# Public: Register an opener for a uri.
#