Skip to content

Commit 4d0a1dd

Browse files
committed
Feature / popup: open tab counters, lists, tab moving now work with tabs in non-current windows
1 parent df43ffb commit 4d0a1dd

4 files changed

Lines changed: 84 additions & 23 deletions

File tree

src/css/popup.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ body {
242242
[data-theme="dark"] img.clear-storage-icon,
243243
[data-theme="dark"] img.delete-assignment,
244244
[data-theme="dark"] #edit-sites-assigned .menu-icon,
245-
[data-theme="dark"] #container-info-table .menu-icon,
245+
[data-theme="dark"] #container-info-table-curr-windows .menu-icon,
246+
[data-theme="dark"] #container-info-table-other-windows .menu-icon,
246247
[data-theme="dark"] #always-open .menu-icon,
247248
[data-theme="dark"] #always-open-in .menu-icon {
248249
filter: invert(0);
@@ -2084,7 +2085,8 @@ h3.title {
20842085

20852086
/* Maintain 1:1 square ratio for favicons of websites added to a specific container */
20862087
#edit-sites-assigned .menu-icon,
2087-
#container-info-table .menu-icon {
2088+
#container-info-table-curr-windows .menu-icon,
2089+
#container-info-table-other-windows .menu-icon {
20882090
inline-size: 16px;
20892091
}
20902092
/* stylelint-enable no-descending-specificity */
@@ -2135,6 +2137,11 @@ hr {
21352137
display: block;
21362138
}
21372139

2140+
#container-info-table-other-windows hr {
2141+
margin-block: 4px;
2142+
margin-inline: 4px;
2143+
}
2144+
21382145
.sub-header-wrapper {
21392146
margin-block-start: 12px;
21402147
padding-inline: 16px;

src/js/background/backgroundLogic.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ const backgroundLogic = {
255255
},
256256

257257
async getTabs(options) {
258-
const requiredArguments = ["cookieStoreId", "windowId"];
258+
const requiredArguments = ["cookieStoreId"];
259259
this.checkArgs(requiredArguments, options, "getTabs");
260260
const { cookieStoreId, windowId } = options;
261261

@@ -299,7 +299,7 @@ const backgroundLogic = {
299299
},
300300

301301
async moveTabsToWindow(options) {
302-
const requiredArguments = ["cookieStoreId", "windowId"];
302+
const requiredArguments = ["cookieStoreId"];
303303
this.checkArgs(requiredArguments, options, "moveTabsToWindow");
304304
const { cookieStoreId, windowId } = options;
305305

@@ -397,13 +397,17 @@ const backgroundLogic = {
397397
const containerState = await identityState.storageArea.get(cookieStoreId);
398398
const openTabs = await browser.tabs.query({
399399
cookieStoreId,
400+
});
401+
const openTabsCurrWin = await browser.tabs.query({
402+
cookieStoreId,
400403
windowId
401404
});
402405
identitiesOutput[cookieStoreId] = {
403406
hasHiddenTabs: !!containerState.hiddenTabs.length,
404407
hasOpenTabs: !!openTabs.length,
405408
numberOfHiddenTabs: containerState.hiddenTabs.length,
406409
numberOfOpenTabs: openTabs.length,
410+
numberOfOpenTabsCurrWin: openTabsCurrWin.length,
407411
isIsolated: !!containerState.isIsolated
408412
};
409413
return;

src/js/popup.js

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ const Logic = {
200200
icon: "default-tab",
201201
color: "default-tab",
202202
numberOfHiddenTabs: 0,
203-
numberOfOpenTabs: 0
203+
numberOfOpenTabs: 0,
204+
numberOfOpenTabsCurrWin: 0
204205
};
205206
// Handle old style rejection with null and also Promise.reject new style
206207
try {
@@ -215,14 +216,14 @@ const Logic = {
215216
return activeTabs.length;
216217
},
217218

218-
_disableMenuItem(message, elementToDisable = document.querySelector("#move-to-new-window")) {
219+
_disableMenuItem(message, elementToDisable) {
219220
elementToDisable.setAttribute("title", message);
220221
elementToDisable.removeAttribute("tabindex");
221222
elementToDisable.classList.remove("hover-highlight");
222223
elementToDisable.classList.add("disabled-menu-item");
223224
},
224225

225-
_enableMenuItems(elementToEnable = document.querySelector("#move-to-new-window")) {
226+
_enableMenuItems(elementToEnable) {
226227
elementToEnable.removeAttribute("title");
227228
elementToEnable.setAttribute("tabindex", "0");
228229
elementToEnable.classList.add("hover-highlight");
@@ -264,6 +265,7 @@ const Logic = {
264265
identity.hasHiddenTabs = stateObject.hasHiddenTabs;
265266
identity.numberOfHiddenTabs = stateObject.numberOfHiddenTabs;
266267
identity.numberOfOpenTabs = stateObject.numberOfOpenTabs;
268+
identity.numberOfOpenTabsCurrWin = stateObject.numberOfOpenTabsCurrWin;
267269
identity.isIsolated = stateObject.isIsolated;
268270
}
269271
if (containerOrder) {
@@ -924,15 +926,20 @@ Logic.registerPanel(P_CONTAINER_INFO, {
924926
}
925927

926928
const moveTabsEl = document.querySelector("#move-to-new-window");
927-
const numTabs = await Logic.numTabs();
929+
const moveAllTabsEl = document.querySelector("#move-all-to-new-window");
928930
if (incompatible) {
929-
Logic._disableMenuItem("Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs.");
930-
return;
931-
} else if (numTabs === 1) {
932-
Logic._disableMenuItem("Cannot move a tab from a single-tab window.");
931+
Logic._disableMenuItem("Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs.", moveTabsEl);
932+
Logic._disableMenuItem("Moving container tabs is incompatible with Pulse, PageShot, and SnoozeTabs.", moveAllTabsEl);
933933
return;
934934
}
935935

936+
Utils.addEnterHandler(moveAllTabsEl, async () => {
937+
await browser.runtime.sendMessage({
938+
method: "moveTabsToWindow",
939+
cookieStoreId: Logic.currentIdentity().cookieStoreId,
940+
});
941+
window.close();
942+
});
936943
Utils.addEnterHandler(moveTabsEl, async () => {
937944
await browser.runtime.sendMessage({
938945
method: "moveTabsToWindow",
@@ -972,20 +979,23 @@ Logic.registerPanel(P_CONTAINER_INFO, {
972979
trHasTabs.style.display = !identity.hasHiddenTabs && !identity.hasOpenTabs ? "none" : "";
973980
}
974981

982+
const moveTabs = document.querySelector("#move-to-new-window");
983+
const moveTabsAll = document.querySelector("#move-all-to-new-window");
984+
if (identity.numberOfOpenTabsCurrWin === 0) {
985+
Logic._disableMenuItem("No tabs available for this container in this window", moveTabs);
986+
}
975987
if (identity.numberOfOpenTabs === 0) {
976-
Logic._disableMenuItem("No tabs available for this container");
977-
} else {
978-
Logic._enableMenuItems();
988+
Logic._disableMenuItem("No tabs available for this container", moveTabsAll);
979989
}
980990

981991
this.intializeShowHide(identity);
982992

983993
// Let's retrieve the list of tabs.
984994
const tabs = await browser.runtime.sendMessage({
985995
method: "getTabs",
986-
windowId: browser.windows.WINDOW_ID_CURRENT,
987996
cookieStoreId: Logic.currentIdentity().cookieStoreId
988997
});
998+
const currentWindowId = (await browser.windows.getCurrent()).id;
989999
const manageContainer = document.querySelector("#manage-container-link");
9901000
Utils.addEnterHandler(manageContainer, async () => {
9911001
Logic.showPanel(P_CONTAINER_EDIT, identity);
@@ -997,7 +1007,7 @@ Logic.registerPanel(P_CONTAINER_INFO, {
9971007
Logic.showPanel(P_CLEAR_CONTAINER_STORAGE, identity);
9981008
}
9991009
});
1000-
return this.buildOpenTabTable(tabs);
1010+
return this.buildOpenTabTable(tabs, currentWindowId);
10011011
},
10021012

10031013
intializeShowHide(identity) {
@@ -1029,13 +1039,24 @@ Logic.registerPanel(P_CONTAINER_INFO, {
10291039
return;
10301040
},
10311041

1032-
buildOpenTabTable(tabs) {
1042+
buildOpenTabTable(tabs, currentWindowId) {
10331043
// Let's remove all the previous tabs.
1034-
const table = document.getElementById("container-info-table");
1035-
while (table.firstChild) {
1036-
table.firstChild.remove();
1044+
const tableCurrWin = document.getElementById("container-info-table-curr-windows");
1045+
while (tableCurrWin.firstChild) {
1046+
tableCurrWin.firstChild.remove();
1047+
}
1048+
1049+
const tableOtherWin = document.getElementById("container-info-table-other-windows");
1050+
while (tableOtherWin.firstChild) {
1051+
tableOtherWin.firstChild.remove();
10371052
}
10381053

1054+
// Sort tabs by window id so that we'll be able to display horizontal rules between tabs in different windows below
1055+
tabs.sort((a, b) => a.windowId - b.windowId);
1056+
// For making horizontal rules between tabs of different windows
1057+
let prevWindowId = undefined;
1058+
const makeHorizontalRule = () => document.createElement("hr");
1059+
10391060
// For each one, let's create a new line.
10401061
const fragment = document.createDocumentFragment();
10411062
for (let tab of tabs) { // eslint-disable-line prefer-const
@@ -1051,12 +1072,21 @@ Logic.registerPanel(P_CONTAINER_INFO, {
10511072
</td>`;
10521073
tr.querySelector(".favicon").appendChild(Utils.createFavIconElement(tab.favIconUrl));
10531074
tr.setAttribute("tabindex", "0");
1054-
table.appendChild(fragment);
1075+
if (tab.windowId === currentWindowId) {
1076+
tableCurrWin.appendChild(fragment);
1077+
} else {
1078+
if (prevWindowId !== undefined && tab.windowId !== prevWindowId) {
1079+
tableOtherWin.appendChild(makeHorizontalRule());
1080+
}
1081+
prevWindowId = tab.windowId;
1082+
tableOtherWin.appendChild(fragment);
1083+
}
10551084

10561085
// On click, we activate this tab. But only if this tab is active.
10571086
if (!tab.hiddenState) {
10581087
Utils.addEnterHandler(tr, async () => {
10591088
await browser.tabs.update(tab.id, { active: true });
1089+
await browser.windows.update(tab.windowId, { focused: true });
10601090
window.close();
10611091
});
10621092

src/popup.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ <h3 class="title" id="container-info-title" data-i18n-attribute-message-id="pers
229229
</span>
230230
</td>
231231
</tr>
232+
<tr class="menu-item hover-highlight keyboard-nav" id="move-all-to-new-window" tabindex="0">
233+
<td>
234+
<img class="menu-icon" alt="" src="/img/movetowindow-16.svg" />
235+
<span class="menu-text" data-i18n-message-id="moveTabsInAllWinsToASingleWindow"></span>
236+
<span class="menu-arrow">
237+
</span>
238+
</td>
239+
</tr>
232240
<tr class="menu-item hover-highlight keyboard-nav" id="always-open" tabindex="0">
233241
<td>
234242
<img class="menu-icon" alt="" src="/img/container-openin-16.svg" />
@@ -251,7 +259,19 @@ <h3 class="title" id="container-info-title" data-i18n-attribute-message-id="pers
251259
<div class="sub-header" data-i18n-message-id="openTabs"></div>
252260
</div>
253261
<div class="scrollable">
254-
<table class="menu" id="container-info-table">
262+
<table class="menu" id="container-info-table-curr-windows">
263+
<tr class="menu-item hover-highlight keyboard-nav" tabindex="0">
264+
<td>
265+
<div class="favicon"><img class="menu-icon" src="https://www.mozilla.org/favicon.ico" /></div>
266+
<span class="menu-text truncate-text">www.mozillllllllllllllllllllllllllllllllllllla.org</span>
267+
<img class="trash-button" src="/img/close.svg" />
268+
</td>
269+
</tr>
270+
</table>
271+
<div class="sub-header-wrapper">
272+
<div class="sub-header" data-i18n-message-id="openTabsInOtherWindows"></div>
273+
</div>
274+
<table class="menu" id="container-info-table-other-windows">
255275
<tr class="menu-item hover-highlight keyboard-nav" tabindex="0">
256276
<td>
257277
<div class="favicon"><img class="menu-icon" src="https://www.mozilla.org/favicon.ico" /></div>

0 commit comments

Comments
 (0)