Merge pull request #9244 from atom/mb-fix-open-handler

Pass application delegate to PaneElement
This commit is contained in:
Max Brunsfeld
2015-10-21 11:29:38 -07:00
2 changed files with 7 additions and 7 deletions

View File

@@ -4,7 +4,7 @@ describe "PaneElement", ->
[paneElement, container, pane] = []
beforeEach ->
spyOn(atom, "open")
spyOn(atom.applicationDelegate, "open")
container = new PaneContainer(config: atom.config, confirm: atom.confirm.bind(atom))
pane = container.getActivePane()
@@ -187,11 +187,11 @@ describe "PaneElement", ->
it "opens it", ->
event = buildDragEvent("drop", [{path: "/fake1"}, {path: "/fake2"}])
paneElement.dispatchEvent(event)
expect(atom.open.callCount).toBe 1
expect(atom.open.argsForCall[0][0]).toEqual pathsToOpen: ['/fake1', '/fake2']
expect(atom.applicationDelegate.open.callCount).toBe 1
expect(atom.applicationDelegate.open.argsForCall[0][0]).toEqual pathsToOpen: ['/fake1', '/fake2']
describe "when a non-file is dragged to the pane", ->
it "does nothing", ->
event = buildDragEvent("drop", [])
paneElement.dispatchEvent(event)
expect(atom.open).not.toHaveBeenCalled()
expect(atom.applicationDelegate.open).not.toHaveBeenCalled()

View File

@@ -44,16 +44,16 @@ class PaneElement extends HTMLElement
event.stopPropagation()
@getModel().activate()
pathsToOpen = Array::map.call event.dataTransfer.files, (file) -> file.path
@open({pathsToOpen}) if pathsToOpen.length > 0
@applicationDelegate.open({pathsToOpen}) if pathsToOpen.length > 0
@addEventListener 'focus', handleFocus, true
@addEventListener 'blur', handleBlur, true
@addEventListener 'dragover', handleDragOver
@addEventListener 'drop', handleDrop
initialize: (@model, {@views, @open}) ->
initialize: (@model, {@views, @applicationDelegate}) ->
throw new Error("Must pass a views parameter when initializing PaneElements") unless @views?
throw new Error("Must pass a open parameter when initializing PaneElements") unless @open?
throw new Error("Must pass an applicationDelegate parameter when initializing PaneElements") unless @applicationDelegate?
@subscriptions.add @model.onDidActivate(@activated.bind(this))
@subscriptions.add @model.observeActive(@activeStatusChanged.bind(this))