-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (55 loc) · 1.45 KB
/
index.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
const crypto = require('crypto')
const noop = require('noop2')
const url = require('url')
const prefix = crypto.createHash('md5')
.update(__dirname)
.digest('hex') + ':'
var counter = 0
module.exports = Pane
function Pane (opts, init, exit) {
const id = String(++counter)
const disposers = []
if (typeof opts === 'function') {
exit = init
init = opts
opts = {}
}
opts = opts || {}
init = init || noop
exit = exit || noop
disposers.push(
atom.views.addViewProvider(Model, View),
atom.workspace.addOpener(opener)
)
function Model () {}
Model.prototype.destroy = exit
Model.prototype.createView = View
Model.prototype.getTitle = function () {
return opts.title || 'Atom Pane'
}
function View (model) {
var el = opts.element || 'div'
if (typeof el === 'string') el = document.createElement(el)
if (typeof el === 'function') el = new el() // eslint-disable-line
model.div = el
return el
}
return atom.workspace.open(prefix + '//' + id, {
activatePane: opts.activatePane !== false,
searchAllPanes: false,
split: opts.split
}).then(function (model) {
disposers.forEach(function (disposer) {
return disposer.dispose()
})
setTimeout(function () {
init(null, atom.views.getView(model))
})
}).catch(init)
function opener (uri) {
uri = url.parse(uri)
if (uri.protocol !== prefix) return
if (uri.host !== id) return
return new Model()
}
}