-
Notifications
You must be signed in to change notification settings - Fork 0
/
reopen-project-list-view.js
76 lines (68 loc) · 1.93 KB
/
reopen-project-list-view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/** @babel */
import SelectListView from 'atom-select-list'
export default class ReopenProjectListView {
constructor (callback) {
this.callback = callback
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')
}
get element () {
return this.selectListView.element
}
dispose () {
this.cancel()
return this.selectListView.destroy()
}
cancel () {
if (this.panel != null) {
this.panel.destroy()
}
this.panel = null
this.currentProjectName = null
if (this.previouslyFocusedElement) {
this.previouslyFocusedElement.focus()
this.previouslyFocusedElement = null
}
}
attach () {
this.previouslyFocusedElement = document.activeElement
if (this.panel == null) {
this.panel = atom.workspace.addModalPanel({item: this})
}
this.selectListView.focus()
this.selectListView.reset()
}
async toggle () {
if (this.panel != null) {
this.cancel()
} else {
this.currentProjectName = atom.project != null ? this.makeName(atom.project.getPaths()) : null
const projects = atom.history.getProjects().map(p => ({ name: this.makeName(p.paths), value: p.paths }))
await this.selectListView.update({items: projects})
this.attach()
}
}
makeName (paths) {
return paths.join(', ')
}
}