This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 363
/
Copy pathfile-view.js
52 lines (44 loc) · 1.71 KB
/
file-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
import {CompositeDisposable} from 'atom'
import getIconServices from './get-icon-services'
export default class FileView {
constructor (file) {
this.file = file
this.subscriptions = new CompositeDisposable()
this.subscriptions.add(this.file.onDidDestroy(() => this.subscriptions.dispose()))
this.element = document.createElement('li')
this.element.setAttribute('is', 'tree-view-file')
this.element.draggable = true
this.element.classList.add('file', 'entry', 'list-item')
this.fileName = document.createElement('span')
this.fileName.classList.add('name', 'icon')
this.element.appendChild(this.fileName)
this.fileName.textContent = this.file.name
this.fileName.title = this.file.name
this.fileName.dataset.name = this.file.name
this.fileName.dataset.path = this.file.path
this.updateIcon()
this.subscriptions.add(this.file.onDidStatusChange(() => this.updateStatus()))
this.subscriptions.add(getIconServices().onDidChange(() => this.updateIcon()))
this.updateStatus()
}
updateIcon () {
getIconServices().updateFileIcon(this)
this.element.getPath = this.getPath.bind(this)
this.element.isPathEqual = this.isPathEqual.bind(this)
this.element.file = this.file
this.element.fileName = this.fileName
this.element.updateStatus = this.updateStatus.bind(this)
}
updateStatus () {
this.element.classList.remove('status-ignored', 'status-ignored-name', 'status-modified', 'status-added')
if (this.file.status != null) {
this.element.classList.add(`status-${this.file.status}`)
}
}
getPath () {
return this.fileName.dataset.path
}
isPathEqual (pathToCompare) {
return this.file.isPathEqual(pathToCompare)
}
}