Merge branch 'master' into fb-mdt-no-cmd-w-on-permanent-dock-items

This commit is contained in:
Max Brunsfeld
2017-04-17 13:39:16 -07:00
5 changed files with 174 additions and 11 deletions

View File

@@ -89,7 +89,7 @@
"autocomplete-atom-api": "0.10.1",
"autocomplete-css": "0.16.1",
"autocomplete-html": "0.7.3",
"autocomplete-plus": "2.35.3",
"autocomplete-plus": "2.35.4",
"autocomplete-snippets": "1.11.0",
"autoflow": "0.29.0",
"autosave": "0.24.2",
@@ -125,7 +125,7 @@
"symbols-view": "0.116.0",
"tabs": "0.105.4",
"timecop": "0.36.0",
"tree-view": "0.217.0-3",
"tree-view": "0.217.0-4",
"update-package-dependencies": "0.11.0",
"welcome": "0.36.2",
"whitespace": "0.36.2",

View File

@@ -120,4 +120,123 @@ describe('Dock', () => {
})
})
})
describe('when you add an item to an empty dock', () => {
describe('when the item has a preferred size', () => {
it('is takes the preferred size of the item', async () => {
jasmine.attachToDOM(atom.workspace.getElement())
const createItem = preferredWidth => ({
element: document.createElement('div'),
getDefaultLocation() { return 'left' },
getPreferredWidth() { return preferredWidth }
})
const dock = atom.workspace.getLeftDock()
const dockElement = dock.getElement()
expect(dock.getPaneItems()).toHaveLength(0)
const item1 = createItem(111)
await atom.workspace.open(item1)
// It should update the width every time we go from 0 -> 1 items, not just the first.
expect(dock.isVisible()).toBe(true)
expect(dockElement.offsetWidth).toBe(111)
dock.destroyActivePane()
expect(dock.getPaneItems()).toHaveLength(0)
expect(dock.isVisible()).toBe(false)
const item2 = createItem(222)
await atom.workspace.open(item2)
expect(dock.isVisible()).toBe(true)
expect(dockElement.offsetWidth).toBe(222)
// Adding a second shouldn't change the size.
const item3 = createItem(333)
await atom.workspace.open(item3)
expect(dockElement.offsetWidth).toBe(222)
})
})
describe('when the item has no preferred size', () => {
it('is still has an explicit size', async () => {
jasmine.attachToDOM(atom.workspace.getElement())
const item = {
element: document.createElement('div'),
getDefaultLocation() { return 'left' }
}
const dock = atom.workspace.getLeftDock()
expect(dock.getPaneItems()).toHaveLength(0)
expect(dock.state.size).toBe(null)
await atom.workspace.open(item)
expect(dock.state.size).not.toBe(null)
})
})
})
describe('a deserialized dock', () => {
it('restores the serialized size', async () => {
jasmine.attachToDOM(atom.workspace.getElement())
const item = {
element: document.createElement('div'),
getDefaultLocation() { return 'left' },
getPreferredWidth() { return 122 },
serialize: () => ({deserializer: 'DockTestItem'})
}
const itemDeserializer = atom.deserializers.add({
name: 'DockTestItem',
deserialize: () => item
})
const dock = atom.workspace.getLeftDock()
const dockElement = dock.getElement()
await atom.workspace.open(item)
dock.setState({size: 150})
expect(dockElement.offsetWidth).toBe(150)
const serialized = dock.serialize()
dock.setState({size: 122})
expect(dockElement.offsetWidth).toBe(122)
dock.destroyActivePane()
dock.deserialize(serialized, atom.deserializers)
expect(dockElement.offsetWidth).toBe(150)
})
it("isn't visible if it has no items", async () => {
jasmine.attachToDOM(atom.workspace.getElement())
const item = {
element: document.createElement('div'),
getDefaultLocation() { return 'left' },
getPreferredWidth() { return 122 }
}
const dock = atom.workspace.getLeftDock()
await atom.workspace.open(item)
expect(dock.isVisible()).toBe(true)
const serialized = dock.serialize()
dock.deserialize(serialized, atom.deserializers)
expect(dock.getPaneItems()).toHaveLength(0)
expect(dock.isVisible()).toBe(false)
})
})
describe('when dragging an item over an empty dock', () => {
it('has the preferred size of the item', () => {
jasmine.attachToDOM(atom.workspace.getElement())
const item = {
element: document.createElement('div'),
getDefaultLocation() { return 'left' },
getPreferredWidth() { return 144 },
serialize: () => ({deserializer: 'DockTestItem'})
}
const dock = atom.workspace.getLeftDock()
const dockElement = dock.getElement()
dock.setDraggingItem(item)
expect(dock.wrapperElement.offsetWidth).toBe(144)
})
})
})

View File

