-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
72 lines (70 loc) · 1.97 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
70
71
72
var url = require('url');
var TermView = require('./lib/TermView');
module.exports = {
termViews: [],
config: {
"autoRunCommand": {
"type": "string",
"default": null
}
},
config:{
autoRunCommand:{
type:'string',
default: null
}
},
activate: function (state) {
this.state = state;
var self = this;
atom.commands.add('atom-workspace','term:open', self.openTerm.bind(self));
['up', 'right', 'down', 'left'].forEach(function (direction) {
atom.commands.add('atom-workspace','term:open-split-'+direction, self.splitTerm.bind(self, direction));
});
if (state.termViews) {
// TODO: restore
}
},
createTermView: function () {
var opts = {
runCommand: atom.config.get('term.autoRunCommand')
};
var termView = new TermView(opts);
termView.on('remove', this.handleRemoveTerm.bind(this));
this.termViews.push(termView);
return termView;
},
splitTerm: function (direction) {
var termView = this.createTermView();
direction = capitalize(direction);
atom.workspace.getActivePane()['split'+direction]({
items: [termView]
});
},
openTerm: function() {
var termView = new TermView();
activePane = atom.workspace.getActivePane();
activePane.addItem(termView);
activePane.activateNextItem();
},
handleRemoveTerm: function (termView) {
var termViews = this.termViews;
termViews.splice(termViews.indexOf(termView), 1); // remove
},
deactivate: function () {
this.termViews.forEach(function (view) {
view.deactivate();
});
},
serialize: function () {
var termViewsState = this.termViews.map(function () {
return termViews.serialize();
});
return {
termViews: termViewsState
};
}
};
function capitalize (str) {
return str[0].toUpperCase() + str.slice(1).toLowerCase();
}