Finished profile panel UI

This commit is contained in:
mauro-balades
2024-04-02 21:09:35 +02:00
parent e6fcb2eac4
commit 320d56356d
15 changed files with 336 additions and 43 deletions

View File

@@ -0,0 +1,11 @@
diff --git a/browser/base/content/global-scripts.inc b/browser/base/content/global-scripts.inc
index f5f43b8f9509c37bf217b3ed1c6c562be85430e0..c8ab55760f817aa14e3db15f6b5556118e65d218 100644
--- a/browser/base/content/global-scripts.inc
+++ b/browser/base/content/global-scripts.inc
@@ -22,4 +22,6 @@ if (AppConstants.platform == "macosx") {
Services.scriptloader.loadSubScript("chrome://global/content/macWindowMenu.js", this);
}
+Services.scriptloader.loadSubScript("chrome://browser/content/zen-browser-places.js", this);
+
</script>

View File

@@ -0,0 +1,12 @@
diff --git a/browser/base/content/webext-panels.xhtml b/browser/base/content/webext-panels.xhtml
index 902fa7e7b3edb3c9502a12e475ade016436b2490..5c6ad5f9d86cd29a12483d7cb71ce9979002f092 100644
--- a/browser/base/content/webext-panels.xhtml
+++ b/browser/base/content/webext-panels.xhtml
@@ -16,6 +16,7 @@
<script src="chrome://global/content/globalOverlay.js"/>
<script src="chrome://browser/content/utilityOverlay.js"/>
<script src="chrome://global/content/editMenuOverlay.js"/>
+ <script src="chrome://browser/content/zen-browser-places.js"/>
<linkset>
<html:link rel="stylesheet" href="chrome://global/skin/global.css" />

View File

@@ -339,7 +339,7 @@
<toolbarbutton id="fxa-toolbar-menu-button" class="toolbarbutton-1 chromeclass-toolbar-additional subviewbutton-nav"
badged="true"
delegatesanchor="true"
onmousedown="gSync.toggleAccountPanel(this, event)"
onmousedown="ZenProfileDialogUI.showSubView(this, event)"
onkeypress="gSync.toggleAccountPanel(this, event)"
consumeanchor="fxa-toolbar-menu-button"
closemenu="none"

View File

@@ -0,0 +1,141 @@
var ZenProfileDialogUI = {
showSubView(parent, event) {
let element = parent.querySelector('.zen-side-bar-profiles-button-panel-correction') || parent;
PanelUI.showSubView('PanelUI-zen-profiles', element, event);
this._updateProfilesList();
this._updateCurentProfileId();
},
_updateProfilesList() {
let parentList = document.getElementById('PanelUI-zen-profiles-list');
this._emptyUserList(parentList);
console.log(ProfileService.profiles)
if (this._getProfilesSize(ProfileService.profiles) <= 1) {
return;
}
parentList.appendChild(document.createElement('toolbarseparator'));
for (let profile of ProfileService.profiles) {
if (profile == ProfileService.currentProfile) {
continue;
}
let item = document.createElement('menu');
item.onclick = () => this._openProfile(profile);
item.className = 'PanelUI-zen-profiles-item';
let avatar = document.createElement('img');
avatar.className = 'PanelUI-zen-profiles-item-avatar';
let name = document.createElement('div');
name.className = 'PanelUI-zen-profiles-item-name';
name.appendChild(document.createTextNode(profile.name));
name.container = true;
avatar.setAttribute('src', profile.zenAvatarPath);
item.appendChild(avatar);
item.appendChild(name);
parentList.appendChild(item);
}
},
_emptyUserList(element) {
element.innerHTML = '';
},
_updateCurentProfileId() {
let currentProfile = ProfileService.currentProfile;
let nameContainer = document.getElementById("PanelUI-zen-profiles-current-name");
nameContainer.textContent = currentProfile.name;
},
_openProfile(profile) {
Services.startup.createInstanceWithProfile(profile);
},
_getProfilesSize(profiles) {
let size = 0;
for (let _ of profiles) {
size += 1;
}
return size;
},
createProfileWizard() {
// This should be rewritten in HTML eventually.
window.browsingContext.topChromeWindow.openDialog(
"chrome://mozapps/content/profile/createProfileWizard.xhtml",
"",
"centerscreen,chrome,modal,titlebar",
ProfileService,
{ CreateProfile: async (profile) => {
try {
ProfileService.defaultProfile = profile;
this._flush();
} catch (e) {
// This can happen on dev-edition.
let [title, msg] = await document.l10n.formatValues([
{ id: "profiles-cannot-set-as-default-title" },
{ id: "profiles-cannot-set-as-default-message" },
]);
Services.prompt.alert(window, title, msg);
}
} }
);
},
async _flush() {
try {
ProfileService.flush();
this._updateProfilesList();
} catch (e) {
let [title, msg, button] = await document.l10n.formatValues([
{ id: "profiles-flush-fail-title" },
{
id:
e.result == Cr.NS_ERROR_DATABASE_CHANGED
? "profiles-flush-conflict"
: "profiles-flush-failed",
},
{ id: "profiles-flush-restart-button" },
]);
const PS = Ci.nsIPromptService;
let result = Services.prompt.confirmEx(
window,
title,
msg,
PS.BUTTON_POS_0 * PS.BUTTON_TITLE_CANCEL +
PS.BUTTON_POS_1 * PS.BUTTON_TITLE_IS_STRING,
null,
button,
null,
null,
{}
);
if (result == 1) {
this._restart(false);
}
}
},
_restart(safeMode) {
let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(
Ci.nsISupportsPRBool
);
Services.obs.notifyObservers(
cancelQuit,
"quit-application-requested",
"restart"
);
if (cancelQuit.data) {
return;
}
let flags = Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart;
if (safeMode) {
Services.startup.restartInSafeMode(flags);
} else {
Services.startup.quit(flags);
}
}
};

