mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Aggregate onDidStopChangingActivePaneItem events across all containers
This commit is contained in:
@@ -156,29 +156,6 @@ describe "PaneContainer", ->
|
||||
pane2.activate()
|
||||
expect(activatedPanes).toEqual([pane1, pane1, pane2, pane2])
|
||||
|
||||
describe "::onDidStopChangingActivePaneItem()", ->
|
||||
[container, pane1, pane2, observed] = []
|
||||
|
||||
beforeEach ->
|
||||
container = new PaneContainer(root: new Pane(items: [new Object, new Object]))
|
||||
container.getRoot().splitRight(items: [new Object, new Object])
|
||||
[pane1, pane2] = container.getPanes()
|
||||
|
||||
observed = []
|
||||
container.onDidStopChangingActivePaneItem (item) -> observed.push(item)
|
||||
|
||||
it "invokes observers when the active item of the active pane stops changing", ->
|
||||
pane2.activateNextItem()
|
||||
pane2.activateNextItem()
|
||||
advanceClock(100)
|
||||
expect(observed).toEqual [pane2.itemAtIndex(0)]
|
||||
|
||||
it "invokes observers when the active pane stops changing", ->
|
||||
pane1.activate()
|
||||
pane2.activate()
|
||||
advanceClock(100)
|
||||
expect(observed).toEqual [pane2.itemAtIndex(0)]
|
||||
|
||||
describe "::observePanes()", ->
|
||||
it "invokes observers with all current and future panes", ->
|
||||
container = new PaneContainer(params)
|
||||
|
||||
@@ -1076,7 +1076,7 @@ describe('Workspace', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('pane containers', () => {
|
||||
describe('active pane containers', () => {
|
||||
it('maintains the active pane and item globally across active pane containers', () => {
|
||||
const leftDock = workspace.getLeftDock()
|
||||
const leftItem1 = {element: document.createElement('div')}
|
||||
@@ -1197,6 +1197,25 @@ describe('Workspace', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('::onDidStopChangingActivePaneItem()', function () {
|
||||
it('invokes observers when the active item of the active pane stops changing', function () {
|
||||
const pane1 = atom.workspace.getCenter().getActivePane()
|
||||
const pane2 = pane1.splitRight({items: [document.createElement('div'), document.createElement('div')]});
|
||||
atom.workspace.getLeftDock().getActivePane().addItem(document.createElement('div'))
|
||||
|
||||
emittedItems = []
|
||||
atom.workspace.onDidStopChangingActivePaneItem(item => emittedItems.push(item))
|
||||
|
||||
pane2.activateNextItem()
|
||||
pane2.activateNextItem()
|
||||
pane1.activate()
|
||||
atom.workspace.getLeftDock().activate()
|
||||
|
||||
advanceClock(100)
|
||||
expect(emittedItems).toEqual([atom.workspace.getLeftDock().getActivePaneItem()])
|
||||
})
|
||||
})
|
||||
|
||||
describe('the grammar-used hook', () => {
|
||||
it('fires when opening a file or changing the grammar of an open file', () => {
|
||||
let editor = null
|
||||
|
||||
@@ -5,7 +5,6 @@ const ItemRegistry = require('./item-registry')
|
||||
const PaneContainerElement = require('./pane-container-element')
|
||||
|
||||
const SERIALIZATION_VERSION = 1
|
||||
const STOPPED_CHANGING_ACTIVE_PANE_ITEM_DELAY = 100
|
||||
|
||||
module.exports =
|
||||
class PaneContainer {
|
||||
@@ -16,7 +15,6 @@ class PaneContainer {
|
||||
this.subscriptions = new CompositeDisposable()
|
||||
this.itemRegistry = new ItemRegistry()
|
||||
this.alive = true
|
||||
this.stoppedChangingActivePaneItemTimeout = null
|
||||
|
||||
this.setRoot(new Pane({container: this, config: this.config, applicationDelegate, notificationManager, deserializerManager, viewRegistry: this.viewRegistry}))
|
||||
this.didActivatePane(this.getRoot())
|
||||
@@ -30,7 +28,6 @@ class PaneContainer {
|
||||
|
||||
destroy () {
|
||||
this.alive = false
|
||||
this.cancelStoppedChangingActivePaneItemTimeout()
|
||||
for (let pane of this.getRoot().getPanes()) { pane.destroy() }
|
||||
this.subscriptions.dispose()
|
||||
this.emitter.dispose()
|
||||
@@ -277,17 +274,6 @@ class PaneContainer {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ const Task = require('./task')
|
||||
const WorkspaceCenter = require('./workspace-center')
|
||||
const WorkspaceElement = require('./workspace-element')
|
||||
|
||||
const STOPPED_CHANGING_ACTIVE_PANE_ITEM_DELAY = 100
|
||||
|
||||
// Essential: Represents the state of the user interface for the entire window.
|
||||
// An instance of this class is available via the `atom.workspace` global.
|
||||
//
|
||||
@@ -35,7 +37,6 @@ module.exports = class Workspace extends Model {
|
||||
this.updateWindowTitle = this.updateWindowTitle.bind(this)
|
||||
this.updateDocumentEdited = this.updateDocumentEdited.bind(this)
|
||||
this.didDestroyPaneItem = this.didDestroyPaneItem.bind(this)
|
||||
this.didChangeActivePaneItem = this.didChangeActivePaneItem.bind(this)
|
||||
this.didChangeActivePaneOnPaneContainer = this.didChangeActivePaneOnPaneContainer.bind(this)
|
||||
this.didChangeActivePaneItemOnPaneContainer = this.didChangeActivePaneItemOnPaneContainer.bind(this)
|
||||
this.didActivatePaneContainer = this.didActivatePaneContainer.bind(this)
|
||||
@@ -59,6 +60,7 @@ module.exports = class Workspace extends Model {
|
||||
this.emitter = new Emitter()
|
||||
this.openers = []
|
||||
this.destroyedItemURIs = []
|
||||
this.stoppedChangingActivePaneItemTimeout = null
|
||||
|
||||
this.paneContainer = new PaneContainer({
|
||||
location: 'center',
|
||||
@@ -177,7 +179,7 @@ module.exports = class Workspace extends Model {
|
||||
}
|
||||
|
||||
subscribeToEvents () {
|
||||
this.subscribeToActiveItem()
|
||||
this.project.onDidChangePaths(this.updateWindowTitle)
|
||||
this.subscribeToFontSize()
|
||||
this.subscribeToAddedItems()
|
||||
this.subscribeToMovedItems()
|
||||
@@ -259,7 +261,7 @@ module.exports = class Workspace extends Model {
|
||||
didActivatePaneContainer (paneContainer) {
|
||||
if (paneContainer !== this.getActivePaneContainer()) {
|
||||
this.activePaneContainer = paneContainer
|
||||
if (global.debug) debugger
|
||||
this.didChangeActivePaneItem(this.activePaneContainer.getActivePaneItem())
|
||||
this.emitter.emit('did-change-active-pane-container', this.activePaneContainer)
|
||||
this.emitter.emit('did-change-active-pane', this.activePaneContainer.getActivePane())
|
||||
this.emitter.emit('did-change-active-pane-item', this.activePaneContainer.getActivePaneItem())
|
||||
@@ -274,38 +276,15 @@ module.exports = class Workspace extends Model {
|
||||
|
||||
didChangeActivePaneItemOnPaneContainer (paneContainer, item) {
|
||||
if (paneContainer === this.getActivePaneContainer()) {
|
||||
this.didChangeActivePaneItem(item)
|
||||
this.emitter.emit('did-change-active-pane-item', item)
|
||||
}
|
||||
}
|
||||
|
||||
didHideDock () {
|
||||
this.getCenter().activate()
|
||||
}
|
||||
|
||||
setHoveredDock (hoveredDock) {
|
||||
this.hoveredDock = hoveredDock
|
||||
_.values(this.docks).forEach(dock => {
|
||||
dock.setHovered(dock === hoveredDock)
|
||||
})
|
||||
}
|
||||
|
||||
setDraggingItem (draggingItem) {
|
||||
_.values(this.docks).forEach(dock => {
|
||||
dock.setDraggingItem(draggingItem)
|
||||
})
|
||||
}
|
||||
|
||||
subscribeToActiveItem () {
|
||||
this.project.onDidChangePaths(this.updateWindowTitle)
|
||||
this.onDidChangeActivePaneItem(this.didChangeActivePaneItem)
|
||||
}
|
||||
|
||||
didChangeActivePaneItem (item) {
|
||||
this.updateWindowTitle()
|
||||
this.updateDocumentEdited()
|
||||
if (this.activeItemSubscriptions != null) {
|
||||
this.activeItemSubscriptions.dispose()
|
||||
}
|
||||
if (this.activeItemSubscriptions) this.activeItemSubscriptions.dispose()
|
||||
this.activeItemSubscriptions = new CompositeDisposable()
|
||||
|
||||
let modifiedSubscription, titleSubscription
|
||||
@@ -334,6 +313,35 @@ module.exports = class Workspace extends Model {
|
||||
|
||||
if (titleSubscription != null) { this.activeItemSubscriptions.add(titleSubscription) }
|
||||
if (modifiedSubscription != null) { this.activeItemSubscriptions.add(modifiedSubscription) }
|
||||
|
||||
this.cancelStoppedChangingActivePaneItemTimeout()
|
||||
this.stoppedChangingActivePaneItemTimeout = setTimeout(() => {
|
||||
this.stoppedChangingActivePaneItemTimeout = null
|
||||
this.emitter.emit('did-stop-changing-active-pane-item', item)
|
||||
}, STOPPED_CHANGING_ACTIVE_PANE_ITEM_DELAY)
|
||||
}
|
||||
|
||||
cancelStoppedChangingActivePaneItemTimeout () {
|
||||
if (this.stoppedChangingActivePaneItemTimeout != null) {
|
||||
clearTimeout(this.stoppedChangingActivePaneItemTimeout)
|
||||
}
|
||||
}
|
||||
|
||||
didHideDock () {
|
||||
this.getCenter().activate()
|
||||
}
|
||||
|
||||
setHoveredDock (hoveredDock) {
|
||||
this.hoveredDock = hoveredDock
|
||||
_.values(this.docks).forEach(dock => {
|
||||
dock.setHovered(dock === hoveredDock)
|
||||
})
|
||||
}
|
||||
|
||||
setDraggingItem (draggingItem) {
|
||||
_.values(this.docks).forEach(dock => {
|
||||
dock.setDraggingItem(draggingItem)
|
||||
})
|
||||
}
|
||||
|
||||
subscribeToAddedItems () {
|
||||
@@ -497,7 +505,7 @@ module.exports = class Workspace extends Model {
|
||||
//
|
||||
// Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
|
||||
onDidStopChangingActivePaneItem (callback) {
|
||||
return this.paneContainer.onDidStopChangingActivePaneItem(callback)
|
||||
return this.emitter.on('did-stop-changing-active-pane-item', callback)
|
||||
}
|
||||
|
||||
// Essential: Invoke the given callback with the current active pane item and
|
||||
@@ -1352,6 +1360,7 @@ module.exports = class Workspace extends Model {
|
||||
// Called by Model superclass when destroyed
|
||||
destroyed () {
|
||||
this.paneContainer.destroy()
|
||||
this.cancelStoppedChangingActivePaneItemTimeout()
|
||||
if (this.activeItemSubscriptions != null) {
|
||||
this.activeItemSubscriptions.dispose()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user