Remove PaneContainer.monitorActivePaneItem

Call didChangeActiveItemOnPane directly from panes and when the active
pane changes instead.
This commit is contained in:
Nathan Sobo
2017-04-06 13:12:51 -06:00
parent 2f7fb3f565
commit ec576b12bc
6 changed files with 13 additions and 59 deletions

View File

@@ -25,7 +25,6 @@ describe "PaneContainer", ->
serialize: -> deserializer: 'Item'
containerA = new PaneContainer(params)
containerA.initialize()
pane1A = containerA.getActivePane()
pane1A.addItem(new Item)
pane2A = pane1A.splitRight(items: [new Item])
@@ -36,7 +35,6 @@ describe "PaneContainer", ->
expect(pane3A.focused).toBe true
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(containerA.serialize(), atom.deserializers)
[pane1B, pane2B, pane3B] = containerB.getPanes()
expect(pane3B.focused).toBe true
@@ -46,7 +44,6 @@ describe "PaneContainer", ->
expect(containerA.getActivePane()).toBe pane3A
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(containerA.serialize(), atom.deserializers)
[pane1B, pane2B, pane3B] = containerB.getPanes()
expect(containerB.getActivePane()).toBe pane3B
@@ -56,7 +53,6 @@ describe "PaneContainer", ->
state = containerA.serialize()
state.activePaneId = -22
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(state, atom.deserializers)
expect(containerB.getActivePane()).toBe containerB.getPanes()[0]
@@ -68,7 +64,6 @@ describe "PaneContainer", ->
it "leaves the empty panes intact", ->
state = containerA.serialize()
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(state, atom.deserializers)
[leftPane, column] = containerB.getRoot().getChildren()
[topPane, bottomPane] = column.getChildren()
@@ -83,7 +78,6 @@ describe "PaneContainer", ->
state = containerA.serialize()
containerB = new PaneContainer(params)
containerB.initialize()
containerB.deserialize(state, atom.deserializers)
[leftPane, rightPane] = containerB.getRoot().getChildren()
@@ -92,7 +86,6 @@ describe "PaneContainer", ->
it "does not allow the root pane to be destroyed", ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().destroy()
expect(container.getRoot()).toBeDefined()
expect(container.getRoot().isDestroyed()).toBe false
@@ -102,7 +95,6 @@ describe "PaneContainer", ->
beforeEach ->
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
it "returns the first pane if no pane has been made active", ->
@@ -132,7 +124,6 @@ describe "PaneContainer", ->
beforeEach ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().addItems([new Object, new Object])
container.getRoot().splitRight(items: [new Object, new Object])
[pane1, pane2] = container.getPanes()
@@ -153,7 +144,6 @@ describe "PaneContainer", ->
describe "::onDidActivatePane", ->
it "invokes observers when a pane is activated (even if it was already active)", ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().splitRight()
[pane1, pane2] = container.getPanes()
@@ -171,7 +161,6 @@ describe "PaneContainer", ->
beforeEach ->
container = new PaneContainer(root: new Pane(items: [new Object, new Object]))
container.initialize()
container.getRoot().splitRight(items: [new Object, new Object])
[pane1, pane2] = container.getPanes()
@@ -193,7 +182,6 @@ describe "PaneContainer", ->
describe "::observePanes()", ->
it "invokes observers with all current and future panes", ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().splitRight()
[pane1, pane2] = container.getPanes()
@@ -208,7 +196,6 @@ describe "PaneContainer", ->
describe "::observePaneItems()", ->
it "invokes observers with all current and future pane items", ->
container = new PaneContainer(params)
container.initialize()
container.getRoot().addItems([new Object, new Object])
container.getRoot().splitRight(items: [new Object])
[pane1, pane2] = container.getPanes()
@@ -229,7 +216,6 @@ describe "PaneContainer", ->
getURI: -> 'test'
container = new PaneContainer(params)
container.initialize()
container.getRoot().splitRight()
[pane1, pane2] = container.getPanes()
pane1.addItem(new TestItem)
@@ -250,7 +236,6 @@ describe "PaneContainer", ->
describe "::onDidAddPane(callback)", ->
it "invokes the given callback when panes are added", ->
container = new PaneContainer(params)
container.initialize()
events = []
container.onDidAddPane (event) ->
expect(event.pane in container.getPanes()).toBe true
@@ -270,7 +255,6 @@ describe "PaneContainer", ->
isDestroyed: -> @_isDestroyed
container = new PaneContainer(params)
container.initialize()
events = []
container.onWillDestroyPane (event) ->
itemsDestroyed = (item.isDestroyed() for item in event.pane.getItems())
@@ -287,7 +271,6 @@ describe "PaneContainer", ->
describe "::onDidDestroyPane(callback)", ->
it "invokes the given callback when panes are destroyed", ->
container = new PaneContainer(params)
container.initialize()
events = []
container.onDidDestroyPane (event) ->
expect(event.pane in container.getPanes()).toBe false
@@ -304,7 +287,6 @@ describe "PaneContainer", ->
it "invokes the given callback when the container is destroyed", ->
container = new PaneContainer(params)
container.initialize()
events = []
container.onDidDestroyPane (event) ->
expect(event.pane in container.getPanes()).toBe false
@@ -321,7 +303,6 @@ describe "PaneContainer", ->
describe "::onWillDestroyPaneItem() and ::onDidDestroyPaneItem", ->
it "invokes the given callbacks when an item will be destroyed on any pane", ->
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
item1 = new Object
item2 = new Object
@@ -349,7 +330,6 @@ describe "PaneContainer", ->
describe "::saveAll()", ->
it "saves all modified pane items", ->
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
pane2 = pane1.splitRight()
@@ -391,7 +371,6 @@ describe "PaneContainer", ->
copy: -> new TestItem(@id)
container = new PaneContainer(params)
container.initialize()
pane1 = container.getRoot()
item1 = new TestItem('1')
pane2 = pane1.splitRight(items: [item1])

