diff --git a/content/treestyletab/res/prefs.js b/content/treestyletab/res/prefs.js index 510aedff..b52c8a90 100644 --- a/content/treestyletab/res/prefs.js +++ b/content/treestyletab/res/prefs.js @@ -25,7 +25,7 @@ http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/prefs.js */ (function() { - const currentRevision = 1; + const currentRevision = 2; if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; @@ -47,20 +47,30 @@ return this._Prefs; }, _Prefs : null, - - getPref : function(aPrefstring) + + get DefaultPrefs() { + if (!this._DefaultPrefs) { + this._DefaultPrefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getDefaultBranch(null); + } + return this._DefaultPrefs; + }, + _DefaultPrefs : null, + + getPref : function(aPrefstring, aBranch) + { + if (!aBranch) aBranch = this.Prefs; try { - switch (this.Prefs.getPrefType(aPrefstring)) + switch (aBranch.getPrefType(aPrefstring)) { case this.Prefs.PREF_STRING: - return decodeURIComponent(escape(this.Prefs.getCharPref(aPrefstring))); + return decodeURIComponent(escape(aBranch.getCharPref(aPrefstring))); break; case this.Prefs.PREF_INT: - return this.Prefs.getIntPref(aPrefstring); + return aBranch.getIntPref(aPrefstring); break; default: - return this.Prefs.getBoolPref(aPrefstring); + return aBranch.getBoolPref(aPrefstring); break; } } @@ -69,10 +79,16 @@ return null; }, - - setPref : function(aPrefstring, aNewValue) + + getDefaultPref : function(aPrefstring) { - var pref = this.Prefs ; + return this.getPref(aPrefstring, this.DefaultPrefs); + }, + + setPref : function(aPrefstring, aNewValue, aBranch) + { + if (!aBranch) aBranch = this.Prefs; + var type; try { type = typeof aNewValue; @@ -84,17 +100,22 @@ switch (type) { case 'string': - pref.setCharPref(aPrefstring, unescape(encodeURIComponent(aNewValue))); + aBranch.setCharPref(aPrefstring, unescape(encodeURIComponent(aNewValue))); break; case 'number': - pref.setIntPref(aPrefstring, parseInt(aNewValue)); + aBranch.setIntPref(aPrefstring, parseInt(aNewValue)); break; default: - pref.setBoolPref(aPrefstring, aNewValue); + aBranch.setBoolPref(aPrefstring, aNewValue); break; } return true; }, + + setDefaultPref : function(aPrefstring) + { + return this.setPref(aPrefstring, aNewValue, this.DefaultPrefs); + }, clearPref : function(aPrefstring) { diff --git a/content/treestyletab/treestyletab.js b/content/treestyletab/treestyletab.js index 45c0d8e8..6442e481 100644 --- a/content/treestyletab/treestyletab.js +++ b/content/treestyletab/treestyletab.js @@ -466,11 +466,6 @@ var TreeStyleTabService = { var pref = isVertical ? 'tabbar.fixed.vertical' : 'tabbar.fixed.horizontal' ; this.setTreePref(pref, !this.getTreePref(pref)); - - if (!this.getTreePref('syncRelatedPrefs')) return; - - if (!isVertical) - this.setTreePref('enableSubtreeIndent', !this.getTreePref(pref)); }, changeTabbarPosition : function(aNewPosition) /* PUBLIC API */ @@ -480,12 +475,6 @@ var TreeStyleTabService = { aNewPosition = aNewPosition.toLowerCase(); this.setTreePref('tabbar.position', aNewPosition); - - if (!this.getTreePref('syncRelatedPrefs')) return; - - var vertical = (aNewPosition == 'left' || aNewPosition == 'right'); - this.setTreePref('enableSubtreeIndent', vertical || !this.getTreePref('tabbar.fixed.horizontal')); - this.setTreePref('allowSubtreeCollapseExpand', vertical); }, /* backward compatibility */ @@ -1170,6 +1159,25 @@ var TreeStyleTabService = { this.overrideExtensionsPreInit(); // hacks.js this.registerTabFocusAllowance(this.defaultTabFocusAllowance); + + // migrate old prefs + switch (this.getTreePref('orientalPrefsMigrated')) + { + case 0: + [ + 'extensions.treestyletab.tabbar.fixed', + 'extensions.treestyletab.enableSubtreeIndent', + 'extensions.treestyletab.allowSubtreeCollapseExpand' + ].forEach(function(aPref) { + let value = this.getPref(aPref); + if (value === null) return; + this.setPref(aPref+'.horizontal', value); + this.setPref(aPref+'.vertical', value); + }, this); + default: + break; + } + this.setTreePref('orientalPrefsMigrated', 1); }, preInitialized : false, diff --git a/content/treestyletab/treestyletabbrowser.js b/content/treestyletab/treestyletabbrowser.js index b3c87459..4cebdbdb 100644 --- a/content/treestyletab/treestyletabbrowser.js +++ b/content/treestyletab/treestyletabbrowser.js @@ -502,7 +502,6 @@ TreeStyleTabBrowser.prototype = { this.onPrefChange('extensions.treestyletab.tabbar.style'); this.onPrefChange('extensions.treestyletab.twisty.style'); this.onPrefChange('extensions.treestyletab.showBorderForFirstTab'); - this.onPrefChange('extensions.treestyletab.enableSubtreeIndent'); this.onPrefChange('extensions.treestyletab.tabbar.invertTabContents'); this.onPrefChange('extensions.treestyletab.tabbar.invertScrollbar'); this.onPrefChange('extensions.treestyletab.tabbar.invertClosebox'); @@ -844,7 +843,7 @@ TreeStyleTabBrowser.prototype = { b.mStrip.removeAttribute('height'); b.mPanelContainer.removeAttribute('height'); - this.updateTabbarFixedState(); + this.updateTabbarState(); if (pos == this.kTABBAR_RIGHT) { b.setAttribute(this.kTABBAR_POSITION, 'right'); @@ -919,7 +918,7 @@ TreeStyleTabBrowser.prototype = { b.setAttribute(this.kMODE, this.getTreePref('tabbar.multirow') ? 'multirow' : 'horizontal' ); b.removeAttribute(this.kTAB_INVERTED); - this.updateTabbarFixedState(); + this.updateTabbarState(); if (pos == this.kTABBAR_BOTTOM) { b.setAttribute(this.kTABBAR_POSITION, 'bottom'); @@ -961,16 +960,19 @@ TreeStyleTabBrowser.prototype = { scrollInnerBox = null; allTabsButton = null; }, - updateTabbarFixedState : function() + updateTabbarState : function() { var b = this.mTabBrowser; + var orient; if (this.isVertical) { + orient = 'vertical'; if (this.getTreePref('tabbar.fixed.vertical')) b.setAttribute(this.kFIXED, true); else b.removeAttribute(this.kFIXED); } else { + orient = 'horizontal'; if (this.getTreePref('tabbar.fixed.horizontal')) { b.setAttribute(this.kFIXED, true); if (!this.isMultiRow()) { @@ -983,6 +985,18 @@ TreeStyleTabBrowser.prototype = { b.mStrip.setAttribute('height', this.getTreePref('tabbar.height')); } } + + if (this.getTreePref('enableSubtreeIndent.'+orient)) + b.setAttribute(this.kINDENTED, 'true'); + else + b.removeAttribute(this.kINDENTED); + + if (this.getTreePref('allowSubtreeCollapseExpand.'+orient)) + b.setAttribute(this.kALLOW_COLLAPSE, 'true'); + else + b.removeAttribute(this.kALLOW_COLLAPSE); + + this.updateAllTabsIndent(); }, destroy : function() @@ -1127,14 +1141,6 @@ TreeStyleTabBrowser.prototype = { }, this); break; - case 'extensions.treestyletab.enableSubtreeIndent': - if (value) - b.setAttribute(this.kINDENTED, 'true'); - else - b.removeAttribute(this.kINDENTED); - this.updateAllTabsIndent(); - break; - case 'extensions.treestyletab.tabbar.style': if (value) { if (/^(default|vertigo|mixed)$/.test(value)) @@ -1189,13 +1195,6 @@ TreeStyleTabBrowser.prototype = { b.removeAttribute(this.kHIDE_ALLTABS); break; - case 'extensions.treestyletab.allowSubtreeCollapseExpand': - if (value) - b.setAttribute(this.kALLOW_COLLAPSE, true); - else - b.removeAttribute(this.kALLOW_COLLAPSE); - break; - case 'extensions.treestyletab.tabbar.autoHide.mode': this.updateAutoHideMode(); break; @@ -1209,9 +1208,13 @@ TreeStyleTabBrowser.prototype = { this.endListenMouseMove(); break; + case 'extensions.treestyletab.enableSubtreeIndent.horizontal': + case 'extensions.treestyletab.enableSubtreeIndent.vertical': + case 'extensions.treestyletab.allowSubtreeCollapseExpand.horizontal': + case 'extensions.treestyletab.allowSubtreeCollapseExpand.vertical': case 'extensions.treestyletab.tabbar.fixed.vertical': case 'extensions.treestyletab.tabbar.fixed.horizontal': - this.updateTabbarFixedState(); + this.updateTabbarState(); break; case 'extensions.treestyletab.tabbar.transparent.style': @@ -2939,7 +2942,8 @@ TreeStyleTabBrowser.prototype = { var b = this.mTabBrowser; if (!aProp) { - aProp = this.getTreePref('enableSubtreeIndent') ? this.indentProp : null ; + let orient = this.isVertical ? 'vertical' : 'horizontal' ; + aProp = this.getTreePref('enableSubtreeIndent.'+orient) ? this.indentProp : null ; } var margin = this.indent < 0 ? this.baseIndent : this.indent ; var indent = margin * aLevel; diff --git a/defaults/preferences/treestyletab.js b/defaults/preferences/treestyletab.js index b7baa4ff..4588f8ae 100644 --- a/defaults/preferences/treestyletab.js +++ b/defaults/preferences/treestyletab.js @@ -39,9 +39,11 @@ pref("extensions.treestyletab.tabbar.togglerSize", 5); pref("extensions.treestyletab.tabbar.fixed.horizontal", true); pref("extensions.treestyletab.tabbar.fixed.vertical", false); pref("extensions.treestyletab.syncRelatedPrefs", true); -pref("extensions.treestyletab.enableSubtreeIndent", true); +pref("extensions.treestyletab.enableSubtreeIndent.horizontal", false); +pref("extensions.treestyletab.enableSubtreeIndent.vertical", true); pref("extensions.treestyletab.enableSubtreeIndent.allTabsPopup", true); -pref("extensions.treestyletab.allowSubtreeCollapseExpand", true); +pref("extensions.treestyletab.allowSubtreeCollapseExpand.horizontal", false); +pref("extensions.treestyletab.allowSubtreeCollapseExpand.vertical", true); pref("extensions.treestyletab.showBorderForFirstTab", false); pref("extensions.treestyletab.autoExpand.enabled", true); pref("extensions.treestyletab.autoExpand.delay", 500); @@ -114,5 +116,8 @@ pref("extensions.multipletab.show.multipletab-selection-item-removeTabSubTree", pref("extensions.treestyletab.TMP.doNotUpdate.isTabVisible", false); +pref("extensions.treestyletab.orientalPrefsMigrated", 0); + + pref("extensions.treestyletab@piro.sakura.ne.jp.name", "chrome://treestyletab/locale/treestyletab.properties"); pref("extensions.treestyletab@piro.sakura.ne.jp.description", "chrome://treestyletab/locale/treestyletab.properties");