View File

@@ -1,6 +1,17 @@
<panelview id="PanelUI-zen-profiles" position="bottomleft topleft" side="right">
<vbox class="panel-subview-body">
<div id="PanelUI-zen-profiles-header"></div>
<div id="PanelUI-zen-profiles-user-picture" />
<vbox>
<html:div id="PanelUI-zen-profiles-header">
<html:div id="PanelUI-zen-profiles-user-picture"></html:div>
</html:div>
<vbox id="PanelUI-zen-profiles-current-info">
<label id="PanelUI-zen-profiles-current-name"></label>
<p id="PanelUI-zen-profiles-current-profile-current" data-l10n-id="zen-panel-ui-current-profile-text"></p>
</vbox>
<vbox id="PanelUI-zen-profiles-list">
</vbox>
<toolbarseparator />
<menuitem command="Tools:PrivateBrowsing" data-l10n-id="appmenuitem-new-private-window" class="PanelUI-zen-profiles-item"></menuitem>
<menuitem oncommand="alert('todo: open about:profiles!');" data-l10n-id="appmenuitem-new-zen-profiles-tab" class="PanelUI-zen-profiles-item"></menuitem>
<menuitem oncommand="ZenProfileDialogUI.createProfileWizard();" data-l10n-id="appmenuitem-new-zen-create-profile" class="PanelUI-zen-profiles-item"></menuitem>
</vbox>
</panelview>

View File

@@ -1,5 +1,8 @@
<toolbar id="zen-sidebar-icons-wrapper">
<toolbarbutton class="toolbarbutton-1 zen-sidebar-action-button" id="zen-profile-button" data-l10n-id="toolbar-button-account" onclick="PanelUI.showSubView('PanelUI-zen-profiles', this, event)"><div></div></toolbarbutton>
<toolbarbutton class="toolbarbutton-1 zen-sidebar-action-button" id="zen-profile-button" data-l10n-id="toolbar-button-account" onclick="ZenProfileDialogUI.showSubView(this, event)">
<html:div class="zen-side-bar-profiles-button-panel-correction"></html:div>
<html:div></html:div>
</toolbarbutton>
<toolbarbutton class="toolbarbutton-1 zen-sidebar-action-button" id="zen-bookmark-button" data-l10n-id="sidebar-menu-bookmarks" onclick="SidebarUI.show('viewBookmarksSidebar');"></toolbarbutton>
<toolbarbutton class="toolbarbutton-1 zen-sidebar-action-button" id="zen-history-button" data-l10n-id="sidebar-menu-history" onclick="SidebarUI.show('viewHistorySidebar');"></toolbarbutton>
<toolbarbutton class="toolbarbutton-1 zen-sidebar-action-button" id="zen-preferences-button" data-l10n-id="toolbar-settings-button" onclick="event.target.ownerGlobal.openPreferences(undefined);"></toolbarbutton>

View File

@@ -1,11 +1,11 @@
diff --git a/browser/base/jar.mn b/browser/base/jar.mn
index e3eb0e6e5f30152905456a07cfe532fe173375fb..15968304e9597e8bfc08cd03dc7615d1a5ff7f7f 100644
index e3eb0e6e5f30152905456a07cfe532fe173375fb..15e742e4cfd9df8eef815f80a4d668f118108c4c 100644
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -105,3 +105,5 @@ browser.jar:
@@ -105,3 +105,6 @@ browser.jar:
# L10n resources and overrides.
% override chrome://global/locale/appstrings.properties chrome://browser/locale/appstrings.properties
+
+#include content/zen-avatars/jar.inc.mn
\ No newline at end of file
+ content/browser/zen-browser-places.js (content/zen-browser-places.js)