-
Notifications
You must be signed in to change notification settings - Fork 0
/
language-bve.js
88 lines (75 loc) · 2.71 KB
/
language-bve.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
77
78
79
80
81
82
83
84
85
86
87
88
'use babel';
import { CompositeDisposable } from 'atom';
SearchStaView = null;
export default {
staSearchListView: null, //駅名検索ビュー
subscriptions: null,
activate(state) {
// Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
this.subscriptions = new CompositeDisposable();
// コマンド登録
this.subscriptions.add(atom.commands.add('atom-workspace', {
'language-bve:GrammarJudgment': () => this.grammarJudgment(),
'language-bve:JumpStation': () => this.openSearchStaPanel()
}));
this.subscriptions.add(atom.workspace.observeTextEditors(editor => {
console.log("New Editor Instanced.");
//新しいエディタがインスタンス化された際
//もし初期化されていなかったら初期化
if(SearchStaView == null){
SearchStaView = require('./bve-searchStaView.js');
}
if(this.staSearchListView == null){
this.staSearchListView = new SearchStaView();
}
if(editor.getCursorBufferPosition().row == 0){
this.setGrammar(editor);
}
editor.onDidChange(event => {
//編集した際
if(editor.getCursorBufferPosition().row == 0){
this.setGrammar(editor);
}
})
editor.onDidSave(event => {
//保存した際(なぜか文法がPlainになってしまうので。)
this.setGrammar(editor);
})
}));
},
deactivate() {
this.staSearchListView.destroy();
this.staSearchListView = null;
this.subscriptions.dispose();
},
//状態を保存しておく
serialize() {
},
//駅名検索パネルを表示
openSearchStaPanel(){
if(this.staSearchListView.isVisible){
this.staSearchListView.hide();
}else{
this.staSearchListView.show(atom.workspace.getActiveTextEditor());
};
},
//文法判定コマンド
grammarJudgment() {
this.setGrammar(atom.workspace.getActiveTextEditor());
},
//文法判定
setGrammar(editor) {
var header = editor.lineTextForBufferRow(0);
if(header.match(/BveTs\s*Map\s*2.02/gi)){
editor.setGrammar(atom.grammars.grammarForScopeName('source.bve-map-2.02'));
}else if(header.match(/BveTs\s*Structure\s*List/gi)){
editor.setGrammar(atom.grammars.grammarForScopeName('source.bve-structure'));
}else if(header.match(/BveTs\s*Sound\s*List/gi)){
editor.setGrammar(atom.grammars.grammarForScopeName('source.bve-sound'));
}else if(header.match(/BveTs\s*Station\s*List/gi)){
editor.setGrammar(atom.grammars.grammarForScopeName('source.bve-station'));
}else if(header.match(/BveTs\s*Train/gi)){
editor.setGrammar(atom.grammars.grammarForScopeName('source.bve-train'));
}
}
};