simplify implementation of "fast restore"
This commit is contained in:
parent
2783f4f3b3
commit
828e6e48f9
@ -1743,8 +1743,6 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
|
|
||||||
destroy : function TSTBrowser_destroy()
|
destroy : function TSTBrowser_destroy()
|
||||||
{
|
{
|
||||||
this.saveTreeStructure();
|
|
||||||
|
|
||||||
this.animationManager.removeTask(this.smoothScrollTask);
|
this.animationManager.removeTask(this.smoothScrollTask);
|
||||||
|
|
||||||
this.autoHide.destroy();
|
this.autoHide.destroy();
|
||||||
@ -2205,10 +2203,6 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
case 'extensions.treestyletab.pinnedTab.faviconized':
|
case 'extensions.treestyletab.pinnedTab.faviconized':
|
||||||
return this.positionPinnedTabsWithDelay();
|
return this.positionPinnedTabsWithDelay();
|
||||||
|
|
||||||
case 'extensions.treestyletab.restoreTreeOnStartup':
|
|
||||||
if (value) this.saveTreeStructureWithDelay();
|
|
||||||
return;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2283,121 +2277,42 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
|
|
||||||
onWindowStateRestored : function TSTBrowser_onWindowStateRestored()
|
onWindowStateRestored : function TSTBrowser_onWindowStateRestored()
|
||||||
{
|
{
|
||||||
if (!this.window.__SS_tabsToRestore)
|
if (this.window.__SS_tabsToRestore) {
|
||||||
return;
|
if (!this.windowStateRestored &&
|
||||||
|
this.getTreePref('restoreTreeOnStartup'))
|
||||||
if (!this.windowStateRestored) {
|
this.restoreTreeStructure();
|
||||||
if (this.getTreePref('restoreTreeOnStartup'))
|
|
||||||
this.restoreTreeStructure(this.windowService.storedTreeStructure);
|
|
||||||
this.windowStateRestored = true;
|
|
||||||
}
|
}
|
||||||
|
this.windowStateRestored = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
getTreeStructure : function TSTBrowser_getTreeStructure(aBaseStructure)
|
restoreTreeStructure : function TSTBrowser_restoreTreeStructure()
|
||||||
{
|
{
|
||||||
aBaseStructure = aBaseStructure || {};
|
|
||||||
var id = this.mTabBrowser.getAttribute('id');
|
|
||||||
var tabs = this.getAllTabsArray(this.mTabBrowser);
|
var tabs = this.getAllTabsArray(this.mTabBrowser);
|
||||||
aBaseStructure[id] = {
|
tabs.reverse().forEach(function(aTab) {
|
||||||
tree : this.getTreeStructureFromTabs(tabs),
|
var id = this.getTabValue(aTab, this.kID);
|
||||||
state : tabs.map(function(aTab) {
|
if (!id)
|
||||||
var state = { id : this.getTabValue(aTab, this.kID) };
|
|
||||||
if (this.isCollapsed(aTab))
|
|
||||||
state.collapsed = true;
|
|
||||||
if (this.isSubtreeCollapsed(aTab))
|
|
||||||
state.subTreeCollapsed = true;
|
|
||||||
return state;
|
|
||||||
}, this)
|
|
||||||
};
|
|
||||||
return aBaseStructure;
|
|
||||||
},
|
|
||||||
|
|
||||||
saveTreeStructureWithDelay : function TSTBrowser_saveTreeStructureWithDelay()
|
|
||||||
{
|
|
||||||
if (this.restoringTree || this.saveTreeStructureWithDelayTimer)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this.saveTreeStructureWithDelayTimer = this.window.setTimeout(function(aSelf) {
|
|
||||||
aSelf.saveTreeStructureWithDelayTimer = null;
|
|
||||||
aSelf.saveTreeStructure();
|
|
||||||
}, this.getPref('browser.sessionstore.interval'), this);
|
|
||||||
},
|
|
||||||
saveTreeStructureWithDelayTimer : null,
|
|
||||||
saveTreeStructure : function TSTBrowser_saveTreeStructure()
|
|
||||||
{
|
|
||||||
if (!this.getTreePref('restoreTreeOnStartup'))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var treeStructures = this.windowService.storedTreeStructure;
|
|
||||||
treeStructures = this.getTreeStructure(treeStructures);
|
|
||||||
this.SessionStore.setWindowValue(this.window, this.kSTRUCTURE, JSON.stringify(treeStructures))
|
|
||||||
},
|
|
||||||
|
|
||||||
restoreTreeStructure : function TSTBrowser_restoreTreeStructure(aStructures)
|
|
||||||
{
|
|
||||||
if (!aStructures)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var id = this.mTabBrowser.getAttribute('id');
|
|
||||||
var treeStructure = id in aStructures ? aStructures[id] : null ;
|
|
||||||
if (
|
|
||||||
!treeStructure ||
|
|
||||||
!treeStructure.state ||
|
|
||||||
!treeStructure.state.length ||
|
|
||||||
!treeStructure.tree ||
|
|
||||||
!treeStructure.tree.length ||
|
|
||||||
treeStructure.state.length != treeStructure.tree.length
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var tabs = this.getAllTabsArray(this.mTabBrowser);
|
|
||||||
|
|
||||||
// on Firefox 3.6, we cannot get tab values before SSTabRestoring...
|
|
||||||
var actualTabs = tabs.map(function(aTab) {
|
|
||||||
return this.getTabValue(aTab, this.kID);
|
|
||||||
}, this).join('\n')+'\n';
|
|
||||||
var restoringTabs = treeStructure.state.map(function(aState) {
|
|
||||||
return aState.id;
|
|
||||||
}).join('\n')+'\n';
|
|
||||||
if (actualTabs.indexOf(restoringTabs) < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var preTabs = actualTabs
|
|
||||||
.split(restoringTabs)[0]
|
|
||||||
.replace(/\n$/, '')
|
|
||||||
.split('\n')
|
|
||||||
.filter(function(aId) { return aId; })
|
|
||||||
.length;
|
|
||||||
tabs = tabs.slice(preTabs, preTabs + treeStructure.tree.length);
|
|
||||||
|
|
||||||
var relations = tabs.map(function(aTab) {
|
|
||||||
return {
|
|
||||||
id : this.getTabValue(aTab, this.kID),
|
|
||||||
parent : this.getTabValue(aTab, this.kPARENT),
|
|
||||||
children : this.getTabValue(aTab, this.kCHILDREN),
|
|
||||||
insertBefore : this.getTabValue(aTab, this.kINSERT_BEFORE),
|
|
||||||
insertAfter : this.getTabValue(aTab, this.kINSERT_AFTER)
|
|
||||||
};
|
|
||||||
}, this);
|
|
||||||
|
|
||||||
this.applyTreeStructureToTabs(tabs, treeStructure.tree, true);
|
|
||||||
|
|
||||||
tabs.forEach(function(aTab, aIndex) {
|
|
||||||
var relation = relations[aIndex];
|
|
||||||
if (!relation.id)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.tabsHash[relation.id] = aTab;
|
this.setTabValue(aTab, this.kID, id);
|
||||||
|
this.tabsHash[id] = aTab;
|
||||||
|
|
||||||
var state = treeStructure.state[aIndex];
|
var collapsed = this.getTabValue(aTab, this.kCOLLAPSED) == 'true';
|
||||||
this.setTabValue(aTab, this.kSUBTREE_COLLAPSED, state.subTreeCollapsed || null);
|
var subTreeCollapsed = this.getTabValue(aTab, this.kSUBTREE_COLLAPSED) == 'true';
|
||||||
this.collapseExpandTab(aTab, state.collapsed || false, true);
|
var children = this.getTabValue(aTab, this.kCHILDREN);
|
||||||
|
if (!children)
|
||||||
|
return;
|
||||||
|
|
||||||
this.setTabValue(aTab, this.kID, relation.id);
|
children.split('|').forEach(function(aChild) {
|
||||||
this.setTabValue(aTab, this.kPARENT, relation.parent);
|
aChild = this.getTabById(aChild);
|
||||||
this.setTabValue(aTab, this.kCHILDREN, relation.children);
|
if (aChild)
|
||||||
this.setTabValue(aTab, this.kINSERT_BEFORE, relation.insertBefore);
|
this.attachTabTo(aChild, aTab, {
|
||||||
this.setTabValue(aTab, this.kINSERT_AFTER, relation.insertAfter);
|
forceExpand : true // to prevent to collapse the selected tab
|
||||||
|
});
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
this.collapseExpandSubtree(aTab, subTreeCollapsed, true);
|
||||||
|
this.collapseExpandTab(aTab, collapsed, true);
|
||||||
|
this.updateInsertionPositionInfo(aTab);
|
||||||
|
|
||||||
aTab.__treestyletab__structureRestored = true;
|
aTab.__treestyletab__structureRestored = true;
|
||||||
}, this);
|
}, this);
|
||||||
@ -2645,17 +2560,7 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
this.updateTabCollapsed(tab, false, this.restoringTree);
|
this.updateTabCollapsed(tab, false, this.restoringTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
var prev = this.getPreviousSiblingTab(tab);
|
this.updateInsertionPositionInfo(tab);
|
||||||
if (prev) {
|
|
||||||
this.setTabValue(tab, this.kINSERT_AFTER, prev.getAttribute(this.kID));
|
|
||||||
this.setTabValue(prev, this.kINSERT_BEFORE, tab.getAttribute(this.kID));
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = this.getNextSiblingTab(tab);
|
|
||||||
if (next) {
|
|
||||||
this.setTabValue(tab, this.kINSERT_BEFORE, next.getAttribute(this.kID));
|
|
||||||
this.setTabValue(next, this.kINSERT_AFTER, tab.getAttribute(this.kID));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.scrollToNewTabMode > 0)
|
if (this.scrollToNewTabMode > 0)
|
||||||
this.scrollToTab(tab, this.scrollToNewTabMode < 2);
|
this.scrollToTab(tab, this.scrollToNewTabMode < 2);
|
||||||
@ -2682,14 +2587,27 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
*/
|
*/
|
||||||
b._lastRelatedTab = lastRelatedTab;
|
b._lastRelatedTab = lastRelatedTab;
|
||||||
|
|
||||||
this.saveTreeStructureWithDelay();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
_addedCountInThisLoop : 0,
|
_addedCountInThisLoop : 0,
|
||||||
_addedCountClearTimer : null,
|
_addedCountClearTimer : null,
|
||||||
_checkRestoringWindowTimerOnTabAdded : null,
|
_checkRestoringWindowTimerOnTabAdded : null,
|
||||||
|
|
||||||
|
updateInsertionPositionInfo : function TSTBrowser_updateInsertionPositionInfo(aTab)
|
||||||
|
{
|
||||||
|
var prev = this.getPreviousSiblingTab(aTab);
|
||||||
|
if (prev) {
|
||||||
|
this.setTabValue(aTab, this.kINSERT_AFTER, prev.getAttribute(this.kID));
|
||||||
|
this.setTabValue(prev, this.kINSERT_BEFORE, aTab.getAttribute(this.kID));
|
||||||
|
}
|
||||||
|
|
||||||
|
var next = this.getNextSiblingTab(aTab);
|
||||||
|
if (next) {
|
||||||
|
this.setTabValue(aTab, this.kINSERT_BEFORE, next.getAttribute(this.kID));
|
||||||
|
this.setTabValue(next, this.kINSERT_AFTER, aTab.getAttribute(this.kID));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onTabRemoved : function TSTBrowser_onTabRemoved(aEvent)
|
onTabRemoved : function TSTBrowser_onTabRemoved(aEvent)
|
||||||
{
|
{
|
||||||
var tab = aEvent.originalTarget;
|
var tab = aEvent.originalTarget;
|
||||||
@ -2869,8 +2787,6 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
|
|
||||||
if (collapsed)
|
if (collapsed)
|
||||||
this.startRendering();
|
this.startRendering();
|
||||||
|
|
||||||
this.saveTreeStructureWithDelay();
|
|
||||||
},
|
},
|
||||||
_reserveCloseNeedlessGroupTabSibling : function TSTBrowser_reserveCloseNeedlessGroupTabSibling(aTab)
|
_reserveCloseNeedlessGroupTabSibling : function TSTBrowser_reserveCloseNeedlessGroupTabSibling(aTab)
|
||||||
{
|
{
|
||||||
@ -2996,8 +2912,6 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
if (this.canStackTabs)
|
if (this.canStackTabs)
|
||||||
this.updateTabsZIndex(true);
|
this.updateTabsZIndex(true);
|
||||||
|
|
||||||
this.saveTreeStructureWithDelay();
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.subTreeMovingCount ||
|
this.subTreeMovingCount ||
|
||||||
this.internallyTabMovingCount ||
|
this.internallyTabMovingCount ||
|
||||||
@ -3304,20 +3218,7 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
this.setTabValue(aTab, this.kID, id);
|
this.setTabValue(aTab, this.kID, id);
|
||||||
this.tabsHash[id] = aTab;
|
this.tabsHash[id] = aTab;
|
||||||
|
|
||||||
if (structureRestored) {
|
if (!structureRestored) {
|
||||||
[
|
|
||||||
this.kPARENT,
|
|
||||||
this.kCHILDREN,
|
|
||||||
this.kINSERT_BEFORE,
|
|
||||||
this.kINSERT_AFTER,
|
|
||||||
this.kSUBTREE_COLLAPSED,
|
|
||||||
this.kCOLLAPSED,
|
|
||||||
this.kCOLLAPSED_DONE
|
|
||||||
].forEach(function(aKey) {
|
|
||||||
this.setTabValue(aTab, aKey, this.getTabValue(aTab, aKey));
|
|
||||||
}, this);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (closeSetId)
|
if (closeSetId)
|
||||||
this.restoreClosedSet(closeSetId, aTab);
|
this.restoreClosedSet(closeSetId, aTab);
|
||||||
|
|
||||||
@ -4508,8 +4409,6 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
|
|
||||||
this.promoteTooDeepLevelTabs(aChild);
|
this.promoteTooDeepLevelTabs(aChild);
|
||||||
|
|
||||||
this.saveTreeStructureWithDelay();
|
|
||||||
|
|
||||||
this.fireAttachedEvent(aChild, aParent);
|
this.fireAttachedEvent(aChild, aParent);
|
||||||
},
|
},
|
||||||
fireAttachedEvent : function TSTBrowser_fireAttachedEvent(aChild, aParent)
|
fireAttachedEvent : function TSTBrowser_fireAttachedEvent(aChild, aParent)
|
||||||
@ -4561,8 +4460,6 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
this.checkTabsIndentOverflow();
|
this.checkTabsIndentOverflow();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveTreeStructureWithDelay();
|
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
parentTab : parentTab
|
parentTab : parentTab
|
||||||
};
|
};
|
||||||
@ -5208,8 +5105,6 @@ TreeStyleTabBrowser.prototype = {
|
|||||||
if (!aCollapse)
|
if (!aCollapse)
|
||||||
this.scrollToTabSubtree(aTab);
|
this.scrollToTabSubtree(aTab);
|
||||||
|
|
||||||
this.saveTreeStructureWithDelay();
|
|
||||||
|
|
||||||
this.doingCollapseExpand = false;
|
this.doingCollapseExpand = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ var TreeStyleTabUtils = {
|
|||||||
kINSERT_BEFORE : 'treestyletab-insert-before',
|
kINSERT_BEFORE : 'treestyletab-insert-before',
|
||||||
kINSERT_AFTER : 'treestyletab-insert-after',
|
kINSERT_AFTER : 'treestyletab-insert-after',
|
||||||
kCLOSED_SET_ID : 'treestyletab-closed-set-id',
|
kCLOSED_SET_ID : 'treestyletab-closed-set-id',
|
||||||
kSTRUCTURE : 'treestyletab-tree-structure',
|
|
||||||
|
|
||||||
kID_RESTORING : 'treestyletab-id-restoring',
|
kID_RESTORING : 'treestyletab-id-restoring',
|
||||||
kCHILDREN_RESTORING : 'treestyletab-children-restoring',
|
kCHILDREN_RESTORING : 'treestyletab-children-restoring',
|
||||||
|
@ -77,11 +77,6 @@ TreeStyleTabWindow.prototype = {
|
|||||||
window : null,
|
window : null,
|
||||||
document : null,
|
document : null,
|
||||||
|
|
||||||
get storedTreeStructure()
|
|
||||||
{
|
|
||||||
return JSON.parse(this.SessionStore.getWindowValue(this.window, this.kSTRUCTURE) || '{}');
|
|
||||||
},
|
|
||||||
|
|
||||||
/* API */
|
/* API */
|
||||||
|
|
||||||
changeTabbarPosition : function TSTWindow_changeTabbarPosition(aNewPosition) /* PUBLIC API (obsolete, for backward compatibility) */
|
changeTabbarPosition : function TSTWindow_changeTabbarPosition(aNewPosition) /* PUBLIC API (obsolete, for backward compatibility) */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user