-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
executable file
·104 lines (82 loc) · 2.62 KB
/
main.js
File metadata and controls
executable file
·104 lines (82 loc) · 2.62 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*!
* Brackets Number Tabs Extension
*
* @author John Smith
* @license http://opensource.org/licenses/MIT
*/
/*jslint vars: true, plusplus: true, nomen: true, regexp: true, maxerr: 50 */
/*global define, brackets */
define(function (require, exports, module) {
'use strict';
var AppInit = brackets.getModule('utils/AppInit');
var CommandManager = brackets.getModule('command/CommandManager');
var Commands = brackets.getModule('command/Commands');
var ExtensionUtils = brackets.getModule('utils/ExtensionUtils');
var KeyBindingManager = brackets.getModule('command/KeyBindingManager');
var MainViewManager = brackets.getModule('view/MainViewManager');
function setDocument(index, active) {
var workingSet = MainViewManager.getWorkingSet();
if(!active) {
// TODO: what do we do if there are > 2 panes...
var fullWorkingSet = MainViewManager.getWorkingSet(MainViewManager.ALL_PANES);
var fileCount = fullWorkingSet.length - workingSet.length;
if(fileCount <= index) { return; }
var paneId = MainViewManager.getActivePaneId();
var paneIds = MainViewManager.getPaneIdList();
var length = paneIds.length;
if(length < 2) { return; }
for(var i = 0; i < length; ++i) {
if(paneIds[i] !== paneId) {
paneId = paneIds[i];
break;
}
}
MainViewManager.setActivePaneId(paneId);
workingSet = MainViewManager.getWorkingSet();
}
if(workingSet && workingSet.length > index) {
var file = workingSet[index];
if(file) {
CommandManager.execute(Commands.CMD_OPEN, {fullPath: file.fullPath});
}
}
}
function cb(index, active) {
return function() {
setDocument(index, active);
};
}
var id = 'ohnnyj.numbertabs.';
function bindActivePane(i) {
var key = [{
key: 'Ctrl-' + i
}, {
key: 'Cmd-' + i,
platform: 'mac'
}];
var _id = id + 'active.' + i;
CommandManager.register('Tab ' + i, _id, cb(i - 1, true));
KeyBindingManager.addBinding(_id, key);
}
function bindInactivePane(i) {
var key = [{
key: 'Alt-' + i
}, {
key: 'Opt-' + i,
platform: 'mac'
}];
var _id = id + 'inactive.' + i;
CommandManager.register('Inactive Pane Tab ' + i, _id, cb(i - 1, false));
KeyBindingManager.addBinding(_id, key);
}
function bind() {
for(var i = 1; i <= 9; ++i) {
bindActivePane(i);
bindInactivePane(i);
}
}
AppInit.appReady(function () {
ExtensionUtils.loadStyleSheet(module, 'res/style/numbertabs.less');
bind();
});
});