View File

@@ -57,7 +57,6 @@ describe('Workspace', () => {
assert: atom.assert.bind(atom),
textEditorRegistry: atom.textEditors
})
atom.workspace.initialize()
return atom.workspace.deserialize(workspaceState, atom.deserializers)
}

View File

@@ -227,7 +227,6 @@ class AtomEnvironment extends Model
@themes.initialize({@configDirPath, resourcePath, safeMode, devMode})
@commandInstaller.initialize(@getVersion())
@workspace.initialize()
@autoUpdater.initialize()
@config.load()

View File

@@ -22,10 +22,6 @@ class PaneContainer {
this.setActivePane(this.getRoot())
}
initialize () {
this.monitorActivePaneItem()
}
getLocation () { return this.location }
getElement () {
@@ -171,6 +167,7 @@ class PaneContainer {
this.activePane = activePane
this.emitter.emit('did-change-active-pane', this.activePane)
this.didChangeActiveItemOnPane(this.activePane, this.activePane.getActiveItem())
}
this.emitter.emit('did-activate-pane', this.activePane)
return this.activePane
@@ -278,36 +275,20 @@ class PaneContainer {
this.emitter.emit('did-destroy-pane', event)
}
didChangeActiveItemOnPane (pane, activeItem) {
if (pane === this.getActivePane()) {
this.emitter.emit('did-change-active-pane-item', activeItem)
this.cancelStoppedChangingActivePaneItemTimeout()
this.stoppedChangingActivePaneItemTimeout = setTimeout(() => {
this.stoppedChangingActivePaneItemTimeout = null
this.emitter.emit('did-stop-changing-active-pane-item', activeItem)
}, STOPPED_CHANGING_ACTIVE_PANE_ITEM_DELAY)
}
}
cancelStoppedChangingActivePaneItemTimeout () {
if (this.stoppedChangingActivePaneItemTimeout != null) {
clearTimeout(this.stoppedChangingActivePaneItemTimeout)
}
}
monitorActivePaneItem () {
let childSubscription = null
this.subscriptions.add(this.observeActivePane(activePane => {
if (childSubscription != null) {
this.subscriptions.remove(childSubscription)
childSubscription.dispose()
}
childSubscription = activePane.observeActiveItem(activeItem => {
this.emitter.emit('did-change-active-pane-item', activeItem)
this.cancelStoppedChangingActivePaneItemTimeout()
const stoppedChangingActivePaneItemCallback = () => {
this.stoppedChangingActivePaneItemTimeout = null
this.emitter.emit('did-stop-changing-active-pane-item', activeItem)
}
this.stoppedChangingActivePaneItemTimeout =
setTimeout(
stoppedChangingActivePaneItemCallback,
STOPPED_CHANGING_ACTIVE_PANE_ITEM_DELAY)
}
)
this.subscriptions.add(childSubscription)
}))
}
}

View File

@@ -340,6 +340,7 @@ class Pane
@addItemToStack(activeItem) unless modifyStack is false
@activeItem = activeItem
@emitter.emit 'did-change-active-item', @activeItem
@container?.didChangeActiveItemOnPane(this, @activeItem)
@activeItem
# Build the itemStack after deserializing

View File

@@ -90,10 +90,6 @@ module.exports = class Workspace extends Model {
this.subscribeToEvents()
}
initialize () {
this.paneContainer.initialize()
}
getElement () {
if (!this.element) {
this.element = new WorkspaceElement().initialize(this, {
@@ -164,7 +160,6 @@ module.exports = class Workspace extends Model {
this.destroyedItemURIs = []
this.element = null
this.consumeServices(this.packageManager)
this.initialize()
}
subscribeToEvents () {