Skip to content

Commit

Permalink
Fix problems with header toolbar:
Browse files Browse the repository at this point in the history
- only fill palette once after window opens
- only set header toolbar buttons to defaults after installation of
addon
- call fillToolboxPalette more often to make sure, palette is correctly
initalized
- new way to make sure, load event listener is really called
  • Loading branch information
jmozmoz committed Aug 15, 2019
1 parent f3252ab commit ca28c65
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
25 changes: 20 additions & 5 deletions chrome/CompactHeader/content/compactHeaderOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,18 @@ org_mozdev_compactHeader.pane = function() {

org_mozdev_compactHeader.debug.log("coheOnLoadMsgHeaderPane 2");

org_mozdev_compactHeader.messenger.loadToolboxData();
org_mozdev_compactHeader.toolbar.fillToolboxPalette();
org_mozdev_compactHeader.messenger.saveToolboxData();

if (coheFirstTime)
{
org_mozdev_compactHeader.debug.log("coheFirstTime start");
coheFirstTime = false;
gMessageListeners.push(coheMessageListener);
org_mozdev_compactHeader.messenger.loadToolboxData();
org_mozdev_compactHeader.toolbar.fillToolboxPalette();
org_mozdev_compactHeader.messenger.saveToolboxData();
// org_mozdev_compactHeader.messenger.loadToolboxData();
// org_mozdev_compactHeader.toolbar.fillToolboxPalette();
// org_mozdev_compactHeader.messenger.saveToolboxData();

org_mozdev_compactHeader.debug.log("coheFirstTime 1");

Expand Down Expand Up @@ -595,7 +599,10 @@ org_mozdev_compactHeader.pane = function() {
selectEmailDisplayed();
}

//org_mozdev_compactHeader.toolbar.fillToolboxPalette(document);
// org_mozdev_compactHeader.messenger.loadToolboxData();
// org_mozdev_compactHeader.toolbar.fillToolboxPalette();
// org_mozdev_compactHeader.messenger.saveToolboxData();

coheToggleHeaderContent();
org_mozdev_compactHeader.toolbar.CHTUpdateReplyButton();
org_mozdev_compactHeader.toolbar.CHTUpdateJunkButton();
Expand Down Expand Up @@ -1245,7 +1252,15 @@ org_mozdev_compactHeader.pane = function() {
return pub;
}();

addEventListener('messagepane-loaded', org_mozdev_compactHeader.pane.coheOnLoadMsgHeaderPane, true);
// https://hg.mozilla.org/comm-central/rev/e1b29b3607c4#l1.13
if (document.getElementById("msgHeaderView").loaded) {
org_mozdev_compactHeader.debug.log("firstRun: messagepane-loaded was already issued");
org_mozdev_compactHeader.pane.coheOnLoadMsgHeaderPane();
}
else {
addEventListener('messagepane-loaded', org_mozdev_compactHeader.pane.coheOnLoadMsgHeaderPane, true);
}

addEventListener('messagepane-unloaded', org_mozdev_compactHeader.pane.coheOnUnloadMsgHeaderPane, true);
addEventListener('load', org_mozdev_compactHeader.pane.coheInitializeOverlay, false);

Expand Down
63 changes: 52 additions & 11 deletions chrome/CompactHeader/content/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ if (typeof org_mozdev_compactHeader == "undefined") {
org_mozdev_compactHeader.toolbar = function() {
var pub = {};

var filledPalette = false;

var cohePrefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch("extensions.CompactHeader.");
Expand Down Expand Up @@ -87,19 +89,8 @@ org_mozdev_compactHeader.toolbar = function() {
}
}

pub.cannotMoveToolbox = function() {
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
.getService(Components.interfaces.nsIXULAppInfo);
var versionChecker = Components.classes["@mozilla.org/xpcom/version-comparator;1"]
.getService(Components.interfaces.nsIVersionComparator);
return (versionChecker.compare(appInfo.version, "10.0a2") < 0)
};

function getToolbarTarget(targetPos, targetHeader) {
//targetPos = targetPos.replace('hdrToolbox.pos.', '');
if (pub.cannotMoveToolbox()) {
targetPos = "top";
}
for (let i = 0; i < gToolboxes.length; i++) {
if ((targetPos == gToolboxes[i].pos) &&
((gToolboxes[i].header == null) || (targetHeader == gToolboxes[i].header))
Expand All @@ -119,6 +110,19 @@ org_mozdev_compactHeader.toolbar = function() {
removeButtonDispMUA();
var hdrToolbar = document.getElementById("header-view-toolbar");
var hdrToolbox = document.getElementById("header-view-toolbox");

if (!hdrToolbox || !hdrToolbox.palette) {
org_mozdev_compactHeader.debug.log("no header-view-toolbox or palette!",
org_mozdev_compactHeader.debug.LOGLEVEL.warn);
return;
}

if (filledPalette) {
return;
}

filledPalette = true;

var buttons = ["button-reply", "button-replyall", "button-replylist",
"button-tag", "button-forward", "button-archive", "button-file",
"button-print", "button-mark", "CompactHeader_button-starMessages",
Expand Down Expand Up @@ -151,6 +155,8 @@ org_mozdev_compactHeader.toolbar = function() {
button = document.getElementById(buttonName);
}
if (button) {
org_mozdev_compactHeader.debug.log("fillToolboxPalette add button: " +
button.id);
var hdrButton = button.cloneNode(true);
if (hdrButton) {
if (hdrButton.localName == "toolbaritem") {
Expand All @@ -171,6 +177,9 @@ org_mozdev_compactHeader.toolbar = function() {
if (hdrToolbox && hdrToolbox.palette) {
hdrToolbox.palette.appendChild(hdrButton);
}
else {
org_mozdev_compactHeader.debug.log("fillToolboxPalette: did not find header palette");
}
/* var bStyle = document.defaultView.getComputedStyle(button, null);
hdrButton.style.listStyleImage = bStyle.listStyleImage;*/
}
Expand All @@ -182,6 +191,10 @@ org_mozdev_compactHeader.toolbar = function() {
hdrToolbar.currentSet = currentSet;
}
}
else {
org_mozdev_compactHeader.debug.log("fillToolboxPalette cannot add button: " +
buttonName);
}
org_mozdev_compactHeader.debug.log("fillToolboxPalette stop");
};

Expand Down Expand Up @@ -218,6 +231,9 @@ org_mozdev_compactHeader.toolbar = function() {
if (hdrToolbox && hdrToolbox.palette) {
buttons2 = Array.prototype.slice.call(hdrToolbox.palette.querySelectorAll("toolbarbutton"));
}
else {
org_mozdev_compactHeader.debug.log("setButtonStyle: did not find header palette");
}
var buttons = buttons1.concat(buttons2);
for (var i=0; i<buttons.length; i++) {
var button = buttons[i];
Expand Down Expand Up @@ -254,6 +270,9 @@ org_mozdev_compactHeader.toolbar = function() {
if (hdrToolbox && hdrToolbox.palette) {
buttons2 = Array.prototype.slice.call(hdrToolbox.palette.querySelectorAll("toolbaritem"));
}
else {
org_mozdev_compactHeader.debug.log("setButtonStyle did not find header palette");
}

var buttons = buttons1.concat(buttons2);
for (var i=0; i<buttons.length; i++) {
Expand Down Expand Up @@ -459,6 +478,7 @@ org_mozdev_compactHeader.toolbar = function() {
button1.parentNode.removeChild(button1);
}
}

var headerViewToolbox = document.getElementById("header-view-toolbox");
if (headerViewToolbox && headerViewToolbox.palette) {
var button2 = headerViewToolbox.palette.
Expand Down Expand Up @@ -502,6 +522,19 @@ org_mozdev_compactHeader.toolbar = function() {
pub.CHTSetDefaultButtons = function () {
var hdrToolbox = document.getElementById("header-view-toolbox");
var hdrToolbar = document.getElementById("header-view-toolbar");

if (!hdrToolbox) {
org_mozdev_compactHeader.debug.log("CHTSetDefaultButtons: no header toolbox!");
return;
}

if (hdrToolbar.hasAttribute("compactHeaderModified") &&
hdrToolbar.getAttribute("compactHeaderModified") == "true") {
org_mozdev_compactHeader.debug.log(
"CHTSetDefaultButtons: do not set default values, because it was already done once"
);
return;
}
var hdrBarDefaultSet = hdrToolbar.getAttribute("defaultset");
var hdrBoxDefaultLabelalign = hdrToolbox.getAttribute("defaultlabelalign");
var hdrBoxDefaultIconsize = hdrToolbox.getAttribute("defaulticonsize");
Expand All @@ -514,6 +547,7 @@ org_mozdev_compactHeader.toolbar = function() {
hdrToolbox.setAttribute("mode", hdrBoxDefaultMode);
hdrToolbar.setAttribute("iconsize", hdrBarDefaultIconsize);
hdrToolbar.setAttribute("mode", hdrBarDefaultMode);
hdrToolbar.setAttribute("compactHeaderModified", "true");

hdrToolbar.currentSet = hdrBarDefaultSet;
hdrToolbar.setAttribute("currentset", hdrBarDefaultSet);
Expand All @@ -524,8 +558,13 @@ org_mozdev_compactHeader.toolbar = function() {
myPersist(hdrToolbar,"iconsize");
myPersist(hdrToolbar,"mode");
myPersist(hdrToolbar,"currentset");
myPersist(hdrToolbar,"compactHeaderModified");
};

/*
* Cleanup header toolbar to the default set when uninstalling
* this addon
*/
pub.CHTCleanupButtons = function() {
var hdrToolbox = document.getElementById("header-view-toolbox");
var hdrToolbar = document.getElementById("header-view-toolbar");
Expand All @@ -539,13 +578,15 @@ org_mozdev_compactHeader.toolbar = function() {
hdrToolbar.setAttribute("mode", "full");
hdrToolbar.currentSet = hdrBarDefaultSet;
hdrToolbar.setAttribute("currentset", hdrBarDefaultSet);
hdrToolbar.removeAttribute("compactHeaderModified");

myPersist(hdrToolbox,"labelalign");
myPersist(hdrToolbox,"iconsize");
myPersist(hdrToolbox,"mode");
myPersist(hdrToolbar,"iconsize");
myPersist(hdrToolbar,"mode");
myPersist(hdrToolbar,"currentset");
myPersist(hdrToolbar,"compactHeaderModified");
};

pub.populateEmptyToolbar = function() {
Expand Down

0 comments on commit ca28c65

Please sign in to comment.