diff --git a/content/treestyletab/config.xul b/content/treestyletab/config.xul
index 58170d03..67456a0b 100644
--- a/content/treestyletab/config.xul
+++ b/content/treestyletab/config.xul
@@ -21,6 +21,9 @@
name="extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab"
type="bool"
inverted="true"/>
+
@@ -38,6 +41,11 @@
+
diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js
index 50716317..c018b05b 100644
--- a/content/treestyletab/treestyletab.js
+++ b/content/treestyletab/treestyletab.js
@@ -11,6 +11,9 @@ var TreeStyleTabService = {
kTWISTY : 'treestyletab-tab-tree-twisty',
kTWISTY_CONTAINER : 'treestyletab-tab-tree-twisty-container',
+ kFOCUS_ALL : 0,
+ kFOCUS_VISIBLE : 1,
+
levelMargin : 12,
NSResolver : {
@@ -40,7 +43,7 @@ var TreeStyleTabService = {
_SessionStore : null,
/* Utilities */
-
+
isEventFiredOnTabIcon : function(aEvent)
{
var tab = this.getTabFromEvent(aEvent);
@@ -72,6 +75,30 @@ var TreeStyleTabService = {
return 'SplitBrowser' ? SplitBrowser.activeBrowser : gBrowser ;
},
+ evaluateXPath : function(aExpression, aContext, aType)
+ {
+ if (!aType) aType = XPathResult.ORDERED_NODE_SNAPSHOT_TYPE;
+ try {
+ var xpathResult = document.evaluate(
+ aExpression,
+ aContext,
+ this.NSResolver,
+ aType,
+ null
+ );
+ }
+ catch(e) {
+ return {
+ singleNodeValue : null,
+ snapshotLength : 0,
+ snapshotItem : function() {
+ return null
+ }
+ };
+ }
+ return xpathResult;
+ },
+
getArrayFromXPathResult : function(aXPathResult)
{
var max = aXPathResult.snapshotLength;
@@ -165,43 +192,23 @@ var TreeStyleTabService = {
separator.setAttribute('hidden', true);
}
},
-
+
getSeparators : function(aPopup)
{
- try {
- var xpathResult = document.evaluate(
- 'descendant::xul:menuseparator',
- aPopup,
- this.NSResolver,
- XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
- null
- );
- }
- catch(e) {
- return { snapshotLength : 0 };
- }
- return xpathResult;
+ return this.evaluateXPath('descendant::xul:menuseparator', aPopup);
},
getObsoleteSeparator : function(aPopup)
{
- try {
- var xpathResult = document.evaluate(
- 'descendant::xul:menuseparator[not(@hidden)][not(following-sibling::*[not(@hidden)]) or not(preceding-sibling::*[not(@hidden)]) or local-name(following-sibling::*[not(@hidden)]) = "menuseparator"]',
- aPopup,
- this.NSResolver,
- XPathResult.FIRST_ORDERED_NODE_TYPE,
- null
- );
- }
- catch(e) {
- return null;
- }
- return xpathResult.singleNodeValue;
+ return this.evaluateXPath(
+ 'descendant::xul:menuseparator[not(@hidden)][not(following-sibling::*[not(@hidden)]) or not(preceding-sibling::*[not(@hidden)]) or local-name(following-sibling::*[not(@hidden)]) = "menuseparator"]',
+ aPopup,
+ XPathResult.FIRST_ORDERED_NODE_TYPE
+ ).singleNodeValue;
},
/* Initializing */
-
+
init : function()
{
if (!('gBrowser' in window)) return;
@@ -238,7 +245,7 @@ var TreeStyleTabService = {
this.initTabBrowser(gBrowser);
},
-
+
initTabBrowser : function(aTabBrowser)
{
aTabBrowser.mTabContainer.addEventListener('TreeStyleTab:TabOpen', this, true);
@@ -255,8 +262,36 @@ var TreeStyleTabService = {
/\{/,
<>>
+ )
+ );
+
+ eval('aTabBrowser.mTabContainer.advanceSelectedTab = '+
+ aTabBrowser.mTabContainer.advanceSelectedTab.toSource().replace(
+ /\{/,
+ <>>
@@ -313,7 +348,7 @@ var TreeStyleTabService = {
delete tabs;
},
-
+
initTab : function(aTab, aTabBrowser)
{
var id = 'tab-<'+Date.now()+'-'+parseInt(Math.random() * 65000)+'>';
@@ -391,7 +426,7 @@ var TreeStyleTabService = {
},
/* Event Handling */
-
+
handleEvent : function(aEvent)
{
switch (aEvent.type)
@@ -641,9 +676,9 @@ var TreeStyleTabService = {
this.collapseExpandTreesIntelligentlyFor(tab);
}
},
-
+
/* Tab Utilities */
-
+
getTabValue : function(aTab, aKey)
{
var value = null;
@@ -682,37 +717,21 @@ var TreeStyleTabService = {
getTabById : function(aId, aTabBrowser)
{
- try {
- var xpathResult = document.evaluate(
- 'descendant::xul:tab[@'+this.kID+' = "'+aId+'"]',
- aTabBrowser.mTabContainer,
- this.NSResolver,
- XPathResult.FIRST_ORDERED_NODE_TYPE,
- null
- );
- }
- catch(e) {
- return null;
- }
- return xpathResult.singleNodeValue;
+ return this.evaluateXPath(
+ 'descendant::xul:tab[@'+this.kID+' = "'+aId+'"]',
+ aTabBrowser.mTabContainer,
+ XPathResult.FIRST_ORDERED_NODE_TYPE
+ ).singleNodeValue;
},
getParentTabOf : function(aTab)
{
var id = aTab.getAttribute(this.kID);
- try {
- var xpathResult = document.evaluate(
- 'parent::*/child::xul:tab[contains(@'+this.kCHILDREN+', "'+id+'")]',
- aTab,
- this.NSResolver,
- XPathResult.FIRST_ORDERED_NODE_TYPE,
- null
- );
- }
- catch(e) {
- return null;
- }
- return xpathResult.singleNodeValue;
+ return this.evaluateXPath(
+ 'parent::*/child::xul:tab[contains(@'+this.kCHILDREN+', "'+id+'")]',
+ aTab,
+ XPathResult.FIRST_ORDERED_NODE_TYPE
+ ).singleNodeValue;
},
getNextSiblingTabOf : function(aTab)
@@ -832,7 +851,7 @@ var TreeStyleTabService = {
},
/* Commands */
-
+
adoptTabTo : function(aChild, aParent, aInfo)
{
if (!aChild || !aParent) return;
@@ -1010,43 +1029,38 @@ var TreeStyleTabService = {
expandedParentTabs.push(parentTab.getAttribute(this.kID));
}
expandedParentTabs = expandedParentTabs.join('|');
- try {
- var xpathResult = document.evaluate(
- 'child::xul:tab[@'+this.kCHILDREN+' and not(@'+this.kCOLLAPSED+'="true") and not(@'+this.kSUBTREE_COLLAPSED+'="true") and not(contains("'+expandedParentTabs+'", @'+this.kID+'))]',
- b.mTabContainer,
- this.NSResolver,
- XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
- null
- );
- var collapseTab;
- var dontCollapse;
- for (var i = 0, maxi = xpathResult.snapshotLength; i < maxi; i++)
- {
- dontCollapse = false;
- collapseTab = xpathResult.snapshotItem(i);
- parentTab = this.getParentTabOf(collapseTab);
- if (parentTab) {
- dontCollapse = true;
- do {
- if (parentTab != parent) continue;
- dontCollapse = false;
- break;
- }
- while (parentTab = this.getParentTabOf(parentTab));
+ var xpathResult = this.evaluateXPath(
+ 'child::xul:tab[@'+this.kCHILDREN+' and not(@'+this.kCOLLAPSED+'="true") and not(@'+this.kSUBTREE_COLLAPSED+'="true") and not(contains("'+expandedParentTabs+'", @'+this.kID+'))]',
+ b.mTabContainer
+ );
+ var collapseTab;
+ var dontCollapse;
+ for (var i = 0, maxi = xpathResult.snapshotLength; i < maxi; i++)
+ {
+ dontCollapse = false;
+ collapseTab = xpathResult.snapshotItem(i);
+
+ parentTab = this.getParentTabOf(collapseTab);
+ if (parentTab) {
+ dontCollapse = true;
+ do {
+ if (parentTab != parent) continue;
+ dontCollapse = false;
+ break;
}
-
- if (!dontCollapse)
- this.collapseExpandTabSubTree(collapseTab, true);
+ while (parentTab = this.getParentTabOf(parentTab));
}
+
+ if (!dontCollapse)
+ this.collapseExpandTabSubTree(collapseTab, true);
}
- catch(e) {
- }
+
this.collapseExpandTabSubTree(aTab, false);
},
/* Pref Listener */
-
+
domain : 'extensions.treestyletab',
observe : function(aSubject, aTopic, aPrefName)
@@ -1065,7 +1079,7 @@ var TreeStyleTabService = {
},
/* Save/Load Prefs */
-
+
get Prefs()
{
if (!this._Prefs) {
diff --git a/defaults/preferences/treestyletab.js b/defaults/preferences/treestyletab.js
index 056909cf..174e7ad0 100644
--- a/defaults/preferences/treestyletab.js
+++ b/defaults/preferences/treestyletab.js
@@ -1,6 +1,8 @@
-pref("extensions.treestyletab.autoCollapseExpandSubTreeOnSelect", true);
-pref("extensions.treestyletab.autoExpandSubTreeOnAppendChild", true);
+pref("extensions.treestyletab.autoCollapseExpandSubTreeOnSelect", true);
+pref("extensions.treestyletab.autoExpandSubTreeOnAppendChild", true);
pref("extensions.treestyletab.adoptChildrenToGrandParentOnRemoveTab", true);
+// 0 = default, 1 = only visible tabs
+pref("extensions.treestyletab.focusMode", 1);
pref("browser.link.open_newwindow.restriction", 0);
diff --git a/locale/en-US/treestyletab/treestyletab.dtd b/locale/en-US/treestyletab/treestyletab.dtd
index cbb2b348..935b7757 100644
--- a/locale/en-US/treestyletab/treestyletab.dtd
+++ b/locale/en-US/treestyletab/treestyletab.dtd
@@ -9,6 +9,8 @@
+
+
diff --git a/locale/ja/treestyletab/treestyletab.dtd b/locale/ja/treestyletab/treestyletab.dtd
index d16b996a..331a3db8 100644
--- a/locale/ja/treestyletab/treestyletab.dtd
+++ b/locale/ja/treestyletab/treestyletab.dtd
@@ -9,6 +9,8 @@
+
+