Merge branch 'as-dg-remove-spacepen-from-reopen-project-list-view'

This commit is contained in:
Damien Guard
2016-12-09 16:44:35 -08:00
2 changed files with 41 additions and 29 deletions

View File

@@ -1,59 +1,71 @@
/** @babel */
import { SelectListView } from 'atom-space-pen-views'
import SelectListView from 'atom-select-list'
export default class ReopenProjectListView extends SelectListView {
initialize (callback) {
export default class ReopenProjectListView {
constructor (callback) {
this.callback = callback
super.initialize()
this.addClass('reopen-project')
this.list.addClass('mark-active')
this.selectListView = new SelectListView({
emptyMessage: 'No projects in history.',
itemsClassList: ['mark-active'],
items: [],
filterKeyForItem: (project) => project.name,
elementForItem: (project) => {
let element = document.createElement('li')
if (project.name === this.currentProjectName) {
element.classList.add('active')
}
element.textContent = project.name
return element
},
didConfirmSelection: (project) => {
this.cancel()
this.callback(project.value)
},
didCancelSelection: () => {
this.cancel()
}
})
this.selectListView.element.classList.add('reopen-project')
}
getFilterKey () {
return 'name'
get element () {
return this.selectListView.element
}
destroy () {
dispose () {
this.cancel()
return this.selectListView.destroy()
}
viewForItem (project) {
let element = document.createElement('li')
if (project.name === this.currentProjectName) {
element.classList.add('active')
}
element.textContent = project.name
return element
}
cancelled () {
cancel () {
if (this.panel != null) {
this.panel.destroy()
}
this.panel = null
this.currentProjectName = null
}
confirmed (project) {
this.cancel()
this.callback(project.value)
if (this.previouslyFocusedElement) {
this.previouslyFocusedElement.focus()
this.previouslyFocusedElement = null
}
}
attach () {
this.storeFocusedElement()
this.previouslyFocusedElement = document.activeElement
if (this.panel == null) {
this.panel = atom.workspace.addModalPanel({item: this})
}
this.focusFilterEditor()
this.selectListView.focus()
this.selectListView.reset()
}
toggle () {
async toggle () {
if (this.panel != null) {
this.cancel()
} else {
this.currentProjectName = atom.project != null ? this.makeName(atom.project.getPaths()) : null
this.setItems(atom.history.getProjects().map(p => ({ name: this.makeName(p.paths), value: p.paths })))
const projects = atom.history.getProjects().map(p => ({ name: this.makeName(p.paths), value: p.paths }))
await this.selectListView.update({items: projects})
this.attach()
}
}