mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Merge pull request #14103 from atom/fb-mdt-workspace-dot-hide
Add `atom.workspace.hide()`
This commit is contained in:
commit
5272fc5f88
@ -906,6 +906,65 @@ describe('Workspace', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('::hide(uri)', () => {
|
||||
let item
|
||||
const URI = 'atom://hide-test'
|
||||
|
||||
beforeEach(() => {
|
||||
const el = document.createElement('div')
|
||||
item = {
|
||||
getTitle: () => 'Item',
|
||||
getElement: () => el,
|
||||
getURI: () => URI
|
||||
}
|
||||
})
|
||||
|
||||
it('removes matching items from the center', () => {
|
||||
const pane = atom.workspace.getActivePane()
|
||||
pane.addItem(item)
|
||||
atom.workspace.hide(URI)
|
||||
expect(pane.getItems().length).toBe(0)
|
||||
})
|
||||
|
||||
it('hides the dock when an item matches', () => {
|
||||
const dock = atom.workspace.getLeftDock()
|
||||
const pane = dock.getActivePane()
|
||||
pane.addItem(item)
|
||||
dock.activate()
|
||||
expect(dock.isOpen()).toBe(true)
|
||||
const itemFound = atom.workspace.hide(URI)
|
||||
expect(itemFound).toBe(true)
|
||||
expect(dock.isOpen()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('::toggle(uri)', () => {
|
||||
it('shows the item and dock if no item matches', () => {
|
||||
const URI = 'atom://hide-test'
|
||||
workspace.addOpener(uri => {
|
||||
if (uri === URI) {
|
||||
const el = document.createElement('div')
|
||||
return {
|
||||
getDefaultLocation: () => 'left',
|
||||
getTitle: () => 'Item',
|
||||
getElement: () => el,
|
||||
getURI: () => URI
|
||||
}
|
||||
}
|
||||
})
|
||||
const dock = workspace.getLeftDock()
|
||||
expect(dock.isOpen()).toBe(false)
|
||||
waitsFor(done => {
|
||||
workspace.onDidOpen(({item}) => {
|
||||
expect(item.getURI()).toBe(URI)
|
||||
expect(dock.isOpen()).toBe(true)
|
||||
done()
|
||||
})
|
||||
workspace.toggle(URI)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('the grammar-used hook', () => {
|
||||
it('fires when opening a file or changing the grammar of an open file', () => {
|
||||
let editor = null
|
||||
|
@ -749,6 +749,47 @@ module.exports = class Workspace extends Model {
|
||||
return item
|
||||
}
|
||||
|
||||
// Essential: Search the workspace for items matching the given URI and hide them.
|
||||
//
|
||||
// * `uri` (optional) A {String} containing a URI.
|
||||
//
|
||||
// Returns a {boolean} indicating whether any items were found (and hidden).
|
||||
hide (uri) {
|
||||
let foundItems = false
|
||||
|
||||
// If any visible item has the given URI, hide it
|
||||
for (const container of this.getPaneContainers()) {
|
||||
const isCenter = container === this.getCenter()
|
||||
if (isCenter || container.isOpen()) {
|
||||
for (const pane of container.getPanes()) {
|
||||
const activeItem = pane.getActiveItem()
|
||||
if (activeItem != null && typeof activeItem.getURI === 'function') {
|
||||
const itemURI = activeItem.getURI()
|
||||
if (itemURI === uri) {
|
||||
foundItems = true
|
||||
// We can't really hide the center so we just destroy the item.
|
||||
if (isCenter) {
|
||||
pane.destroyItem(activeItem)
|
||||
} else {
|
||||
container.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundItems
|
||||
}
|
||||
|
||||
// Essential: Search the workspace for items matching the given URI. If any are found, hide them.
|
||||
// Otherwise, open the URL.
|
||||
//
|
||||
// * `uri` (optional) A {String} containing a URI.
|
||||
toggle (uri) {
|
||||
if (!this.hide(uri)) this.open(uri, {searchAllPanes: true})
|
||||
}
|
||||
|
||||
// Open Atom's license in the active pane.
|
||||
openLicense () {
|
||||
return this.open(path.join(process.resourcesPath, 'LICENSE.md'))
|
||||
@ -1189,37 +1230,6 @@ module.exports = class Workspace extends Model {
|
||||
return [this.getCenter(), ..._.values(this.docks)]
|
||||
}
|
||||
|
||||
toggle (uri) {
|
||||
let foundItems = false
|
||||
|
||||
// If any visible item has the given URI, hide it
|
||||
for (const location of this.getPaneContainers()) {
|
||||
const isCenter = location === this.getCenter()
|
||||
if (isCenter || location.isOpen()) {
|
||||
for (const pane of location.getPanes()) {
|
||||
const activeItem = pane.getActiveItem()
|
||||
if (activeItem != null && typeof activeItem.getURI === 'function') {
|
||||
const itemURI = activeItem.getURI()
|
||||
if (itemURI === uri) {
|
||||
foundItems = true
|
||||
// We can't really hide the center so we just destroy the item.
|
||||
if (isCenter) {
|
||||
pane.destroyItem(activeItem)
|
||||
} else {
|
||||
location.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no visible items had the URI, show it.
|
||||
if (!foundItems) {
|
||||
this.open(uri, {searchAllPanes: true})
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Section: Panels
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user