Merge pull request #442 from saneyuki/migrate
Move TreeStyleTabBase.migratePrefs() to TreeStyleTabUtils.migratePrefs()
This commit is contained in:
commit
46657fd827
126
modules/base.js
126
modules/base.js
@ -300,7 +300,7 @@ var TreeStyleTabBase = {
|
||||
this.isMac = Services.appinfo.OS == 'Darwin';
|
||||
|
||||
this.applyPlatformDefaultPrefs();
|
||||
this.migratePrefs();
|
||||
utils.migratePrefs();
|
||||
|
||||
this.addPrefListener(this);
|
||||
|
||||
@ -354,130 +354,6 @@ var TreeStyleTabBase = {
|
||||
}
|
||||
},
|
||||
|
||||
kPREF_VERSION : 9,
|
||||
migratePrefs : function utils_migratePrefs()
|
||||
{
|
||||
// migrate old prefs
|
||||
var orientalPrefs = [];
|
||||
switch (utils.getTreePref('prefsVersion'))
|
||||
{
|
||||
case 0:
|
||||
orientalPrefs = orientalPrefs.concat([
|
||||
'extensions.treestyletab.tabbar.fixed',
|
||||
'extensions.treestyletab.enableSubtreeIndent',
|
||||
'extensions.treestyletab.allowSubtreeCollapseExpand'
|
||||
]);
|
||||
case 1:
|
||||
case 2:
|
||||
if (utils.getTreePref('urlbar.loadSameDomainToNewChildTab') !== null) {
|
||||
let value = utils.getTreePref('urlbar.loadSameDomainToNewChildTab');
|
||||
utils.setTreePref('urlbar.loadSameDomainToNewTab', value);
|
||||
utils.setTreePref('urlbar.loadSameDomainToNewTab.asChild', value);
|
||||
if (value) utils.setTreePref('urlbar.loadDifferentDomainToNewTab', value);
|
||||
utils.clearTreePref('urlbar.loadSameDomainToNewChildTab');
|
||||
}
|
||||
case 3:
|
||||
if (utils.getTreePref('loadDroppedLinkToNewChildTab') !== null) {
|
||||
utils.setTreePref('dropLinksOnTab.behavior',
|
||||
utils.getTreePref('loadDroppedLinkToNewChildTab.confirm') ?
|
||||
this.kDROPLINK_ASK :
|
||||
utils.getTreePref('loadDroppedLinkToNewChildTab') ?
|
||||
this.kDROPLINK_NEWTAB :
|
||||
this.kDROPLINK_LOAD
|
||||
);
|
||||
utils.clearTreePref('loadDroppedLinkToNewChildTab.confirm');
|
||||
utils.clearTreePref('loadDroppedLinkToNewChildTab');
|
||||
}
|
||||
if (utils.getTreePref('openGroupBookmarkAsTabSubTree') !== null) {
|
||||
let behavior = 0;
|
||||
if (utils.getTreePref('openGroupBookmarkAsTabSubTree.underParent'))
|
||||
behavior += this.kGROUP_BOOKMARK_USE_DUMMY;
|
||||
if (!utils.getTreePref('openGroupBookmarkBehavior.confirm')) {
|
||||
behavior += (
|
||||
utils.getTreePref('openGroupBookmarkAsTabSubTree') ?
|
||||
this.kGROUP_BOOKMARK_SUBTREE :
|
||||
utils.getTreePref('browser.tabs.loadFolderAndReplace') ?
|
||||
this.kGROUP_BOOKMARK_REPLACE :
|
||||
this.kGROUP_BOOKMARK_SEPARATE
|
||||
);
|
||||
}
|
||||
utils.setTreePref('openGroupBookmark.behavior', behavior);
|
||||
utils.clearTreePref('openGroupBookmarkBehavior.confirm');
|
||||
utils.clearTreePref('openGroupBookmarkAsTabSubTree');
|
||||
utils.clearTreePref('openGroupBookmarkAsTabSubTree.underParent');
|
||||
this.setPref('browser.tabs.loadFolderAndReplace', !!(behavior & this.kGROUP_BOOKMARK_REPLACE));
|
||||
}
|
||||
case 4:
|
||||
let (prefs = [
|
||||
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect',
|
||||
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.onCurrentTabRemove',
|
||||
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.whileFocusMovingByShortcut',
|
||||
'extensions.treestyletab.autoExpandSubTreeOnAppendChild',
|
||||
'extensions.treestyletab.autoExpandSubTreeOnCollapsedChildFocused',
|
||||
'extensions.treestyletab.collapseExpandSubTree.dblclick',
|
||||
'extensions.treestyletab.createSubTree.underParent',
|
||||
'extensions.treestyletab.show.context-item-reloadTabSubTree',
|
||||
'extensions.treestyletab.show.context-item-removeTabSubTree',
|
||||
'extensions.treestyletab.show.context-item-bookmarkTabSubTree',
|
||||
'extensions.multipletab.show.multipletab-selection-item-removeTabSubTree',
|
||||
'extensions.multipletab.show.multipletab-selection-item-createSubTree'
|
||||
]) {
|
||||
for (let i = 0, maxi = prefs.length; i < maxi; i++)
|
||||
{
|
||||
let pref = prefs[i];
|
||||
let value = this.getPref(pref);
|
||||
if (value === null) continue;
|
||||
this.setPref(pref.replace('SubTree', 'Subtree'), value);
|
||||
this.clearPref(pref);
|
||||
}
|
||||
}
|
||||
case 5:
|
||||
let (behavior = utils.getTreePref('openGroupBookmark.behavior')) {
|
||||
behavior = behavior | 2048;
|
||||
utils.setTreePref('openGroupBookmark.behavior', behavior);
|
||||
}
|
||||
case 6:
|
||||
let (
|
||||
general = utils.getTreePref('autoAttachNewTabsAsChildren'),
|
||||
search = utils.getTreePref('autoAttachSearchResultAsChildren')
|
||||
) {
|
||||
if (general !== null)
|
||||
utils.setTreePref('autoAttach', general);
|
||||
if (search !== null)
|
||||
utils.setTreePref('autoAttach.searchResult', search);
|
||||
}
|
||||
case 7:
|
||||
let (
|
||||
enabled = utils.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut'),
|
||||
delay = utils.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay')
|
||||
) {
|
||||
if (enabled !== null) {
|
||||
utils.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut', enabled);
|
||||
utils.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.collapseOthers', enabled);
|
||||
}
|
||||
if (delay !== null)
|
||||
utils.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay', delay);
|
||||
}
|
||||
case 8:
|
||||
orientalPrefs = orientalPrefs.concat([
|
||||
'extensions.treestyletab.indent',
|
||||
'extensions.treestyletab.indent.min'
|
||||
]);
|
||||
default:
|
||||
for (let i = 0, maxi = orientalPrefs.length; i < maxi; i++)
|
||||
{
|
||||
let pref = orientalPrefs[i];
|
||||
let value = this.getPref(pref);
|
||||
if (value === null) continue;
|
||||
this.setPref(pref+'.horizontal', value);
|
||||
this.setPref(pref+'.vertical', value);
|
||||
this.clearPref(pref);
|
||||
}
|
||||
break;
|
||||
}
|
||||
utils.setTreePref('prefsVersion', this.kPREF_VERSION);
|
||||
},
|
||||
|
||||
initUninstallationListener : function TSTWindow_initUninstallationListener()
|
||||
{
|
||||
var restorePrefs = function() {
|
||||
|
133
modules/utils.js
133
modules/utils.js
@ -58,8 +58,12 @@ XPCOMUtils.defineLazyGetter(this, 'stringBundle', function() {
|
||||
return window['piro.sakura.ne.jp'].stringBundle;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, 'base',
|
||||
'resource://treestyletab-modules/base.js', 'TreeStyleTabBase');
|
||||
|
||||
const TST_PREF_PREFIX = 'extensions.treestyletab.';
|
||||
const TST_PREF_VERSION = 9;
|
||||
|
||||
|
||||
let TreeStyleTabUtils = {
|
||||
|
||||
@ -84,6 +88,135 @@ let TreeStyleTabUtils = {
|
||||
return prefs.clearPref(TST_PREF_PREFIX + aPrefstring);
|
||||
},
|
||||
|
||||
migratePrefs : function utils_migratePrefs()
|
||||
{
|
||||
// migrate old prefs
|
||||
var orientalPrefs = [];
|
||||
switch (this.getTreePref('prefsVersion'))
|
||||
{
|
||||
case 0:
|
||||
orientalPrefs = orientalPrefs.concat([
|
||||
'extensions.treestyletab.tabbar.fixed',
|
||||
'extensions.treestyletab.enableSubtreeIndent',
|
||||
'extensions.treestyletab.allowSubtreeCollapseExpand'
|
||||
]);
|
||||
case 1:
|
||||
case 2:
|
||||
if (this.getTreePref('urlbar.loadSameDomainToNewChildTab') !== null) {
|
||||
let value = this.getTreePref('urlbar.loadSameDomainToNewChildTab');
|
||||
this.setTreePref('urlbar.loadSameDomainToNewTab', value);
|
||||
this.setTreePref('urlbar.loadSameDomainToNewTab.asChild', value);
|
||||
if (value) {
|
||||
this.setTreePref('urlbar.loadDifferentDomainToNewTab', value);
|
||||
}
|
||||
this.clearTreePref('urlbar.loadSameDomainToNewChildTab');
|
||||
}
|
||||
case 3:
|
||||
if (this.getTreePref('loadDroppedLinkToNewChildTab') !== null) {
|
||||
this.setTreePref('dropLinksOnTab.behavior',
|
||||
this.getTreePref('loadDroppedLinkToNewChildTab.confirm') ?
|
||||
base.kDROPLINK_ASK :
|
||||
this.getTreePref('loadDroppedLinkToNewChildTab') ?
|
||||
base.kDROPLINK_NEWTAB :
|
||||
base.kDROPLINK_LOAD
|
||||
);
|
||||
this.clearTreePref('loadDroppedLinkToNewChildTab.confirm');
|
||||
utithisls.clearTreePref('loadDroppedLinkToNewChildTab');
|
||||
}
|
||||
if (this.getTreePref('openGroupBookmarkAsTabSubTree') !== null) {
|
||||
let behavior = 0;
|
||||
if (this.getTreePref('openGroupBookmarkAsTabSubTree.underParent'))
|
||||
behavior += base.kGROUP_BOOKMARK_USE_DUMMY;
|
||||
if (!this.getTreePref('openGroupBookmarkBehavior.confirm')) {
|
||||
behavior += (
|
||||
this.getTreePref('openGroupBookmarkAsTabSubTree') ?
|
||||
base.kGROUP_BOOKMARK_SUBTREE :
|
||||
this.getTreePref('browser.tabs.loadFolderAndReplace') ?
|
||||
base.kGROUP_BOOKMARK_REPLACE :
|
||||
base.kGROUP_BOOKMARK_SEPARATE
|
||||
);
|
||||
}
|
||||
this.setTreePref('openGroupBookmark.behavior', behavior);
|
||||
this.clearTreePref('openGroupBookmarkBehavior.confirm');
|
||||
this.clearTreePref('openGroupBookmarkAsTabSubTree');
|
||||
this.clearTreePref('openGroupBookmarkAsTabSubTree.underParent');
|
||||
prefs.setPref('browser.tabs.loadFolderAndReplace', !!(behavior & base.kGROUP_BOOKMARK_REPLACE));
|
||||
}
|
||||
case 4:
|
||||
let (prefs = [
|
||||
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect',
|
||||
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.onCurrentTabRemove',
|
||||
'extensions.treestyletab.autoCollapseExpandSubTreeOnSelect.whileFocusMovingByShortcut',
|
||||
'extensions.treestyletab.autoExpandSubTreeOnAppendChild',
|
||||
'extensions.treestyletab.autoExpandSubTreeOnCollapsedChildFocused',
|
||||
'extensions.treestyletab.collapseExpandSubTree.dblclick',
|
||||
'extensions.treestyletab.createSubTree.underParent',
|
||||
'extensions.treestyletab.show.context-item-reloadTabSubTree',
|
||||
'extensions.treestyletab.show.context-item-removeTabSubTree',
|
||||
'extensions.treestyletab.show.context-item-bookmarkTabSubTree',
|
||||
'extensions.multipletab.show.multipletab-selection-item-removeTabSubTree',
|
||||
'extensions.multipletab.show.multipletab-selection-item-createSubTree'
|
||||
]) {
|
||||
for (let i = 0, maxi = prefs.length; i < maxi; i++)
|
||||
{
|
||||
let pref = prefs[i];
|
||||
let value = prefs.getPref(pref);
|
||||
if (value === null) {
|
||||
continue;
|
||||
}
|
||||
prefs.setPref(pref.replace('SubTree', 'Subtree'), value);
|
||||
prefs.clearPref(pref);
|
||||
}
|
||||
}
|
||||
case 5:
|
||||
let (behavior = this.getTreePref('openGroupBookmark.behavior')) {
|
||||
behavior = behavior | 2048;
|
||||
this.setTreePref('openGroupBookmark.behavior', behavior);
|
||||
}
|
||||
case 6:
|
||||
let (
|
||||
general = this.getTreePref('autoAttachNewTabsAsChildren'),
|
||||
search = this.getTreePref('autoAttachSearchResultAsChildren')
|
||||
) {
|
||||
if (general !== null)
|
||||
this.setTreePref('autoAttach', general);
|
||||
if (search !== null)
|
||||
this.setTreePref('autoAttach.searchResult', search);
|
||||
}
|
||||
case 7:
|
||||
let (
|
||||
enabled = this.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut'),
|
||||
delay = this.getTreePref('autoCollapseExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay')
|
||||
) {
|
||||
if (enabled !== null) {
|
||||
this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut', enabled);
|
||||
this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.collapseOthers', enabled);
|
||||
}
|
||||
if (delay !== null)
|
||||
this.setTreePref('autoExpandSubtreeOnSelect.whileFocusMovingByShortcut.delay', delay);
|
||||
}
|
||||
case 8:
|
||||
orientalPrefs = orientalPrefs.concat([
|
||||
'extensions.treestyletab.indent',
|
||||
'extensions.treestyletab.indent.min'
|
||||
]);
|
||||
default:
|
||||
for (let i = 0, maxi = orientalPrefs.length; i < maxi; i++)
|
||||
{
|
||||
let pref = orientalPrefs[i];
|
||||
let value = prefs.getPref(pref);
|
||||
if (value === null) {
|
||||
continue;
|
||||
}
|
||||
prefs.setPref(pref+'.horizontal', value);
|
||||
prefs.setPref(pref+'.vertical', value);
|
||||
prefs.clearPref(pref);
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.setTreePref('prefsVersion', TST_PREF_VERSION);
|
||||
},
|
||||
|
||||
/* string bundle */
|
||||
get treeBundle () {
|
||||
return stringBundle.get('chrome://treestyletab/locale/treestyletab.properties');
|
||||
|
Loading…
Reference in New Issue
Block a user