-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTabGroupie.js
293 lines (258 loc) · 10.5 KB
/
TabGroupie.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
"use strict";
var INFO =
["plugin", { name: "TabGroupie", version: "0.9.1",
href: "https://github.com/eri451/TabGroupie",
summary: "TabGroupie Plugin", xmlns: "dactyl" },
["author", { email: "[email protected]"},
"eri!" ],
["license", { href: "http://opensource.org/licenses/mit-license.php" },
"MIT" ],
["project", { name: "Pentadactyl", "min-version": "1.0b7.2" }],
["p", {},
"This plugin allows you to create tabgroups, rename or delete them and",
"move the currently use tab from group to group."],
["item", {},
["tags", {}, ":tgc :tgroup-move"],
["spec", {}, ":tgroup-move ", ["oa", {}, "targetGroup"]],
["description", {},
["p", {},
"Move the current tab to the specified group."],
["p", {},
"A groupname, that is not listed, will be handled as a new ",
"group with a new name assumed you confirm the prompt. ",
"[Y/n/b] for yes(default), no and background."]]],
["item", {},
["tags", {}, ":tgd :tgroup-delete"],
["spec", {}, ":tgroup-delete ", ["oa", {}, "GroupName"]],
["description", {},
"This is deleting the given tabgroup incl. its items."]],
["item", {},
["tags" ,{}, ":tgg :tgroup-get"],
["spec", {}, ":tgroup-get ", ["oa", {}, "TabIndex"]],
["description", {},
"This moves a tab to the current group."]],
["item", {},
["tags" ,{}, ":tgn :tgroup-new"],
["spec", {}, ":tgroup-new ", ["oa", {}, "newGroupname"]],
["description", {},
"Create a new tabgroup."]],
["item", {},
["tags", {}, ":tgs :tgroup-switch"],
["spec", {}, ":tgroup-switch ", ["oa", {}, "targetGroup"]],
["description", {},
"switch to last viewed tab of a specified group."]],
["item", {},
["tags", {}, ":tgt :tgroup-title"],
["spec", {}, ":tgroup-title ", ["oa", {}, "newName"]],
["description", {},
"Sets a new title to the currently used group."]]];
let TabGroupie = {
init: function init(){ // gets called to refresh the list too
let tabGroups = this.TabGroups = new Array();
tabs.getGroups( function ({ GroupItems }) {
let items = GroupItems.groupItems;
for(let x = 0; x < items.length; x+=1) {
let id = items[x].id;
let title = items[x].getTitle();
tabGroups.push({
"id": id,
"title": (title === "") ? "" + id : title,
});
}
});
},
getIdByTitle: function getIdByTitle(pattern){
for (let i = 0; i < this.TabGroups.length; i+=1){
if (this.TabGroups[i].title === pattern)
return this.TabGroups[i].id;
}
commandline.input("Group does not exist. Create? [Y/n/b] ", check, {argCount: "1"});
function check(args){
if ( args.length === 0
|| "" + args[0] === "y"
|| "" + args[0] === "Y"
|| "" + args[0] === "b" ) {
TabGroupie.newTabGroup(pattern, window.gBrowser.selectedTab, function () {
if ("" + args[0] !== "b")
tabs.selectAlternateTab();
});
}
return null;
}
},
changeGroup: function changeGroup(TargetGroupTitle){
let activeTab = window.gBrowser.selectedTab;
let targetGroupId = this.getIdByTitle(TargetGroupTitle);
if (targetGroupId != null){
TabView.moveTabTo(activeTab, targetGroupId);
TabView.hide();
tabs.selectAlternateTab();
}
},
changeTitle: function changeTitle(newTitle){
tabs.getGroups( function ({ GroupItems }) {
let activeGroup = GroupItems.getActiveGroupItem();
activeGroup.setTitle(newTitle);
});
},
newTabGroup: function newTabGroup(title, tab, callback){
this.createGroup(title, function ({ id }) {
tab = tab || window.gBrowser.addTab(prefs.get("browser.startup.homepage"));
TabView.moveTabTo(tab, id);
TabView.hide();
if (callback) callback(tab);
});
},
createGroup: function createGroup(title, callback){
tabs.getGroups( function ({ GroupItems }) {
let newGroup = GroupItems.newGroup();
newGroup.setTitle(title);
if (callback) callback(newGroup);
});
},
deleter: function deleter(title){
tabs.getGroups( function ({ GroupItems }) {
let items = GroupItems.groupItems;
for (let i = 0; i < items.length; i+=1) {
let item = items[i];
if (item.id === TabGroupie.getIdByTitle(title)){
item.closeAll();
break;
}
}
});
},
switchto: function switchto(title){
if (title){
tabs.getGroups( function ({ GroupItems }) {
let items = GroupItems.groupItems;
for (let i = 0; i < items.length; i+=1) {
let item = items[i];
if (item.id === TabGroupie.getIdByTitle(title)){
// alert(item.id);
let activeTab = item.getActiveTab();
let index = tabs.allTabs.indexOf(activeTab.tab);
config.tabbrowser.mTabContainer.selectedIndex = index;
break;
}
}
});
}else{
// alert("yep your are in the else");
tabs.getGroups( function ({ GroupItems }) {
let lastGroup = GroupItems.getLastActiveGroupItem();
// alert(lastGroup.id);
let activeTab = lastGroup.getActiveTab();
let index = tabs.allTabs.indexOf(activeTab.tab);
config.tabbrowser.mTabContainer.selectedIndex = index;
});
}
},
getTab: function getTab(index){
tabs.getGroups( function ({ GroupItems }) {
let activeGroup = GroupItems.getActiveGroupItem();
let tab = tabs.getTab(index - 1,false); // cause we count from 0
TabView.moveTabTo(tab, activeGroup.id);
let tabIndex = tabs.allTabs.indexOf(tab);
config.tabbrowser.mTabContainer.selectedIndex = tabIndex;
});
},
}
try{
TabGroupie.init();
}
catch (err){
dactyl.echoerr("Tabgroupie.init() failed");
}
group.commands.add(["tgroup-mo[ve]", "tgm"],
"Change current tab to another group.",
function (args){
TabGroupie.changeGroup("" + args[0]);
TabGroupie.init();
},
{
argCount: "1",
completer: function (context) { //thanks to Kris Maglione
context.keys = { text: "title", description: "id"};
context.completions = TabGroupie.TabGroups;
}
});
group.commands.add(["tgroup-t[itle]", "tgt"],
"Change the title of the current group",
function (args){
TabGroupie.changeTitle("" + args[0]);
TabGroupie.init();
},
{
argCount: "1",
});
group.commands.add(["tgroup-n[ew]", "tgn"],
"add a new tabgroup",
function (args){
TabGroupie.newTabGroup( "" + args[0], null, function (tab) {
window.gBrowser.selectedTab = tab;
});
TabGroupie.init();
},
{
argCount: "1",
});
group.commands.add(["tgroup-d[elete]", "tgd"],
"delete a tabgroup incl. its items",
function (args) {
TabGroupie.deleter("" + args[0]);
TabGroupie.init();
},
{
argCount: "1",
completer: function (context) { //thanks to Kris Maglione
context.keys = { text: "title", description: "id" };
context.completions = TabGroupie.TabGroups;
}
});
group.commands.add(["tgroup-s[witch]", "tgs"],
"switch to last viewed tab of a specified group",
function (args){
if (args[0] != undefined){
// alert("arg:" + args[0]);
TabGroupie.switchto("" + args[0]);
}else{
TabGroupie.switchto(); // go to last active Group
}
TabGroupie.init();
},
{
argCount: "?",
completer: function (context) { //thanks to Kris Maglione
context.keys = { text: "title", description: "id" };
context.completions = TabGroupie.TabGroups;
}
});
group.commands.add(["tgroup-g[et]", "tgg"],
"get a tab to the current group",
function (args){
TabGroupie.getTab(args[0]);
TabGroupie.init();
},
{
argCount: "1",
completer: function (context) {
completion.buffer(context);
}
});
group.commands.add(["tgroup-o[pen]", "tgo"],
"open a new tab to a new group",
function (args){
TabGroupie.newTabGroup( args[0].substring(0,6) + '...', null , function (tab) {
window.gBrowser.selectedTab = tab;
});
dactyl.open(args[0] || "about:blank");
TabGroupie.init();
},
{
bang: true,
completer: function (context) completion.url(context),
domains: function (args) commands.get("open").domains(args),
literal: 0,
privateData: true
});