Refactor ZenWorkspaces to use _createNewTabForWorkspace method for preparing new workspace

This commit is contained in:
Mauro Balades
2024-07-13 22:09:50 +02:00
parent 9a816fe73a
commit 7e1c76a1da
9 changed files with 94 additions and 11 deletions

View File

@@ -29,7 +29,20 @@ var ZenWorkspaces = {
return this._workspaceCache;
},
onWorkspacesEnabledChanged() {
if (this.workspaceEnabled) {
this.initializeWorkspaces();
} else {
this._workspaceCache = null;
document.getElementById("zen-workspaces-button")?.remove();
for (let tab of gBrowser.tabs) {
gBrowser.showTab(tab);
}
}
},
async initializeWorkspaces() {
Services.prefs.addObserver("zen.workspaces.enabled", this.onWorkspacesEnabledChanged.bind(this));
this.initializeWorkspacesButton();
let file = new FileUtils.File(this._storeFile);
if (!file.exists()) {
@@ -149,6 +162,10 @@ var ZenWorkspaces = {
initializeWorkspacesButton() {
if (!this.workspaceEnabled) {
return;
} else if (document.getElementById("zen-workspaces-button")) {
let button = document.getElementById("zen-workspaces-button");
button.removeAttribute("hidden");
return;
}
let browserTabs = document.getElementById("tabbrowser-tabs");
let button = document.createElement("toolbarbutton");

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/preferences/jar.mn b/browser/components/preferences/jar.mn
index 3b60d18e483bc3c4e9b4309f0dc1e4231b7116b1..aa30bc3de15b68ac90c12142a8851af99e1209ae 100644
index 3b60d18e483bc3c4e9b4309f0dc1e4231b7116b1..e5b679b25941a7f1ed52db9fa3f7740a7220b9e4 100644
--- a/browser/components/preferences/jar.mn
+++ b/browser/components/preferences/jar.mn
@@ -23,3 +23,5 @@ browser.jar:
@@ -7,4 +7,4 @@ index 3b60d18e483bc3c4e9b4309f0dc1e4231b7116b1..aa30bc3de15b68ac90c12142a8851af9
content/browser/preferences/web-appearance-dark.svg
content/browser/preferences/web-appearance-light.svg
+
+ content/browser/preferences/zen-looks.js
+ content/browser/preferences/zen-settings.js

View File

@@ -1,12 +1,13 @@
diff --git a/browser/components/preferences/preferences.js b/browser/components/preferences/preferences.js
index c30a51c67ce636fa889090419a5c2642d74b4f49..b48ab31c564db4a4911c9fca291b4f09ba1025af 100644
index 7e21bab426b6eb52fe84876d817fddbdb1a35ffc..fe23eb36a28a2baa4facad80a776e739ee6e43b1 100644
--- a/browser/components/preferences/preferences.js
+++ b/browser/components/preferences/preferences.js
@@ -198,6 +198,7 @@ function init_all() {
@@ -196,6 +196,8 @@ function init_all() {
// the entire document.
Preferences.queueUpdateOfAllElements();
Services.telemetry.setEventRecordingEnabled("aboutpreferences", true);
+ register_module("paneZenLooks", gZenLooksAndFeel);
+ register_module("paneZenWorkspaces", gZenWorkspacesSettings);
register_module("paneGeneral", gMainPane);
register_module("paneHome", gHomePane);

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/preferences/preferences.xhtml b/browser/components/preferences/preferences.xhtml
index eee227822a772bec128d6adbe4f6aca90ed810f6..b52ee22054e3b2c80d4b780bc01507478becc583 100644
index 3affb19d1a243da4a5782c9a4a5588d165b4119f..ccb56cc323ff5c3e94013de782af54911fc0c360 100644
--- a/browser/components/preferences/preferences.xhtml
+++ b/browser/components/preferences/preferences.xhtml
@@ -43,6 +43,8 @@
@@ -11,7 +11,7 @@ index eee227822a772bec128d6adbe4f6aca90ed810f6..b52ee22054e3b2c80d4b780bc0150747
<link rel="localization" href="branding/brand.ftl"/>
<link rel="localization" href="browser/browser.ftl"/>
<!-- Used by fontbuilder.js -->
@@ -99,6 +101,12 @@
@@ -97,6 +99,12 @@
<hbox flex="1">
<vbox class="navigation">
@@ -24,7 +24,7 @@ index eee227822a772bec128d6adbe4f6aca90ed810f6..b52ee22054e3b2c80d4b780bc0150747
<!-- category list -->
<richlistbox id="categories" data-l10n-id="category-list" data-l10n-attrs="aria-label">
<richlistitem id="category-general"
@@ -112,6 +120,17 @@
@@ -110,6 +118,28 @@
<label class="category-name" flex="1" data-l10n-id="pane-general-title"></label>
</richlistitem>
@@ -38,11 +38,22 @@ index eee227822a772bec128d6adbe4f6aca90ed810f6..b52ee22054e3b2c80d4b780bc0150747
+ <image class="category-icon"/>
+ <label class="category-name" flex="1" data-l10n-id="pane-zen-looks-title"></label>
+ </richlistitem>
+
+ <richlistitem id="category-zen-workspaces"
+ class="category"
+ value="paneZenWorkspaces"
+ helpTopic="prefs-main"
+ data-l10n-id="category-zen-workspaces"
+ data-l10n-attrs="tooltiptext"
+ align="center">
+ <image class="category-icon"/>
+ <label class="category-name" flex="1" data-l10n-id="pane-zen-workspaces-title"></label>
+ </richlistitem>
+
<richlistitem id="category-home"
class="category"
value="paneHome"
@@ -230,11 +249,13 @@
@@ -228,11 +258,13 @@
<html:a href="about:policies" target="_blank" data-l10n-id="managed-notice"/>
</hbox>
</hbox>
@@ -56,11 +67,12 @@ index eee227822a772bec128d6adbe4f6aca90ed810f6..b52ee22054e3b2c80d4b780bc0150747
</hbox>
</hbox>
<vbox id="mainPrefPane">
@@ -248,6 +269,7 @@
@@ -246,6 +278,8 @@
#include sync.inc.xhtml
#include experimental.inc.xhtml
#include moreFromMozilla.inc.xhtml
+#include zenLooksAndFeel.inc.xhtml
+#include zenWorkspaces.inc.xhtml
</vbox>
</vbox>
</vbox>

View File

@@ -48,6 +48,11 @@ var gZenLooksAndFeel = {
},
};
var gZenWorkspacesSettings = {
init() {
},
};
Preferences.addAll([
{
id: "zen.theme.toolbar-themed",
@@ -64,4 +69,9 @@ Preferences.addAll([
type: "bool",
default: false,
},
{
id: "zen.workspaces.enabled",
type: "bool",
default: true,
}
]);

View File

@@ -1,4 +1,4 @@
<script src="chrome://browser/content/preferences/zen-looks.js"/>
<script src="chrome://browser/content/preferences/zen-settings.js"/>
<html:template id="template-paneZenLooks">
<hbox id="zenLooksCategory"
class="subcategory"

View File

@@ -0,0 +1,25 @@
<html:template id="template-paneZenWorkspaces">
<hbox id="ZenWorkspacesCategory"
class="subcategory"
hidden="true"
data-category="paneZenWorkspaces">
<html:h1 data-l10n-id="pane-workspaces-title"/>
</hbox>
<hbox id="zenSidePanelsCategory"
class="subcategory"
hidden="true"
data-category="paneZenWorkspaces">
<html:h1 data-l10n-id="pane-settings-workspaces-title"/>
</hbox>
<groupbox id="zenSidePanelsGroup" data-category="paneZenWorkspaces" hidden="true" class="highlighting-group">
<label><html:h2 data-l10n-id="zen-settings-workspaces-header"/></label>
<description class="description-deemphasized" data-l10n-id="zen-settings-workspaces-description" />
<checkbox id="zenWorkspacesActivate"
data-l10n-id="zen-settings-workspaces-enabled"
preference="zen.workspaces.enabled"/>
</groupbox>
</html:template>

View File

@@ -19,4 +19,16 @@ zen-side-panels-enabled =
zen-look-and-feel-compact-view-header = Show in compact view
zen-look-and-feel-compact-view-description = Only show the toolbars you use!
zen-look-and-feel-compact-view-enabled =
.label = Enable { -brand-short-name }'s compact mode
.label = Enable { -brand-short-name }'s compact mode
pane-zen-workspaces-title = Workspaces
category-zen-workspaces =
.tooltiptext = { pane-workspaces-title }
pane-zen-workspaces-header = Workspaces
zen-settings-workspaces-header = General settings for workspaces
zen-settings-workspaces-description = With workspaces, you can have multiple browsing sessions at once!
zen-settings-workspaces-enabled =
.label = Enable Workspaces (Experimental)

View File

@@ -185,3 +185,9 @@ groupbox h2 {
position: absolute;
background: var(--zen-colors-tertiary);
}
/* Workspace */
#category-zen-workspaces > .category-icon {
list-style-image: url("chrome://browser/skin/window.svg");
}