Store the original state of the "Tabs on Top" for user's expectation correctly

This commit is contained in:
SHIMODA Hiroshi 2012-04-09 20:18:52 +09:00
parent b1b029686d
commit 7c6b3475ba
3 changed files with 53 additions and 32 deletions

View File

@ -585,7 +585,6 @@ pref("browser.link.open_newwindow.restriction.override", 0);
pref("browser.tabs.loadFolderAndReplace.override", false);
pref("browser.tabs.insertRelatedAfterCurrent.override", false);
pref("browser.tabs.insertRelatedAfterCurrent.override.force", true);
pref("extensions.treestyletab.tabsOnTopShouldBeRestored", false);
/**
* Extra commands for selected tabs (Multiple Tab Handler)

View File

@ -1498,15 +1498,22 @@ TreeStyleTabBrowser.prototype = {
// remove ordinal for "tabs on top" https://bugzilla.mozilla.org/show_bug.cgi?id=544815
if (this.position == 'top') {
this.removeTabStripAttribute('ordinal');
// Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=555987
// This should be done when the value of the "ordinal" attribute
// is modified dynamically. So, we don' have to do it before
// the browser window is completely initialized.
if (TabsOnTop && !this.windowService.isPopupWindow &&
this.windowService.initialized) {
TabsOnTop.enabled = !TabsOnTop.enabled;
let currentState = TabsOnTop.enabled;
let originalState = this.getTreePref('tabsOnTop.originalState');
if (originalState !== null &&
currentState != originalState &&
this.windowService.tabsOnTopChangingByUI &&
!this.windowService.changingTabsOnTop)
this.setTreePref('tabsOnTop.originalState', currentState);
// Workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=555987
// This should be done when the value of the "ordinal" attribute
// is modified dynamically. So, we don' have to do it before
// the browser window is completely initialized.
TabsOnTop.enabled = !currentState;
this.Deferred.next(function() {
TabsOnTop.enabled = !TabsOnTop.enabled;
TabsOnTop.enabled = currentState;
}).error(this.defaultDeferredErrorHandler);
}
}
@ -1525,10 +1532,7 @@ TreeStyleTabBrowser.prototype = {
if (TabsOnTop && !this.windowService.isPopupWindow) {
let updateTabsOnTop = function() {
let tabsWasOnTop = TabsOnTop.enabled;
TabsOnTop.enabled = TabsOnTop.enabled && self.position == 'top' && self.fixed;
if (tabsWasOnTop && !TabsOnTop.enabled)
self.setTreePref('tabsOnTopShouldBeRestored', true);
self.windowService.updateTabsOnTop();
};
// TabsOnTop.enabled is always "false" before the browser window is
// completely initialized. So, we have to check it with delay only
@ -4467,24 +4471,27 @@ TreeStyleTabBrowser.prototype = {
onTabsOnTopSyncCommand : function TSTBrowser_onTabsOnTopSyncCommand(aEnabled)
{
if (
this.windowService.tabsOnTopChangingByUI ||
!aEnabled ||
this.position != 'top' ||
this.fixed ||
!this.windowService.isPopupWindow
this.windowService.isPopupWindow
)
return;
this.windowService.tabsOnTopChangingByUI = true;
var self = this;
this.Deferred
.next(function() {
self.windowService.toggleFixed(self.mTabBrowser);
})
.next(function() {
if (self.window.TabsOnTop.enabled != aEnabled) {
dump('onTabsOnTopSyncCommand, set to '+aEnabled+'\n');
if (self.window.TabsOnTop.enabled != aEnabled)
self.window.TabsOnTop.enabled = aEnabled;
}
})
.error(this.defaultDeferredErrorHandler);
.error(this.defaultDeferredErrorHandler)
.next(function() {
self.windowService.tabsOnTopChangingByUI = false;
});
},
onTreeStyleTabPrintPreviewEntered : function TSTBrowser_onTreeStyleTabPrintPreviewEntered(aEvent)

View File

@ -387,8 +387,8 @@ TreeStyleTabWindow.prototype = {
namespace = void(0);
var self = this;
var restorePrefs = function() {
if (prefs.getPref('extensions.treestyletab.tabsOnTopShouldBeRestored')) {
prefs.clearPref('extensions.treestyletab.tabsOnTopShouldBeRestored');
if (prefs.getPref('extensions.treestyletab.tabsOnTop.originalState')) {
prefs.clearPref('extensions.treestyletab.tabsOnTop.originalState');
try {
self.browser.treeStyleTab.position = 'top';
}
@ -980,25 +980,40 @@ TreeStyleTabWindow.prototype = {
updateTabsOnTop : function TSTWindow_updateTabsOnTop()
{
var w = this.window;
if (this.isPopupWindow || !('TabsOnTop' in w) || !('enabled' in w.TabsOnTop))
if (
this.isPopupWindow ||
this.tabsOnTopChangingByUI ||
this.tabsOnTopChangingByTST ||
!('TabsOnTop' in w) ||
!('enabled' in w.TabsOnTop)
)
return;
var TabsOnTop = w.TabsOnTop;
if (!('_tabsOnTopDefaultState' in this))
this._tabsOnTopDefaultState = TabsOnTop.enabled;
this.tabsOnTopChangingByTST = true;
if (this.browser.treeStyleTab.position != 'top' ||
!this.browser.treeStyleTab.fixed) {
if (TabsOnTop.enabled) {
TabsOnTop.enabled = false;
this.setTreePref('tabsOnTopShouldBeRestored', true);
try {
var TabsOnTop = w.TabsOnTop;
var originalState = this.getTreePref('tabsOnTop.originalState');
if (originalState === null) {
let current = this.getDefaultPref('browser.tabs.onTop') === null ?
TabsOnTop.enabled :
this.getPref('browser.tabs.onTop') ;
this.setTreePref('tabsOnTop.originalState', originalState = current);
}
if (this.browser.treeStyleTab.position != 'top' ||
!this.browser.treeStyleTab.fixed) {
if (TabsOnTop.enabled)
TabsOnTop.enabled = false;
}
else {
if (TabsOnTop.enabled != originalState)
TabsOnTop.enabled = originalState;
this.clearTreePref('tabsOnTop.originalState');
}
}
else if ('_tabsOnTopDefaultState' in this) {
if (TabsOnTop.enabled!= this._tabsOnTopDefaultState)
TabsOnTop.enabled = this._tabsOnTopDefaultState;
delete this._tabsOnTopDefaultState;
this.setTreePref('tabsOnTopShouldBeRestored', false);
finally {
this.tabsOnTopChangingByTST = false;
}
},