Skip to content

Commit 51ba5e5

Browse files
committed
collapseStack cleanup
1 parent a393e3f commit 51ba5e5

File tree

4 files changed

+33
-46
lines changed

4 files changed

+33
-46
lines changed

chrome/content/tabutils-st.js

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -173,50 +173,43 @@ tabutils._stackTabs = function() {
173173
aTab.dispatchEvent(new CustomEvent("TabUnstacked", {bubbles: true}));
174174
};
175175

176-
gBrowser.collapseStack = function collapseStack(aTab) {
176+
gBrowser.collapseStack = function collapseStack(aTab, aForce) {
177177
if (!aTab.hasAttribute("group"))
178178
return;
179179

180-
if (aTab.hasAttribute("group-collapsed"))
180+
if (aForce == aTab.hasAttribute("group-collapsed"))
181181
return;
182182

183+
if (aForce == null)
184+
aForce = !aTab.hasAttribute("group-collapsed");
185+
183186
let tabs = this.siblingTabsOf(aTab);
184187
for (let tab of tabs) {
185-
tab.collapsed = true;
186-
tabutils.setAttribute(tab, "group-collapsed", true);
188+
tab.collapsed = aForce;
189+
tabutils.setAttribute(tab, "group-collapsed", aForce);
187190
if (tab.hasAttribute("group-selected"))
188191
aTab = tab;
189192
}
190193
aTab.collapsed = false;
191194

192-
let tabcontent = document.getAnonymousElementByAttribute(aTab, "class", "tab-content");
193-
if (tabcontent)
194-
tabcontent.setAttribute("group-counter", "(" + tabs.length + ")");
195+
if (aForce) {
196+
let tabcontent = document.getAnonymousElementByAttribute(aTab, "class", "tab-content");
197+
if (tabcontent)
198+
tabcontent.setAttribute("group-counter", "(" + tabs.length + ")");
199+
}
195200

196-
aTab.dispatchEvent(new CustomEvent("StackCollapsed", {bubbles: true}));
201+
aTab.dispatchEvent(new CustomEvent(aForce ? "StackCollapsed" : "StackExpanded", {bubbles: true}));
197202
this.mTabContainer.adjustTabstrip();
198-
};
199-
200-
gBrowser.expandStack = function expandStack(aTab) {
201-
if (!aTab.hasAttribute("group"))
202-
return;
203203

204-
if (!aTab.hasAttribute("group-collapsed"))
205-
return;
206-
207-
let tabs = this.siblingTabsOf(aTab);
208-
for (let tab of tabs) {
209-
tab.collapsed = false;
210-
tabutils.removeAttribute(tab, "group-collapsed");
211-
if (tab.hasAttribute("group-selected"))
212-
aTab = tab;
204+
if (!aForce) {
205+
this.mTabContainer.mTabstrip.ensureElementIsVisible(tabs[tabs.length - 1], false);
206+
this.mTabContainer.mTabstrip.ensureElementIsVisible(tabs[0], false);
213207
}
214-
aTab.dispatchEvent(new CustomEvent("StackExpanded", {bubbles: true}));
215-
this.mTabContainer.adjustTabstrip();
216-
this.mTabContainer.mTabstrip.ensureElementIsVisible(tabs[tabs.length - 1], false);
217-
this.mTabContainer.mTabstrip.ensureElementIsVisible(tabs[0], false);
208+
this.mTabContainer.mTabstrip.ensureElementIsVisible(aTab, false);
218209
};
219210

211+
gBrowser.expandStack = function expandStack(aTab) this.collapseStack(aTab, false);
212+
220213
gBrowser.updateStack = function updateStack(aTab, options = {}) {
221214
let tabs = this.siblingTabsOf(aTab);
222215
if (tabs.length == 0)
@@ -468,7 +461,7 @@ tabutils._stackTabs = function() {
468461
TU_getPref("extensions.tabutils.autoExpandStackAndCollapseOthersOnSelect", true)) {
469462
Array.forEach(this.visibleTabs, function(aTab) {
470463
if (aTab.hasAttribute("group-selected") && !aTab.selected)
471-
this.collapseStack(aTab);
464+
this.collapseStack(aTab, true);
472465
}, this);
473466
this.expandStack(aTab);
474467
this.mTabContainer.mTabstrip.ensureElementIsVisible(this.mCurrentTab, false);
@@ -479,7 +472,7 @@ tabutils._stackTabs = function() {
479472
if (lastTab && lastTab.hasAttribute("group") &&
480473
lastTab.getAttribute("group") != aTab.getAttribute("group") &&
481474
TU_getPref("extensions.tabutils.autoCollapseStackOnBlur", false))
482-
this.collapseStack(lastTab);
475+
this.collapseStack(lastTab, true);
483476
});
484477

485478
TU_hookCode("gBrowser.onTabPinning", "}", function() {
@@ -524,8 +517,8 @@ tabutils._stackTabs = function() {
524517

525518
TU_hookCode("gBrowser.createTooltip", /(tab|tn).getAttribute\("label"\)/, function(s, s1) (function() {
526519
$1.mOverTwisty ? $1.hasAttribute("group-collapsed") ?
527-
document.getElementById("context_expandStack").getAttribute("label") :
528-
document.getElementById("context_collapseStack").getAttribute("label")
520+
document.getElementById("context_collapseStack").getAttribute("label_expand") :
521+
document.getElementById("context_collapseStack").getAttribute("label_collapse")
529522
: this.isCollapsedStack($1) ?
530523
TU_getPref("extensions.tabutils.mouseHoverPopup", true) ?
531524
event.preventDefault() :

chrome/content/tabutils.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,10 +2190,7 @@ tabutils._tabClickingOptions = function() {
21902190
$("context_closeAllTabs").doCommand();
21912191
break;
21922192
case 51: //Collapse/Expand Stack
2193-
if (gBrowser.mContextTab.hasAttribute("group-collapsed"))
2194-
$("context_expandStack").doCommand();
2195-
else
2196-
$("context_collapseStack").doCommand();
2193+
$("context_collapseStack").doCommand();
21972194
break;
21982195
case 52: //Recolor Stack
21992196
$("context_colorStack").doCommand();
@@ -2448,8 +2445,10 @@ tabutils._tabContextMenu = function() {
24482445

24492446
var item = $("context_tabStackMenu");
24502447
if (item && !item.hidden && !item.collapsed) {
2451-
$("context_collapseStack").setAttribute("disabled", tab.hasAttribute("group-collapsed"));
2452-
$("context_expandStack").setAttribute("disabled", !tab.hasAttribute("group-collapsed"));
2448+
let item = $("context_collapseStack");
2449+
let collapsed = tab.hasAttribute("group-collapsed");
2450+
item.setAttribute("label", collapsed ? item.getAttribute("label_expand") : item.getAttribute("label_collapse"));
2451+
item.setAttribute("accesskey", collapsed ? item.getAttribute("accesskey_expand") : item.getAttribute("accesskey_collapse"));
24532452
}
24542453

24552454
var item = $("context_readTab");

chrome/content/tabutils.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@
177177
let bindingParent = document.getBindingParent(this);
178178
let tab = document.getBindingParent(bindingParent);
179179
180-
if (tab.hasAttribute("group-collapsed"))
181-
gBrowser.expandStack(tab);
182-
else
183-
gBrowser.collapseStack(tab);
180+
gBrowser.collapseStack(tab);
184181
185182
event.stopPropagation();
186183
]]></handler>

chrome/content/tabutils.xul

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,11 @@
275275
grouponly="true">
276276
<menupopup>
277277
<menuitem id="context_collapseStack"
278-
label="&collapseStack.label;"
279-
accesskey="&collapseStack.accesskey;"
278+
label_collapse="&collapseStack.label;"
279+
label_expand="&expandStack.label;"
280+
accesskey_collapse="&collapseStack.accesskey;"
281+
accesskey_expand="&expandStack.accesskey;"
280282
oncommand="gBrowser.collapseStack(gBrowser.mContextTab);"/>
281-
<menuitem id="context_expandStack"
282-
label="&expandStack.label;"
283-
accesskey="&expandStack.accesskey;"
284-
oncommand="gBrowser.expandStack(gBrowser.mContextTab);"/>
285283
<menuitem id="context_colorStack"
286284
label="&colorStack.label;"
287285
accesskey="&colorStack.accesskey;"

0 commit comments

Comments
 (0)