Apply new pref value only for the topmost browser window smartly
This commit is contained in:
parent
fe39d5d6f3
commit
04b06ef084
@ -282,9 +282,11 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
|
||||
get expandedWidth()
|
||||
{
|
||||
var lastWidth = this.treeStyleTab.getWindowValue(this.kTABBAR_EXPANDED_WIDTH);
|
||||
return lastWidth === '' ?
|
||||
utils.getTreePref('tabbar.width') :
|
||||
parseInt(lastWidth);
|
||||
if (lastWidth === '') {
|
||||
lastWidth = utils.getTreePref('tabbar.width');
|
||||
this.treeStyleTab.setWindowValue(this.kTABBAR_EXPANDED_WIDTH, lastWidth);
|
||||
}
|
||||
return parseInt(lastWidth);
|
||||
},
|
||||
set expandedWidth(aValue)
|
||||
{
|
||||
@ -297,17 +299,17 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
|
||||
aValue = newWidth.expanded;
|
||||
}
|
||||
this.treeStyleTab.setWindowValue(this.kTABBAR_EXPANDED_WIDTH, aValue);
|
||||
this.treeStyleTab.setPrefForActiveWindow(function() {
|
||||
utils.setTreePref('tabbar.width', aValue);
|
||||
});
|
||||
utils.setTreePref('tabbar.width', aValue);
|
||||
return aValue;
|
||||
},
|
||||
get shrunkenWidth()
|
||||
{
|
||||
var lastWidth = this.treeStyleTab.getWindowValue(this.kTABBAR_SHRUNKEN_WIDTH);
|
||||
return lastWidth === '' ?
|
||||
utils.getTreePref('tabbar.shrunkenWidth') :
|
||||
parseInt(lastWidth);
|
||||
if (lastWidth === '') {
|
||||
lastWidth = utils.getTreePref('tabbar.shrunkenWidth');
|
||||
this.treeStyleTab.setWindowValue(this.kTABBAR_SHRUNKEN_WIDTH, lastWidth);
|
||||
}
|
||||
return parseInt(lastWidth);
|
||||
},
|
||||
set shrunkenWidth(aValue)
|
||||
{
|
||||
@ -320,9 +322,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
|
||||
aValue = newWidth.shrunken;
|
||||
}
|
||||
this.treeStyleTab.setWindowValue(this.kTABBAR_SHRUNKEN_WIDTH, aValue);
|
||||
this.treeStyleTab.setPrefForActiveWindow(function() {
|
||||
utils.setTreePref('tabbar.shrunkenWidth', aValue);
|
||||
});
|
||||
utils.setTreePref('tabbar.shrunkenWidth', aValue);
|
||||
return aValue;
|
||||
},
|
||||
|
||||
@ -1092,14 +1092,14 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
|
||||
switch (aPrefName)
|
||||
{
|
||||
case 'extensions.treestyletab.tabbar.autoHide.mode':
|
||||
if (!this.window.TreeStyleTabService.shouldApplyNewPref)
|
||||
if (!this.window.TreeStyleTabService.shouldApplyNewPref('tabbar.autoHide.mode'))
|
||||
return;
|
||||
this.browser.setAttribute(this.kMODE+'-normal', value);
|
||||
this.updateMode(value);
|
||||
return;
|
||||
|
||||
case 'extensions.treestyletab.tabbar.autoHide.mode.fullscreen':
|
||||
if (!this.window.TreeStyleTabService.shouldApplyNewPref)
|
||||
if (!this.window.TreeStyleTabService.shouldApplyNewPref('tabbar.autoHide.mode.fullscreen'))
|
||||
return;
|
||||
this.browser.setAttribute(this.kMODE+'-fullscreen', value);
|
||||
this.updateMode(value);
|
||||
@ -1496,11 +1496,9 @@ AutoHideWindow.prototype = inherit(AutoHideBase.prototype, {
|
||||
utils.getTreePref(toggleKey) :
|
||||
AutoHideBrowser.prototype.kMODE_DISABLED ;
|
||||
|
||||
this.treeStyleTab.setPrefForActiveWindow(function() {
|
||||
utils.setTreePref(key, mode);
|
||||
b.setAttribute(AutoHideBrowser.prototype.kMODE+'-'+(w.fullScreen ? 'fullscreen' : 'normal' ), mode);
|
||||
b.treeStyleTab.autoHide.updateMode(mode);
|
||||
});
|
||||
utils.setTreePref(key, mode);
|
||||
b.setAttribute(AutoHideBrowser.prototype.kMODE+'-'+(w.fullScreen ? 'fullscreen' : 'normal' ), mode);
|
||||
b.treeStyleTab.autoHide.updateMode(mode);
|
||||
},
|
||||
|
||||
initMode : function AHW_initMode()
|
||||
|
@ -2538,24 +2538,13 @@ var TreeStyleTabBase = inherit(TreeStyleTabConstants, {
|
||||
return size;
|
||||
},
|
||||
|
||||
get shouldApplyNewPref()
|
||||
shouldApplyNewPref : function TSTBase_shouldApplyNewPref(aKey)
|
||||
{
|
||||
return (
|
||||
!this.applyOnlyForActiveWindow ||
|
||||
this.window == this.topBrowserWindow
|
||||
) &&
|
||||
!this.inWindowDestoructionProcess;
|
||||
},
|
||||
|
||||
applyOnlyForActiveWindow : false,
|
||||
setPrefForActiveWindow : function TSTBase_setPrefForActiveWindow(aTask) {
|
||||
TreeStyleTabBase.applyOnlyForActiveWindow = true;
|
||||
try {
|
||||
aTask.call(this);
|
||||
}
|
||||
finally {
|
||||
TreeStyleTabBase.applyOnlyForActiveWindow = false;
|
||||
}
|
||||
!utils.isTreePrefChanging(aKey) &&
|
||||
this.window == this.topBrowserWindow &&
|
||||
!this.inWindowDestoructionProcess
|
||||
);
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -214,9 +214,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
set tabbarWidth(aValue)
|
||||
{
|
||||
this.setWindowValue(this.kTABBAR_WIDTH, aValue);
|
||||
this.setPrefForActiveWindow(function() {
|
||||
utils.setTreePref('tabbar.width', aValue);
|
||||
});
|
||||
utils.setTreePref('tabbar.width', aValue);
|
||||
return aValue;
|
||||
},
|
||||
*/
|
||||
@ -231,9 +229,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
set tabbarHeight(aValue)
|
||||
{
|
||||
this.setWindowValue(this.kTABBAR_HEIGHT, aValue);
|
||||
this.setPrefForActiveWindow(function() {
|
||||
utils.setTreePref('tabbar.height', aValue);
|
||||
});
|
||||
utils.setTreePref('tabbar.height', aValue);
|
||||
return aValue;
|
||||
},
|
||||
|
||||
@ -756,20 +752,16 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
let width = this.tabbarWidth;
|
||||
let minWidth = Math.max(this.MIN_TABBAR_WIDTH, this.scrollBox.boxObject.width);
|
||||
if (minWidth > width) {
|
||||
this.setPrefForActiveWindow((function() {
|
||||
this.tabbarWidth = minWidth;
|
||||
this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE);
|
||||
}).bind(this));
|
||||
this.tabbarWidth = minWidth;
|
||||
this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
let height = this.tabbarHeight;
|
||||
let minHeight = Math.max(this.MIN_TABBAR_HEIGHT, this.scrollBox.boxObject.height);
|
||||
if (minHeight > height) {
|
||||
this.setPrefForActiveWindow((function() {
|
||||
this.tabbarHeight = minHeight;
|
||||
this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE);
|
||||
}).bind(this));
|
||||
this.tabbarHeight = minHeight;
|
||||
this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -1372,9 +1364,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
if (!aIsTemporaryChange) {
|
||||
let positionName = this.normalizeTabbarPosition(pos);
|
||||
this.setWindowValue(this.kTABBAR_POSITION, positionName);
|
||||
this.setPrefForActiveWindow(function() {
|
||||
utils.setTreePref('tabbar.position', positionName);
|
||||
});
|
||||
utils.setTreePref('tabbar.position', positionName);
|
||||
}
|
||||
|
||||
aOldPosition = aOldPosition || pos;
|
||||
@ -2607,7 +2597,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
switch (aPrefName)
|
||||
{
|
||||
case 'extensions.treestyletab.tabbar.position':
|
||||
if (this.shouldApplyNewPref)
|
||||
if (this.shouldApplyNewPref('tabbar.position'))
|
||||
this.position = value;
|
||||
return;
|
||||
|
||||
@ -2649,7 +2639,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
return this.setTabbrowserAttribute(this.kFIRSTTAB_BORDER, value);
|
||||
|
||||
case 'extensions.treestyletab.tabbar.fixed.horizontal':
|
||||
if (!this.shouldApplyNewPref)
|
||||
if (!this.shouldApplyNewPref('tabbar.fixed.horizontal'))
|
||||
return;
|
||||
this.setTabbrowserAttribute(this.kFIXED+'-horizontal', value ? 'true' : null, b);
|
||||
case 'extensions.treestyletab.maxTreeLevel.horizontal':
|
||||
@ -2659,7 +2649,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
return;
|
||||
|
||||
case 'extensions.treestyletab.tabbar.fixed.vertical':
|
||||
if (!this.shouldApplyNewPref)
|
||||
if (!this.shouldApplyNewPref('tabbar.fixed.vertical'))
|
||||
return;
|
||||
this.setTabbrowserAttribute(this.kFIXED+'-vertical', value ? 'true' : null, b);
|
||||
case 'extensions.treestyletab.maxTreeLevel.vertical':
|
||||
@ -2670,10 +2660,11 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
|
||||
case 'extensions.treestyletab.tabbar.width':
|
||||
case 'extensions.treestyletab.tabbar.shrunkenWidth':
|
||||
if (!this.shouldApplyNewPref)
|
||||
if (!this.shouldApplyNewPref('tabbar.width'))
|
||||
return;
|
||||
if (!this.autoHide.isResizing && this.isVertical) {
|
||||
this.removeTabStripAttribute('width');
|
||||
this.tabbarWidth = value;
|
||||
this.setTabStripAttribute('width', this.autoHide.placeHolderWidthFromMode);
|
||||
this.updateFloatingTabbar(this.kTABBAR_UPDATE_BY_PREF_CHANGE);
|
||||
}
|
||||
@ -2681,9 +2672,10 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
|
||||
return;
|
||||
|
||||
case 'extensions.treestyletab.tabbar.height':
|
||||
if (!this.shouldApplyNewPref)
|
||||
if (!this.shouldApplyNewPref('tabbar.height'))
|
||||
return;
|
||||
this._horizontalTabMaxIndentBase = 0;
|
||||
this.tabbarHeight = value;
|
||||
this.checkTabsIndentOverflow();
|
||||
return;
|
||||
|
||||
|
@ -43,6 +43,7 @@ const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import('resource://gre/modules/Timer.jsm');
|
||||
Cu.import('resource://treestyletab-modules/constants.js');
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, 'window', function() {
|
||||
@ -82,11 +83,15 @@ let TreeStyleTabUtils = {
|
||||
|
||||
setTreePref : function TSTUtils_setTreePref(aPrefstring, aNewValue)
|
||||
{
|
||||
if (this.isPrefChanging(aPrefstring))
|
||||
return aNewValue;
|
||||
return prefs.setPref(TST_PREF_PREFIX + aPrefstring, aNewValue);
|
||||
},
|
||||
|
||||
clearTreePref : function TSTUtils_clearTreePref(aPrefstring)
|
||||
{
|
||||
if (this.isPrefChanging(aPrefstring))
|
||||
return null;
|
||||
return prefs.clearPref(TST_PREF_PREFIX + aPrefstring);
|
||||
},
|
||||
|
||||
@ -332,5 +337,41 @@ let TreeStyleTabUtils = {
|
||||
return source.indexOf(aMatcher) > -1;
|
||||
else
|
||||
return aMatcher.test(source);
|
||||
},
|
||||
|
||||
isPrefChanging : function utils_isPrefChanging(aKey)
|
||||
{
|
||||
return aKey in this.changingPrefs;
|
||||
},
|
||||
isTreePrefChanging : function utils_isPrefChanging(aKey)
|
||||
{
|
||||
return (TST_PREF_PREFIX + aKey) in this.changingPrefs ||
|
||||
this.isPrefChanging(aKey);
|
||||
},
|
||||
|
||||
/* Pref Listener */
|
||||
domains : [
|
||||
'extensions.treestyletab.'
|
||||
],
|
||||
|
||||
observe : function utils_observe(aSubject, aTopic, aData)
|
||||
{
|
||||
switch (aTopic)
|
||||
{
|
||||
case 'nsPref:changed':
|
||||
this.onPrefChange(aData);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
||||
changingPrefs : {},
|
||||
onPrefChange : function utils_onPrefChange(aPrefName)
|
||||
{
|
||||
this.changingPrefs[aPrefName] = true;
|
||||
setTimeout((function() {
|
||||
delete this.changingPrefs[aPrefName];
|
||||
}).bind(this));
|
||||
}
|
||||
};
|
||||
|
||||
prefs.addPrefListener(TreeStyleTabUtils);
|
||||
|
@ -109,12 +109,10 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
|
||||
set position(aValue)
|
||||
{
|
||||
var setPosition = (function() {
|
||||
this.setPrefForActiveWindow((function() {
|
||||
if (this.preInitialized && this.browser.treeStyleTab)
|
||||
this.browser.treeStyleTab.position = aValue;
|
||||
else
|
||||
this.base.position = aValue;
|
||||
}).bind(this));
|
||||
if (this.preInitialized && this.browser.treeStyleTab)
|
||||
this.browser.treeStyleTab.position = aValue;
|
||||
else
|
||||
this.base.position = aValue;
|
||||
}).bind(this);
|
||||
|
||||
if ('UndoTabService' in this.window && this.window.UndoTabService.isUndoable()) {
|
||||
@ -1374,10 +1372,8 @@ TreeStyleTabWindow.prototype = inherit(TreeStyleTabBase, {
|
||||
|
||||
var newFixed = b.getAttribute(this.kFIXED+'-'+orient) != 'true';
|
||||
this.setTabbrowserAttribute(this.kFIXED+'-'+orient, newFixed || null, b);
|
||||
this.setPrefForActiveWindow(function() {
|
||||
b.treeStyleTab.fixed = newFixed;
|
||||
utils.setTreePref('tabbar.fixed.'+orient, newFixed);
|
||||
});
|
||||
b.treeStyleTab.fixed = newFixed;
|
||||
utils.setTreePref('tabbar.fixed.'+orient, newFixed);
|
||||
|
||||
b.treeStyleTab.updateTabbarState();
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user