Rename conflicting variable:

prefs =>
subTreePrefs
This commit is contained in:
Piro / YUKI Hiroshi 2013-01-15 23:00:19 +09:00
parent 15a7581ab6
commit 34d48370c4

View File

@ -1,238 +1,238 @@
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
* The contents of this file are subject to the Mozilla Public License Version * The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with * 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at * the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/ * http://www.mozilla.org/MPL/
* *
* Software distributed under the License is distributed on an "AS IS" basis, * Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the * for the specific language governing rights and limitations under the
* License. * License.
* *
* The Original Code is the Tree Style Tab. * The Original Code is the Tree Style Tab.
* *
* The Initial Developer of the Original Code is YUKI "Piro" Hiroshi. * The Initial Developer of the Original Code is YUKI "Piro" Hiroshi.
* Portions created by the Initial Developer are Copyright (C) 2010-2013 * Portions created by the Initial Developer are Copyright (C) 2010-2013
* the Initial Developer. All Rights Reserved. * the Initial Developer. All Rights Reserved.
* *
* Contributor(s): YUKI "Piro" Hiroshi <piro.outsider.reflex@gmail.com> * Contributor(s): YUKI "Piro" Hiroshi <piro.outsider.reflex@gmail.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead * in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only * of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to * under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your * use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice * decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete * and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under * the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL. * the terms of any one of the MPL, the GPL or the LGPL.
* *
* ***** END LICENSE BLOCK ******/ * ***** END LICENSE BLOCK ******/
"use strict"; "use strict";
let EXPORTED_SYMBOLS = ['TreeStyleTabUtils']; let EXPORTED_SYMBOLS = ['TreeStyleTabUtils'];
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cu = Components.utils; const Cu = Components.utils;
Cu.import('resource://gre/modules/XPCOMUtils.jsm'); Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://treestyletab-modules/constants.js'); Cu.import('resource://treestyletab-modules/constants.js');
XPCOMUtils.defineLazyGetter(this, 'window', function() { XPCOMUtils.defineLazyGetter(this, 'window', function() {
Cu.import('resource://treestyletab-modules/lib/namespace.jsm'); Cu.import('resource://treestyletab-modules/lib/namespace.jsm');
return getNamespaceFor('piro.sakura.ne.jp'); return getNamespaceFor('piro.sakura.ne.jp');
}); });
XPCOMUtils.defineLazyGetter(this, 'prefs', function() { XPCOMUtils.defineLazyGetter(this, 'prefs', function() {
Cu.import('resource://treestyletab-modules/lib/prefs.js'); Cu.import('resource://treestyletab-modules/lib/prefs.js');
return window['piro.sakura.ne.jp'].prefs; return window['piro.sakura.ne.jp'].prefs;
}); });
XPCOMUtils.defineLazyGetter(this, 'stringBundle', function() { XPCOMUtils.defineLazyGetter(this, 'stringBundle', function() {
Cu.import('resource://treestyletab-modules/lib/stringBundle.js', {}); Cu.import('resource://treestyletab-modules/lib/stringBundle.js', {});
return window['piro.sakura.ne.jp'].stringBundle; return window['piro.sakura.ne.jp'].stringBundle;
}); });
XPCOMUtils.defineLazyModuleGetter(this, 'TreeStyleTabConstants', XPCOMUtils.defineLazyModuleGetter(this, 'TreeStyleTabConstants',
'resource://treestyletab-modules/constants.js', 'TreeStyleTabConstants'); 'resource://treestyletab-modules/constants.js', 'TreeStyleTabConstants');
const TST_PREF_PREFIX = 'extensions.treestyletab.'; const TST_PREF_PREFIX = 'extensions.treestyletab.';
const TST_PREF_VERSION = 9; const TST_PREF_VERSION = 9;
let TreeStyleTabUtils = { let TreeStyleTabUtils = {
get prefs () { get prefs () {
return prefs; return prefs;
}, },
/* Save/Load Prefs */ /* Save/Load Prefs */
getTreePref : function TSTUtils_getTreePref(aPrefstring) getTreePref : function TSTUtils_getTreePref(aPrefstring)
{ {
return prefs.getPref(TST_PREF_PREFIX + aPrefstring); return prefs.getPref(TST_PREF_PREFIX + aPrefstring);
}, },
setTreePref : function TSTUtils_setTreePref(aPrefstring, aNewValue) setTreePref : function TSTUtils_setTreePref(aPrefstring, aNewValue)
{ {
return prefs.setPref(TST_PREF_PREFIX + aPrefstring, aNewValue); return prefs.setPref(TST_PREF_PREFIX + aPrefstring, aNewValue);
}, },
clearTreePref : function TSTUtils_clearTreePref(aPrefstring) clearTreePref : function TSTUtils_clearTreePref(aPrefstring)
{ {
return prefs.clearPref(TST_PREF_PREFIX + aPrefstring); return prefs.clearPref(TST_PREF_PREFIX + aPrefstring);
}, },
migratePrefs : function utils_migratePrefs() migratePrefs : function utils_migratePrefs()
{ {
// migrate old prefs // migrate old prefs
var orientalPrefs = []; var orientalPrefs = [];
switch (this.getTreePref('prefsVersion')) switch (this.getTreePref('prefsVersion'))
{ {
case 0: case 0:
orientalPrefs = orientalPrefs.concat([ orientalPrefs = orientalPrefs.concat([
'extensions.treestyletab.tabbar.fixed', 'extensions.treestyletab.tabbar.fixed',
'extensions.treestyletab.enableSubtreeIndent', 'extensions.treestyletab.enableSubtreeIndent',
'extensions.treestyletab.allowSubtreeCollapseExpand' 'extensions.treestyletab.allowSubtreeCollapseExpand'
]); ]);
case 1: case 1:
case 2: case 2:
if (this.getTreePref('urlbar.loadSameDomainToNewChildTab') !== null) { if (this.getTreePref('urlbar.loadSameDomainToNewChildTab') !== null) {
let value = this.getTreePref('urlbar.loadSameDomainToNewChildTab'); let value = this.getTreePref('urlbar.loadSameDomainToNewChildTab');
this.setTreePref('urlbar.loadSameDomainToNewTab', value); this.setTreePref('urlbar.loadSameDomainToNewTab', value);
this.setTreePref('urlbar.loadSameDomainToNewTab.asChild', value); this.setTreePref('urlbar.loadSameDomainToNewTab.asChild', value);
if (value) { if (value) {
this.setTreePref('urlbar.loadDifferentDomainToNewTab', value); this.setTreePref('urlbar.loadDifferentDomainToNewTab', value);
} }
this.clearTreePref('urlbar.loadSameDomainToNewChildTab'); this.clearTreePref('urlbar.loadSameDomainToNewChildTab');
} }
case 3: case 3:
if (this.getTreePref('loadDroppedLinkToNewChildTab') !== null) { if (this.getTreePref('loadDroppedLinkToNewChildTab') !== null) {
this.setTreePref('dropLinksOnTab.behavior', this.setTreePref('dropLinksOnTab.behavior',
this.getTreePref('loadDroppedLinkToNewChildTab.confirm') ? this.getTreePref('loadDroppedLinkToNewChildTab.confirm') ?
TreeStyleTabConstants.kDROPLINK_ASK : TreeStyleTabConstants.kDROPLINK_ASK :
this.getTreePref('loadDroppedLinkToNewChildTab') ? this.getTreePref('loadDroppedLinkToNewChildTab') ?
TreeStyleTabConstants.kDROPLINK_NEWTAB : TreeStyleTabConstants.kDROPLINK_NEWTAB :
TreeStyleTabConstants.kDROPLINK_LOAD TreeStyleTabConstants.kDROPLINK_LOAD
); );
this.clearTreePref('loadDroppedLinkToNewChildTab.confirm'); this.clearTreePref('loadDroppedLinkToNewChildTab.confirm');
this.clearTreePref('loadDroppedLinkToNewChildTab'); this.clearTreePref('loadDroppedLinkToNewChildTab');
} }
if (this.getTreePref('openGroupBookmarkAsTabSubTree') !== null) { if (this.getTreePref('openGroupBookmarkAsTabSubTree') !== null) {
let behavior = 0; let behavior = 0;
if (this.getTreePref('openGroupBookmarkAsTabSubTree.underParent')) if (this.getTreePref('openGroupBookmarkAsTabSubTree.underParent'))
behavior += TreeStyleTabConstants.kGROUP_BOOKMARK_USE_DUMMY; behavior += TreeStyleTabConstants.kGROUP_BOOKMARK_USE_DUMMY;
if (!this.getTreePref('openGroupBookmarkBehavior.confirm')) { if (!this.getTreePref('openGroupBookmarkBehavior.confirm')) {
behavior += ( behavior += (
this.getTreePref('openGroupBookmarkAsTabSubTree') ? this.getTreePref('openGroupBookmarkAsTabSubTree') ?
TreeStyleTabConstants.kGROUP_BOOKMARK_SUBTREE : TreeStyleTabConstants.kGROUP_BOOKMARK_SUBTREE :
this.getTreePref('browser.tabs.loadFolderAndReplace') ? this.getTreePref('browser.tabs.loadFolderAndReplace') ?
TreeStyleTabConstants.kGROUP_BOOKMARK_REPLACE : TreeStyleTabConstants.kGROUP_BOOKMARK_REPLACE :
TreeStyleTabConstants.kGROUP_BOOKMARK_SEPARATE TreeStyleTabConstants.kGROUP_BOOKMARK_SEPARATE
); );
} }
this.setTreePref('openGroupBookmark.behavior', behavior); this.setTreePref('openGroupBookmark.behavior', behavior);
this.clearTreePref('openGroupBookmarkBehavior.confirm'); this.clearTreePref('openGroupBookmarkBehavior.confirm');
this.clearTreePref('openGroupBookmarkAsTabSubTree'); this.clearTreePref('openGroupBookmarkAsTabSubTree');
this.clearTreePref('openGroupBookmarkAsTabSubTree.underParent'); this.clearTreePref('openGroupBookmarkAsTabSubTree.underParent');
prefs.setPref('browser.tabs.loadFolderAndReplace', !!(behavior & TreeStyleTabConstants.kGROUP_BOOKMARK_REPLACE)); prefs.setPref('browser.tabs.loadFolderAndReplace', !!(behavior & TreeStyleTabConstants.kGROUP_BOOKMARK_REPLACE));
} }
case 4: case 4:
let (prefs = [ let (subTreePrefs = [
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect', 'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect',
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.onCurrentTabRemove', 'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.onCurrentTabRemove',
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.whileFocusMovingByShortcut', 'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.whileFocusMovingByShortcut',
'extensions.treestyletab.autoExpandSubTreeOnAppendChild', 'extensions.treestyletab.autoExpandSubTreeOnAppendChild',
'extensions.treestyletab.autoExpandSubTreeOnCollapsedChildFocused', 'extensions.treestyletab.autoExpandSubTreeOnCollapsedChildFocused',
'extensions.treestyletab.collapseExpandSubTree.dblclick', 'extensions.treestyletab.collapseExpandSubTree.dblclick',
'extensions.treestyletab.createSubTree.underParent', 'extensions.treestyletab.createSubTree.underParent',
'extensions.treestyletab.show.context-item-reloadTabSubTree', 'extensions.treestyletab.show.context-item-reloadTabSubTree',
'extensions.treestyletab.show.context-item-removeTabSubTree', 'extensions.treestyletab.show.context-item-removeTabSubTree',
'extensions.treestyletab.show.context-item-bookmarkTabSubTree', 'extensions.treestyletab.show.context-item-bookmarkTabSubTree',
'extensions.multipletab.show.multipletab-selection-item-removeTabSubTree', 'extensions.multipletab.show.multipletab-selection-item-removeTabSubTree',
'extensions.multipletab.show.multipletab-selection-item-createSubTree' 'extensions.multipletab.show.multipletab-selection-item-createSubTree'
]) { ]) {
for (let i = 0, maxi = prefs.length; i < maxi; i++) for (let i = 0, maxi = subTreePrefs.length; i < maxi; i++)
{ {
let pref = prefs[i]; let pref = subTreePrefs[i];
let value = prefs.getPref(pref); let value = prefs.getPref(pref);
if (value === null) { if (value === null) {
continue; continue;
} }
prefs.setPref(pref.replace('SubTree', 'Subtree'), value); prefs.setPref(pref.replace('SubTree', 'Subtree'), value);
prefs.clearPref(pref); prefs.clearPref(pref);
} }
} }
case 5: case 5:
let (behavior = this.getTreePref('openGroupBookmark.behavior')) { let (behavior = this.getTreePref('openGroupBookmark.behavior')) {
behavior = behavior | 2048; behavior = behavior | 2048;
this.setTreePref('openGroupBookmark.behavior', behavior); this.setTreePref('openGroupBookmark.behavior', behavior);
} }
case 6: case 6:
let ( let (
general = this.getTreePref('autoAttachNewTabsAsChildren'), general = this.getTreePref('autoAttachNewTabsAsChildren'),
search = this.getTreePref('autoAttachSearchResultAsChildren') search = this.getTreePref('autoAttachSearchResultAsChildren')
) { ) {
if (general !== null) if (general !== null)
this.setTreePref('autoAttach', general); this.setTreePref('autoAttach', general);
if (search !== null) if (search !== null)
this.setTreePref('autoAttach.searchResult', search); this.setTreePref('autoAttach.searchResult', search);
} }
case 7: case 7:
let ( let (
enabled = this.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut'), enabled = this.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut'),
delay = this.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay') delay = this.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay')
) { ) {
if (enabled !== null) { if (enabled !== null) {
this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut', enabled); this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut', enabled);
this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.collapseOthers', enabled); this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.collapseOthers', enabled);
} }
if (delay !== null) if (delay !== null)
this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay', delay); this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay', delay);
} }
case 8: case 8:
orientalPrefs = orientalPrefs.concat([ orientalPrefs = orientalPrefs.concat([
'extensions.treestyletab.indent', 'extensions.treestyletab.indent',
'extensions.treestyletab.indent.min' 'extensions.treestyletab.indent.min'
]); ]);
default: default:
for (let i = 0, maxi = orientalPrefs.length; i < maxi; i++) for (let i = 0, maxi = orientalPrefs.length; i < maxi; i++)
{ {
let pref = orientalPrefs[i]; let pref = orientalPrefs[i];
let value = prefs.getPref(pref); let value = prefs.getPref(pref);
if (value === null) { if (value === null) {
continue; continue;
} }
prefs.setPref(pref+'.horizontal', value); prefs.setPref(pref+'.horizontal', value);
prefs.setPref(pref+'.vertical', value); prefs.setPref(pref+'.vertical', value);
prefs.clearPref(pref); prefs.clearPref(pref);
} }
break; break;
} }
this.setTreePref('prefsVersion', TST_PREF_VERSION); this.setTreePref('prefsVersion', TST_PREF_VERSION);
}, },
/* string bundle */ /* string bundle */
get treeBundle () { get treeBundle () {
return stringBundle.get('chrome://treestyletab/locale/treestyletab.properties'); return stringBundle.get('chrome://treestyletab/locale/treestyletab.properties');
}, },
get tabbrowserBundle () { get tabbrowserBundle () {
return stringBundle.get('chrome://browser/locale/tabbrowser.properties'); return stringBundle.get('chrome://browser/locale/tabbrowser.properties');
}, },
evalInSandbox : function utils_evalInSandbox(aCode, aOwner) evalInSandbox : function utils_evalInSandbox(aCode, aOwner)
{ {
try { try {
var sandbox = new Cu.Sandbox(aOwner || 'about:blank'); var sandbox = new Cu.Sandbox(aOwner || 'about:blank');
return Cu.evalInSandbox(aCode, sandbox); return Cu.evalInSandbox(aCode, sandbox);
} }
catch(e) { catch(e) {
} }
return void(0); return void(0);
} }
}; };