@@ -984,6 +984,29 @@ describe('Workspace', () => {
})
})
describe('finding items in the workspace', () => {
it('can identify the pane and pane container for a given item or URI', () => {
const uri = 'atom://test-pane-for-item'
const item = {
element: document.createElement('div'),
getURI () { return uri }
}
atom.workspace.getActivePane().activateItem(item)
expect(atom.workspace.paneForItem(item)).toBe(atom.workspace.getCenter().getActivePane())
expect(atom.workspace.paneContainerForItem(item)).toBe(atom.workspace.getCenter())
expect(atom.workspace.paneForURI(uri)).toBe(atom.workspace.getCenter().getActivePane())
expect(atom.workspace.paneContainerForURI(uri)).toBe(atom.workspace.getCenter())
atom.workspace.getActivePane().destroyActiveItem()
atom.workspace.getLeftDock().getActivePane().activateItem(item)
expect(atom.workspace.paneForItem(item)).toBe(atom.workspace.getLeftDock().getActivePane())
expect(atom.workspace.paneContainerForItem(item)).toBe(atom.workspace.getLeftDock())
expect(atom.workspace.paneForURI(uri)).toBe(atom.workspace.getLeftDock().getActivePane())
expect(atom.workspace.paneContainerForURI(uri)).toBe(atom.workspace.getLeftDock())
})
})
describe('::hide(uri)', () => {
let item
const URI = 'atom://hide-test'

View File

@@ -46,6 +46,7 @@ module.exports = class Dock {
})
this.state = {
size: null,
visible: false,
shouldAnimate: false
}
@@ -56,6 +57,7 @@ module.exports = class Dock {
this.didActivate(this)
}),
this.paneContainer.observePanes(pane => {
pane.onDidAddItem(this.handleDidAddPaneItem.bind(this))
pane.onDidRemoveItem(this.handleDidRemovePaneItem.bind(this))
}),
this.paneContainer.onDidChangeActivePane((item) => params.didChangeActivePane(this, item)),
@@ -206,7 +208,11 @@ module.exports = class Dock {
}
const shouldBeVisible = state.visible || state.showDropTarget
const size = Math.max(MINIMUM_SIZE, state.size == null ? this.getInitialSize() : state.size)
const size = Math.max(MINIMUM_SIZE,
state.size ||
(state.draggingItem && getPreferredSize(state.draggingItem, this.location)) ||
DEFAULT_INITIAL_SIZE
)
// We need to change the size of the mask...
this.maskElement.style[this.widthOrHeight] = `${shouldBeVisible ? size : 0}px`
@@ -224,10 +230,16 @@ module.exports = class Dock {
})
}
handleDidAddPaneItem () {
if (this.state.size == null) {
this.setState({size: this.getInitialSize()})
}
}
handleDidRemovePaneItem () {
// Hide the dock if you remove the last item.
if (this.paneContainer.getPaneItems().length === 0) {
this.setState({visible: false, hovered: false})
this.setState({visible: false, hovered: false, size: null})
}
}
@@ -340,13 +352,12 @@ module.exports = class Dock {
}
getInitialSize () {
let initialSize
// The item may not have been activated yet. If that's the case, just use the first item.
const activePaneItem = this.paneContainer.getActivePaneItem() || this.paneContainer.getPaneItems()[0]
if (activePaneItem != null) {
initialSize = getPreferredSize(activePaneItem, this.location)
}
return initialSize == null ? DEFAULT_INITIAL_SIZE : initialSize
// If there are items, we should have an explicit width; if not, we shouldn't.
return activePaneItem
? getPreferredSize(activePaneItem, this.location) || DEFAULT_INITIAL_SIZE
: null
}
serialize () {
@@ -361,7 +372,7 @@ module.exports = class Dock {
deserialize (serialized, deserializerManager) {
this.paneContainer.deserialize(serialized.paneContainer, deserializerManager)
this.setState({
size: serialized.size,
size: serialized.size || this.getInitialSize(),
// If no items could be deserialized, we don't want to show the dock (even if it was visible last time)
visible: serialized.visible && (this.paneContainer.getPaneItems().length > 0)
})

View File

@@ -1373,6 +1373,16 @@ module.exports = class Workspace extends Model {
return this.getPaneContainers().find(container => container.paneForURI(uri))
}
// Extended: Get the first pane container that contains the given item.
//
// * `item` the Item that the returned pane container must contain.
//
// Returns a {Dock}, the {WorkspaceCenter}, or `undefined` if no item exists
// with the given URI.
paneContainerForItem (uri) {
return this.getPaneContainers().find(container => container.paneForItem(uri))
}
// Extended: Get the first {Pane} that contains an item with the given URI.
//
// * `uri` {String} uri
@@ -1389,7 +1399,7 @@ module.exports = class Workspace extends Model {
// Extended: Get the {Pane} containing the given item.
//
// * `item` Item the returned pane contains.
// * `item` the Item that the returned pane must contain.
//
// Returns a {Pane} or `undefined` if no pane exists for the given item.
paneForItem (item) {