From 28a91a3a8665c2e04e82e26f6a9a75a2721bb962 Mon Sep 17 00:00:00 2001 From: piro Date: Wed, 8 Jul 2009 10:40:51 +0000 Subject: [PATCH] =?UTF-8?q?*=20=E3=82=BB=E3=83=83=E3=82=B7=E3=83=A7?= =?UTF-8?q?=E3=83=B3=E5=BE=A9=E5=85=83=E6=99=82=E3=81=AB=E7=8F=BE=E5=9C=A8?= =?UTF-8?q?=E3=81=AE=E3=82=BF=E3=83=96=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=81=8C?= =?UTF-8?q?=E3=81=8A=E3=81=8B=E3=81=97=E3=81=8F=E3=81=AA=E3=82=8B=E5=95=8F?= =?UTF-8?q?=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3=EF=BC=88=E5=AF=BE=E5=87=A6?= =?UTF-8?q?=EF=BC=89=20*=20=E5=A4=89=E6=95=B0=E3=82=B9=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=97=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@4674 599a83e7-65a4-db11-8015-0010dcdd6dc2 --- content/treestyletab/treestyletab.js | 7 +- content/treestyletab/treestyletabbrowser.js | 109 ++++++++++---------- 2 files changed, 61 insertions(+), 55 deletions(-) diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 24161bf0..09b1ebd5 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -776,6 +776,7 @@ var TreeStyleTabService = { getNextTab : function(aTab) { + if (!aTab) return null; return this.evaluateXPath( 'following-sibling::xul:tab[1]', aTab, @@ -785,6 +786,7 @@ var TreeStyleTabService = { getPreviousTab : function(aTab) { + if (!aTab) return null; return this.evaluateXPath( 'preceding-sibling::xul:tab[1]', aTab, @@ -794,6 +796,7 @@ var TreeStyleTabService = { getNextVisibleTab : function(aTab) { + if (!aTab) return null; return this.evaluateXPath( 'following-sibling::xul:tab[not(@'+this.kCOLLAPSED+'="true")][1]', aTab, @@ -803,6 +806,7 @@ var TreeStyleTabService = { getPreviousVisibleTab : function(aTab) { + if (!aTab) return null; return this.evaluateXPath( 'preceding-sibling::xul:tab[not(@'+this.kCOLLAPSED+'="true")][1]', aTab, @@ -812,6 +816,7 @@ var TreeStyleTabService = { getLastVisibleTab : function(aTab) { + if (!aTab) return null; return this.evaluateXPath( 'child::xul:tab[not(@'+this.kCOLLAPSED+'="true")][last()]', aTab.parentNode, @@ -830,7 +835,7 @@ var TreeStyleTabService = { getVisibleIndex : function(aTab) { - if (aTab.getAttribute(this.kCOLLAPSED) == 'true') return -1; + if (!aTab || aTab.getAttribute(this.kCOLLAPSED) == 'true') return -1; return this.evaluateXPath( 'count(preceding-sibling::xul:tab[not(@'+this.kCOLLAPSED+'="true")])', aTab, diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index ce82a8a5..f6e452d0 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -514,54 +514,49 @@ TreeStyleTabBrowser.prototype = { aTabBrowser.treeStyleTab.onPrefChange('extensions.treestyletab.tabbar.autoHide.mode'); }, 0, b); - let (tabContextMenu) { - tabContextMenu = document.getAnonymousElementByAttribute(b, 'anonid', 'tabContextMenu'); - tabContextMenu.addEventListener('popupshowing', this, false); - if (!('MultipleTabService' in window)) { - window.setTimeout(function(aSelf, aTabBrowser, aPopup) { - let suffix = '-tabbrowser-'+(aTabBrowser.id || 'instance-'+parseInt(Math.random() * 65000)); - [ - aSelf.kMENUITEM_RELOADSUBTREE, - aSelf.kMENUITEM_RELOADCHILDREN, - aSelf.kMENUITEM_REMOVESUBTREE, - aSelf.kMENUITEM_REMOVECHILDREN, - aSelf.kMENUITEM_COLLAPSEEXPAND_SEPARATOR, - aSelf.kMENUITEM_COLLAPSE, - aSelf.kMENUITEM_EXPAND, - aSelf.kMENUITEM_AUTOHIDE_SEPARATOR, - aSelf.kMENUITEM_AUTOHIDE, - aSelf.kMENUITEM_FIXED, - aSelf.kMENUITEM_POSITION, - aSelf.kMENUITEM_BOOKMARKSUBTREE - ].forEach(function(aID) { - let item = document.getElementById(aID).cloneNode(true); - item.setAttribute('id', item.getAttribute('id')+suffix); + var tabContextMenu = document.getAnonymousElementByAttribute(b, 'anonid', 'tabContextMenu'); + tabContextMenu.addEventListener('popupshowing', this, false); + if (!('MultipleTabService' in window)) { + window.setTimeout(function(aSelf, aTabBrowser, aPopup) { + let suffix = '-tabbrowser-'+(aTabBrowser.id || 'instance-'+parseInt(Math.random() * 65000)); + [ + aSelf.kMENUITEM_RELOADSUBTREE, + aSelf.kMENUITEM_RELOADCHILDREN, + aSelf.kMENUITEM_REMOVESUBTREE, + aSelf.kMENUITEM_REMOVECHILDREN, + aSelf.kMENUITEM_COLLAPSEEXPAND_SEPARATOR, + aSelf.kMENUITEM_COLLAPSE, + aSelf.kMENUITEM_EXPAND, + aSelf.kMENUITEM_AUTOHIDE_SEPARATOR, + aSelf.kMENUITEM_AUTOHIDE, + aSelf.kMENUITEM_FIXED, + aSelf.kMENUITEM_POSITION, + aSelf.kMENUITEM_BOOKMARKSUBTREE + ].forEach(function(aID) { + let item = document.getElementById(aID).cloneNode(true); + item.setAttribute('id', item.getAttribute('id')+suffix); - let refNode = void(0); - let insertAfter = item.getAttribute('multipletab-insertafter'); - if (insertAfter) { - try { - eval('refNode = ('+insertAfter+').nextSibling'); - } - catch(e) { - } + let refNode = void(0); + let insertAfter = item.getAttribute('multipletab-insertafter'); + if (insertAfter) { + try { + eval('refNode = ('+insertAfter+').nextSibling'); } - let insertBefore = item.getAttribute('multipletab-insertbefore'); - if (refNode === void(0) && insertBefore) { - try { - eval('refNode = '+insertBefore); - } - catch(e) { - } + catch(e) { } - aPopup.insertBefore(item, refNode || null); - }); - tabContextMenu = null; - }, 0, this, b, tabContextMenu); - } - else { + } + let insertBefore = item.getAttribute('multipletab-insertbefore'); + if (refNode === void(0) && insertBefore) { + try { + eval('refNode = '+insertBefore); + } + catch(e) { + } + } + aPopup.insertBefore(item, refNode || null); + }); tabContextMenu = null; - } + }, 0, this, b, tabContextMenu); } let (allTabPopup) { @@ -1008,11 +1003,15 @@ TreeStyleTabBrowser.prototype = { var b = this.mTabBrowser; - var tabs = this.getTabs(b); - for (var i = 0, maxi = tabs.snapshotLength; i < maxi; i++) - { - this.destroyTab(tabs.snapshotItem(i)); - } + var tabs = this.getTabsArray(b); + tabs.forEach(function(aTab) { + let next = this.getNextSiblingTab(aTab); + if (next) + this.setTabValue(aTab, this.kINSERT_BEFORE, next.getAttribute(this.kID)); + }, this); + tabs.forEach(function(aTab) { + this.destroyTab(aTab); + }, this); b.removeEventListener('TabOpen', this, true); b.removeEventListener('TabClose', this, true); @@ -1760,9 +1759,8 @@ TreeStyleTabBrowser.prototype = { } var nextTab = this.getTabValue(tab, this.kINSERT_BEFORE); - if (nextTab && maybeDuplicated) { - nextTab = this.redirectId(nextTab); - } + if (nextTab && maybeDuplicated) nextTab = this.redirectId(nextTab); + nextTab = this.getTabById(nextTab); var ancestors = (this.getTabValue(tab, this.kANCESTOR) || this.getTabValue(tab, this.kPARENT)).split('|'); var parent = null; @@ -1783,7 +1781,7 @@ TreeStyleTabBrowser.prototype = { if (parent) { this.attachTabTo(tab, parent, { dontExpand : true, - insertBefore : (nextTab ? this.getTabById(nextTab) : null ), + insertBefore : nextTab, dontUpdateIndent : true }); this.updateTabsIndent([tab], undefined, undefined, aWithoutAnimation); @@ -1799,7 +1797,6 @@ TreeStyleTabBrowser.prototype = { } if (!parent) { - nextTab = this.getTabById(nextTab); if (!nextTab) nextTab = this.getNextTab(tab); var parentOfNext = this.getParentTab(nextTab); var newPos = -1; @@ -2839,7 +2836,10 @@ TreeStyleTabBrowser.prototype = { var insertBefore = aInfo.insertBefore; var beforeTab = insertBefore ? insertBefore.getAttribute(this.kID) : null ; var beforeIndex; +Application.console.log('insertBefore '+insertBefore); +Application.console.log('beforeTab '+beforeTab); if (beforeTab && (beforeIndex = children.indexOf(beforeTab)) > -1) { +Application.console.log('beforeIndex '+beforeIndex); children.splice(beforeIndex, 0, id); newIndex = insertBefore._tPos; } @@ -2858,6 +2858,7 @@ TreeStyleTabBrowser.prototype = { this.inheritTabIndent(aChild, aParent); if (newIndex > aChild._tPos) newIndex--; +Application.console.log('newIndex '+newIndex); this.moveTabSubTreeTo(aChild, newIndex); if (!aInfo.dontExpand) {