ライブラリ更新

git-svn-id: http://www.cozmixng.org/repos/piro/treestyletab/trunk@6153 599a83e7-65a4-db11-8015-0010dcdd6dc2
This commit is contained in:
piro 2010-01-25 04:36:08 +00:00
parent 96fc9b2b2e
commit 7a6246302a

View File

@ -22,13 +22,14 @@ var window = {};
window['piro.sakura.ne.jp'].prefs.addPrefListener(listener); window['piro.sakura.ne.jp'].prefs.addPrefListener(listener);
window['piro.sakura.ne.jp'].prefs.removePrefListener(listener); window['piro.sakura.ne.jp'].prefs.removePrefListener(listener);
lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
original: original:
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/prefs.js http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/prefs.js
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/prefs.test.js
*/ */
(function() { (function() {
const currentRevision = 2; const currentRevision = 4;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {}; if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
@ -39,48 +40,38 @@ var window = {};
return; return;
} }
const Cc = Components.classes;
const Ci = Components.interfaces;
window['piro.sakura.ne.jp'].prefs = { window['piro.sakura.ne.jp'].prefs = {
revision : currentRevision, revision : currentRevision,
get Prefs() Prefs : Cc['@mozilla.org/preferences;1']
{ .getService(Ci.nsIPrefBranch)
if (!this._Prefs) { .QueryInterface(Ci.nsIPrefBranch2),
this._Prefs = Components.classes['@mozilla.org/preferences;1'].getService(Components.interfaces.nsIPrefBranch);
}
return this._Prefs;
},
_Prefs : null,
get DefaultPrefs() DefaultPrefs : Cc['@mozilla.org/preferences-service;1']
{ .getService(Ci.nsIPrefService)
if (!this._DefaultPrefs) { .getDefaultBranch(null),
this._DefaultPrefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getDefaultBranch(null);
}
return this._DefaultPrefs;
},
_DefaultPrefs : null,
getPref : function(aPrefstring, aBranch) getPref : function(aPrefstring, aBranch)
{ {
if (!aBranch) aBranch = this.Prefs; if (!aBranch) aBranch = this.Prefs;
try {
switch (aBranch.getPrefType(aPrefstring)) switch (aBranch.getPrefType(aPrefstring))
{ {
case this.Prefs.PREF_STRING: case aBranch.PREF_STRING:
return decodeURIComponent(escape(aBranch.getCharPref(aPrefstring))); return decodeURIComponent(escape(aBranch.getCharPref(aPrefstring)));
break;
case this.Prefs.PREF_INT:
return aBranch.getIntPref(aPrefstring);
break;
default:
return aBranch.getBoolPref(aPrefstring);
break;
}
}
catch(e) {
}
case aBranch.PREF_INT:
return aBranch.getIntPref(aPrefstring);
case aBranch.PREF_BOOL:
return aBranch.getBoolPref(aPrefstring);
case aBranch.PREF_INVALID:
default:
return null; return null;
}
}, },
getDefaultPref : function(aPrefstring) getDefaultPref : function(aPrefstring)
@ -91,53 +82,36 @@ var window = {};
setPref : function(aPrefstring, aNewValue, aBranch) setPref : function(aPrefstring, aNewValue, aBranch)
{ {
if (!aBranch) aBranch = this.Prefs; if (!aBranch) aBranch = this.Prefs;
switch (typeof aNewValue)
var type;
try {
type = typeof aNewValue;
}
catch(e) {
type = null;
}
switch (type)
{ {
case 'string': case 'string':
aBranch.setCharPref(aPrefstring, unescape(encodeURIComponent(aNewValue))); return aBranch.setCharPref(aPrefstring, unescape(encodeURIComponent(aNewValue)));
break;
case 'number': case 'number':
aBranch.setIntPref(aPrefstring, parseInt(aNewValue)); return aBranch.setIntPref(aPrefstring, parseInt(aNewValue));
break;
default: default:
aBranch.setBoolPref(aPrefstring, aNewValue); return aBranch.setBoolPref(aPrefstring, aNewValue);
break;
} }
return true;
}, },
setDefaultPref : function(aPrefstring) setDefaultPref : function(aPrefstring, aNewValue)
{ {
return this.setPref(aPrefstring, aNewValue, this.DefaultPrefs); return this.setPref(aPrefstring, aNewValue, this.DefaultPrefs);
}, },
clearPref : function(aPrefstring) clearPref : function(aPrefstring)
{ {
try { if (this.Prefs.prefHasUserValue(aPrefstring))
this.Prefs.clearUserPref(aPrefstring); this.Prefs.clearUserPref(aPrefstring);
}
catch(e) {
}
return;
}, },
addPrefListener : function(aObserver) addPrefListener : function(aObserver)
{ {
var domains = ('domains' in aObserver) ? aObserver.domains : [aObserver.domain] ; var domains = ('domains' in aObserver) ? aObserver.domains : [aObserver.domain] ;
try { try {
var pbi = this.Prefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal); for each (var domain in domains)
for (var i = 0; i < domains.length; i++) this.Prefs.addObserver(domain, aObserver, false);
pbi.addObserver(domains[i], aObserver, false);
} }
catch(e) { catch(e) {
} }
@ -147,9 +121,8 @@ var window = {};
{ {
var domains = ('domains' in aObserver) ? aObserver.domains : [aObserver.domain] ; var domains = ('domains' in aObserver) ? aObserver.domains : [aObserver.domain] ;
try { try {
var pbi = this.Prefs.QueryInterface(Components.interfaces.nsIPrefBranchInternal); for each (var domain in domains)
for (var i = 0; i < domains.length; i++) this.Prefs.removeObserver(domain, aObserver, false);
pbi.removeObserver(domains[i], aObserver, false);
} }
catch(e) { catch(e) {
} }