From 0d6aa6674be92a9ba7327fc802ecab7ef125c251 Mon Sep 17 00:00:00 2001 From: piro Date: Fri, 25 Dec 2009 19:27:34 +0000 Subject: [PATCH] rollbackTabbarPosition => undoChangeTabbarPosition / redoChangeTabbarPosition git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@5634 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 9 +++- modules/utils.js | 61 ++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 3191b987..c8e96bac 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -16,9 +16,14 @@ var TreeStyleTabService = { return this.utils.currentTabbarPosition = aValue; }, - rollbackTabbarPosition : function TSTService_rollbackTabbarPosition() /* PUBLIC API */ + undoChangeTabbarPosition : function TSTService_undoChangeTabbarPosition() /* PUBLIC API */ { - return this.utils.rollbackTabbarPosition(); + return this.utils.undoChangeTabbarPosition(); + }, + + redoChangeTabbarPosition : function TSTService_redoChangeTabbarPosition() /* PUBLIC API */ + { + return this.utils.redoChangeTabbarPosition(); }, get treeViewEnabled() /* PUBLIC API */ diff --git a/modules/utils.js b/modules/utils.js index a1e26092..327860f3 100644 --- a/modules/utils.js +++ b/modules/utils.js @@ -241,7 +241,7 @@ var TreeStyleTabUtils = { this.addPrefListener(this); this.ObserverService.addObserver(this, 'private-browsing-change-granted', false); - this._tabbarPositionHistory.push(this.currentTabbarPosition); + this.onChangeTabbarPosition(this.currentTabbarPosition); this.onPrefChange('extensions.treestyletab.indent'); this.onPrefChange('extensions.treestyletab.clickOnIndentSpaces.enabled'); @@ -1395,25 +1395,72 @@ var TreeStyleTabUtils = { return aValue; }, - rollbackTabbarPosition : function TSTUtils_rollbackTabbarPosition() /* PUBLIC API */ + undoChangeTabbarPosition : function TSTUtils_undoChangeTabbarPosition() /* PUBLIC API */ { - if (!this._tabbarPositionHistory.length) + if (this._tabbarPositionHistoryIndex <= 0) return false; this._inRollbackTabbarPosition = true; - this.currentTabbarPosition = this._tabbarPositionHistory.pop(); + + var current = this.currentTabbarPosition; + var previous; + + do { + previous = this._tabbarPositionHistory[--this._tabbarPositionHistoryIndex]; + } + while (previous && current == previous); + + this.currentTabbarPosition = previous; + this._inRollbackTabbarPosition = false; - return true; + return current != previous; + }, + + redoChangeTabbarPosition : function TSTUtils_redoChangeTabbarPosition() /* PUBLIC API */ + { + if (this._tabbarPositionHistoryIndex >= this._tabbarPositionHistory.length-1) + return false; + + this._inRollbackTabbarPosition = true; + + var current = this.currentTabbarPosition; + var next; + + do { + next = this._tabbarPositionHistory[++this._tabbarPositionHistoryIndex]; + } + while (next && current == next); + + this.currentTabbarPosition = next; + + this._inRollbackTabbarPosition = false; + + return current != next; }, onChangeTabbarPosition : function TSTUtils_onChangeTabbarPosition(aPosition) { - if (this._inRollbackTabbarPosition) return; - this._tabbarPositionHistory.push(aPosition); + var history = this._tabbarPositionHistory; + var current = history[this._tabbarPositionHistoryIndex]; + if ( + this._inRollbackTabbarPosition || + (current && current == aPosition) + ) + return; + + history = history.slice(0, this._tabbarPositionHistoryIndex+1); + history.push(aPosition); + history = history.slice(-this.kMAX_TABBAR_POSITION_HISTORY); + + this._tabbarPositionHistory = history; + this._tabbarPositionHistoryIndex = history.length-1; }, _tabbarPositionHistory : [], + _tabbarPositionHistoryIndex : -1, + + kMAX_TABBAR_POSITION_HISTORY : 999, /* Pref Listener */