1
0
Fork 1
mirror of https://github.com/zen-browser/desktop.git synced 2025-07-09 00:35:31 +02:00
zen-desktop/src/browser/components/tabbrowser/content/tabbrowser-js.patch
Kristijan Ribarić 8c42614427 feat(pinned-tab-manager): Add restore pinned tabs to pinned url option
This commit introduces a new option to the pinned tab manager that allows users to restore pinned tabs to their pinned URL and title, even if the current tab has a different URL.

- Adds a new preference `zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url` to control this behavior.
- Updates the tab browser, tab state, and preferences code to support the new option.
- Adds a new UI element in the settings to allow users to enable/disable this feature.

This feature enhances the pinned tab manager by providing more control over how pinned tabs are restored when the browser is restarted.
2024-10-08 15:00:10 +02:00

152 lines
5 KiB
C++

diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js
index c89ae2cbb978d6218bd56a059c5ca1e371231607..6608e0d7df1092a7398979abb166895e0b4fb66b 100644
--- a/browser/components/tabbrowser/content/tabbrowser.js
+++ b/browser/components/tabbrowser/content/tabbrowser.js
@@ -456,11 +456,26 @@
return duplicateTabs;
},
+ get _numVisiblePinTabs() {
+ let i = 0;
+ for (let tab of this.tabs) {
+ if (!tab.pinned) {
+ break;
+ }
+ if (!tab.hidden) {
+ i++;
+ }
+ }
+ return i;
+ },
+
get _numPinnedTabs() {
- for (var i = 0; i < this.tabs.length; i++) {
- if (!this.tabs[i].pinned) {
+ let i = 0;
+ for (let tab of this.tabs) {
+ if (!tab.pinned) {
break;
}
+ i++;
}
return i;
},
@@ -2705,6 +2720,11 @@
);
}
+ let hasZenDefaultUserContextId = false;
+ if (typeof ZenWorkspaces !== "undefined") {
+ [userContextId, hasZenDefaultUserContextId] = ZenWorkspaces.getContextIdIfNeeded(userContextId);
+ }
+
if (!UserInteraction.running("browser.tabs.opening", window)) {
UserInteraction.start("browser.tabs.opening", "initting", window);
}
@@ -2773,6 +2793,9 @@
noInitialLabel,
skipBackgroundNotify,
});
+ if (hasZenDefaultUserContextId) {
+ t.setAttribute("zenDefaultUserContextId", "true");
+ }
if (insertTab) {
// insert the tab into the tab container in the correct position
this._insertTabAtIndex(t, {
@@ -3262,6 +3285,14 @@
) {
tabWasReused = true;
tab = this.selectedTab;
+
+ if (tabData.zenWorkspace) {
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
+ }
+ if (tabData.zenDefaultUserContextId) {
+ tab.setAttribute("zenDefaultUserContextId", "true");
+ }
+
if (!tabData.pinned) {
this.unpinTab(tab);
} else {
@@ -3283,6 +3314,13 @@
url = tabData.entries[activeIndex].url;
}
+ if(Services.prefs.getBoolPref("zen.pinned-tab-manager.restore-pinned-tabs-to-pinned-url", false) && tabData.pinned && tabData.zenPinnedUrl) {
+ tabData.entries = [{url: tabData.zenPinnedUrl, title: tabData.zenPinnedTitle}];
+ tabData.image = tabData.zenPinnedIcon;
+ tabData.index = 0;
+ url = tabData.zenPinnedUrl;
+ }
+
let preferredRemoteType = E10SUtils.getRemoteTypeForURI(
url,
gMultiProcessBrowser,
@@ -3311,6 +3349,12 @@
preferredRemoteType,
});
+ if (tabData.zenWorkspace) {
+ tab.setAttribute("zen-workspace-id", tabData.zenWorkspace);
+ }
+ if (tabData.zenDefaultUserContextId) {
+ tab.setAttribute("zenDefaultUserContextId", "true");
+ }
if (select) {
tabToSelect = tab;
}
@@ -3345,7 +3389,17 @@
this.tabContainer._invalidateCachedTabs();
}
}
+ if (tabData.zenPinnedUrl) {
+ tab.setAttribute("zen-pinned-url", tabData.zenPinnedUrl);
+ }
+ if (tabData.zenPinnedTitle) {
+ tab.setAttribute("zen-pinned-title", tabData.zenPinnedTitle);
+ }
+
+ if(tabData.zenPinnedIcon) {
+ tab.setAttribute("zen-pinned-icon", tabData.zenPinnedIcon);
+ }
tab.initialize();
}
@@ -4198,6 +4252,7 @@
isLastTab ||
aTab.pinned ||
aTab.hidden ||
+ true ||
this._removingTabs.size >
3 /* don't want lots of concurrent animations */ ||
!aTab.hasAttribute(
@@ -5131,10 +5186,10 @@
SessionStore.deleteCustomTabValue(aTab, "hiddenBy");
},
- hideTab(aTab, aSource) {
+ hideTab(aTab, aSource, forZenWorkspaces = false) {
if (
aTab.hidden ||
- aTab.pinned ||
+ (aTab.pinned && !forZenWorkspaces) ||
aTab.selected ||
aTab.closing ||
// Tabs that are sharing the screen, microphone or camera cannot be hidden.
@@ -7870,7 +7925,14 @@ var TabContextMenu = {
);
contextUnpinSelectedTabs.hidden =
!this.contextTab.pinned || !multiselectionContext;
-
+ let contextResetPinnedTab = document.getElementById("context_zen-reset-pinned-tab");
+ if(contextResetPinnedTab) {
+ contextResetPinnedTab.hidden = !this.contextTab.pinned || !this.contextTab.getAttribute("zen-pinned-url") || multiselectionContext;
+ }
+ let contextReplacePinnedUrlWithCurrent = document.getElementById("context_zen-replace-pinned-url-with-current");
+ if(contextReplacePinnedUrlWithCurrent) {
+ contextReplacePinnedUrlWithCurrent.hidden = !this.contextTab.pinned || !this.contextTab.getAttribute("zen-pinned-url") || multiselectionContext;
+ }
// Move Tab items
let contextMoveTabOptions = document.getElementById(
"context_moveTabOptions"