mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 23:27:58 +01:00
s/service[(".*?")]/services.get(\1)/g; s/service.get(\w+)/'services.create("' + lcfirst($1) + '")'/ge
This commit is contained in:
@@ -751,8 +751,8 @@ function Buffer() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var cacheEntryDescriptor = service["cache"].createSession(proto, 0, true)
|
var cacheEntryDescriptor = services.get("cache").createSession(proto, 0, true)
|
||||||
.openCacheEntry(cacheKey, ACCESS_READ, false);
|
.openCacheEntry(cacheKey, ACCESS_READ, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
|
|||||||
@@ -1551,7 +1551,7 @@ function Completion() //{{{
|
|||||||
|
|
||||||
location: function location(context)
|
location: function location(context)
|
||||||
{
|
{
|
||||||
if (!service["autoCompleteSearch"])
|
if (!services.get("autoCompleteSearch"))
|
||||||
return
|
return
|
||||||
context.anchored = false;
|
context.anchored = false;
|
||||||
context.title = ["Smart Completions"];
|
context.title = ["Smart Completions"];
|
||||||
@@ -1567,8 +1567,8 @@ function Completion() //{{{
|
|||||||
for (i in util.range(0, result.matchCount))
|
for (i in util.range(0, result.matchCount))
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
service["autoCompleteSearch"].stopSearch();
|
services.get("autoCompleteSearch").stopSearch();
|
||||||
service["autoCompleteSearch"].startSearch(context.filter, "", context.result, {
|
services.get("autoCompleteSearch").startSearch(context.filter, "", context.result, {
|
||||||
onSearchResult: function onSearchResult(search, result)
|
onSearchResult: function onSearchResult(search, result)
|
||||||
{
|
{
|
||||||
context.result = result;
|
context.result = result;
|
||||||
@@ -1651,9 +1651,7 @@ function Completion() //{{{
|
|||||||
context.anchored = false;
|
context.anchored = false;
|
||||||
context.title = ["Firefox Preference", "Value"];
|
context.title = ["Firefox Preference", "Value"];
|
||||||
context.keys = { text: function (item) item, description: function (item) options.getPref(item) };
|
context.keys = { text: function (item) item, description: function (item) options.getPref(item) };
|
||||||
context.completions = Cc["@mozilla.org/preferences-service;1"]
|
context.completions = services.get("pref").getChildList("", { value: 0 });
|
||||||
.getService(Ci.nsIPrefBranch)
|
|
||||||
.getChildList("", { value: 0 });
|
|
||||||
},
|
},
|
||||||
|
|
||||||
search: function search(context, noSuggest)
|
search: function search(context, noSuggest)
|
||||||
@@ -1704,7 +1702,7 @@ function Completion() //{{{
|
|||||||
|
|
||||||
let completions = [];
|
let completions = [];
|
||||||
engineList.forEach(function (name) {
|
engineList.forEach(function (name) {
|
||||||
let engine = service["browserSearch"].getEngineByAlias(name);
|
let engine = services.get("browserSearch").getEngineByAlias(name);
|
||||||
if (!engine)
|
if (!engine)
|
||||||
return;
|
return;
|
||||||
let [,word] = /^\s*(\S+)/.exec(context.filter) || [];
|
let [,word] = /^\s*(\S+)/.exec(context.filter) || [];
|
||||||
@@ -1727,7 +1725,7 @@ function Completion() //{{{
|
|||||||
context.title = ["Shell Command", "Path"];
|
context.title = ["Shell Command", "Path"];
|
||||||
context.generate = function ()
|
context.generate = function ()
|
||||||
{
|
{
|
||||||
let dirNames = service["environment"].get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":"));
|
let dirNames = services.get("environment").get("PATH").split(RegExp(liberator.has("Win32") ? ";" : ":"));
|
||||||
let commands = [];
|
let commands = [];
|
||||||
|
|
||||||
for (let [,dirName] in Iterator(dirNames))
|
for (let [,dirName] in Iterator(dirNames))
|
||||||
|
|||||||
@@ -1644,9 +1644,8 @@ function Events() //{{{
|
|||||||
prefObserver: {
|
prefObserver: {
|
||||||
register: function ()
|
register: function ()
|
||||||
{
|
{
|
||||||
const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
|
// better way to monitor all changes?
|
||||||
this._branch = prefService.getBranch(""); // better way to monitor all changes?
|
this._branch = services.get("pref").getBranch("").QueryInterface(Ci.nsIPrefBranch2);
|
||||||
this._branch.QueryInterface(Ci.nsIPrefBranch2);
|
|
||||||
this._branch.addObserver("", this, false);
|
this._branch.addObserver("", this, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ function Search() //{{{
|
|||||||
var highlightObj = {
|
var highlightObj = {
|
||||||
search: function (aWord, matchCase)
|
search: function (aWord, matchCase)
|
||||||
{
|
{
|
||||||
var finder = service.getFind();
|
var finder = services.create("find");
|
||||||
if (matchCase !== undefined)
|
if (matchCase !== undefined)
|
||||||
finder.caseSensitive = matchCase;
|
finder.caseSensitive = matchCase;
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ function IO() //{{{
|
|||||||
const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager);
|
const downloadManager = Cc["@mozilla.org/download-manager;1"].createInstance(Ci.nsIDownloadManager);
|
||||||
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||||
|
|
||||||
var processDir = service["directory"].get("CurWorkD", Ci.nsIFile);
|
var processDir = services.get("directory").get("CurWorkD", Ci.nsIFile);
|
||||||
var cwd = processDir;
|
var cwd = processDir;
|
||||||
var oldcwd = null;
|
var oldcwd = null;
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ function IO() //{{{
|
|||||||
var scriptNames = [];
|
var scriptNames = [];
|
||||||
|
|
||||||
// default option values
|
// default option values
|
||||||
var cdpath = "," + (service["environment"].get("CDPATH").replace(/[:;]/g, ",") || ",");
|
var cdpath = "," + (services.get("environment").get("CDPATH").replace(/[:;]/g, ",") || ",");
|
||||||
var shell, shellcmdflag;
|
var shell, shellcmdflag;
|
||||||
|
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
@@ -89,7 +89,7 @@ function IO() //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell = service["environment"].get("SHELL") || "sh";
|
shell = services.get("environment").get("SHELL") || "sh";
|
||||||
shellcmdflag = "-c";
|
shellcmdflag = "-c";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +132,7 @@ function IO() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
service.getFile().initWithPath(path);
|
services.create("file").initWithPath(path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
@@ -480,7 +480,7 @@ function IO() //{{{
|
|||||||
// also expands relative paths
|
// also expands relative paths
|
||||||
getFile: function (path, noCheckPWD)
|
getFile: function (path, noCheckPWD)
|
||||||
{
|
{
|
||||||
let file = service.getFile();
|
let file = services.create("file");
|
||||||
|
|
||||||
if (/file:\/\//.test(path))
|
if (/file:\/\//.test(path))
|
||||||
{
|
{
|
||||||
@@ -521,7 +521,7 @@ function IO() //{{{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let file = service["directory"].get("TmpD", Ci.nsIFile);
|
let file = services.get("directory").get("TmpD", Ci.nsIFile);
|
||||||
file.append(tmpName);
|
file.append(tmpName);
|
||||||
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
|
file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
|
||||||
|
|
||||||
@@ -627,7 +627,7 @@ function IO() //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let dirs = service["environment"].get("PATH").split(WINDOWS ? ";" : ":");
|
let dirs = services.get("environment").get("PATH").split(WINDOWS ? ";" : ":");
|
||||||
// Windows tries the cwd first TODO: desirable?
|
// Windows tries the cwd first TODO: desirable?
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
dirs = [io.getCurrentDirectory().path].concat(dirs);
|
dirs = [io.getCurrentDirectory().path].concat(dirs);
|
||||||
@@ -645,7 +645,7 @@ lookup:
|
|||||||
// automatically try to add the executable path extensions on windows
|
// automatically try to add the executable path extensions on windows
|
||||||
if (WINDOWS)
|
if (WINDOWS)
|
||||||
{
|
{
|
||||||
let extensions = service["environment"].get("PATHEXT").split(";");
|
let extensions = services.get("environment").get("PATHEXT").split(";");
|
||||||
for (let [,extension] in Iterator(extensions))
|
for (let [,extension] in Iterator(extensions))
|
||||||
{
|
{
|
||||||
file = joinPaths(dir, program + extension);
|
file = joinPaths(dir, program + extension);
|
||||||
@@ -664,7 +664,7 @@ lookup:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let process = service.getProcess();
|
let process = services.create("process");
|
||||||
|
|
||||||
process.init(file);
|
process.init(file);
|
||||||
process.run(blocking, args, args.length);
|
process.run(blocking, args, args.length);
|
||||||
@@ -922,7 +922,7 @@ lookup:
|
|||||||
|
|
||||||
}; //}}}
|
}; //}}}
|
||||||
|
|
||||||
IO.__defineGetter__("runtimePath", function () service["environment"].get(config.name.toUpperCase() + "_RUNTIME") ||
|
IO.__defineGetter__("runtimePath", function () services.get("environment").get(config.name.toUpperCase() + "_RUNTIME") ||
|
||||||
"~/" + (liberator.has("Win32") ? "" : ".") + config.name.toLowerCase());
|
"~/" + (liberator.has("Win32") ? "" : ".") + config.name.toLowerCase());
|
||||||
|
|
||||||
IO.expandPath = function (path, relative)
|
IO.expandPath = function (path, relative)
|
||||||
@@ -939,7 +939,7 @@ IO.expandPath = function (path, relative)
|
|||||||
function expand(path) path.replace(
|
function expand(path) path.replace(
|
||||||
!WINDOWS ? /\$(\w+)\b|\${(\w+)}/g
|
!WINDOWS ? /\$(\w+)\b|\${(\w+)}/g
|
||||||
: /\$(\w+)\b|\${(\w+)}|%(\w+)%/g,
|
: /\$(\w+)\b|\${(\w+)}|%(\w+)%/g,
|
||||||
function (m, n1, n2, n3) service["environment"].get(n1 || n2 || n3) || m
|
function (m, n1, n2, n3) services.get("environment").get(n1 || n2 || n3) || m
|
||||||
);
|
);
|
||||||
path = expand(path);
|
path = expand(path);
|
||||||
|
|
||||||
@@ -947,12 +947,12 @@ IO.expandPath = function (path, relative)
|
|||||||
if (!relative && (WINDOWS ? /^~(?:$|\\)/ : /^~(?:$|\/)/).test(path))
|
if (!relative && (WINDOWS ? /^~(?:$|\\)/ : /^~(?:$|\/)/).test(path))
|
||||||
{
|
{
|
||||||
// Try $HOME first, on all systems
|
// Try $HOME first, on all systems
|
||||||
let home = service["environment"].get("HOME");
|
let home = services.get("environment").get("HOME");
|
||||||
|
|
||||||
// Windows has its own ideosyncratic $HOME variables.
|
// Windows has its own ideosyncratic $HOME variables.
|
||||||
if (!home && WINDOWS)
|
if (!home && WINDOWS)
|
||||||
home = service["environment"].get("USERPROFILE") ||
|
home = services.get("environment").get("USERPROFILE") ||
|
||||||
service["environment"].get("HOMEDRIVE") + service["environment"].get("HOMEPATH");
|
services.get("environment").get("HOMEDRIVE") + services.get("environment").get("HOMEPATH");
|
||||||
|
|
||||||
path = home + path.substr(1);
|
path = home + path.substr(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
let prefix = [BASE];
|
let prefix = [BASE];
|
||||||
|
|
||||||
["service.js",
|
["services.js",
|
||||||
"liberator.js",
|
"liberator.js",
|
||||||
"config.js",
|
"config.js",
|
||||||
"util.js",
|
"util.js",
|
||||||
|
|||||||
@@ -28,11 +28,6 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
|||||||
|
|
||||||
/** @scope modules */
|
/** @scope modules */
|
||||||
|
|
||||||
const Cc = Components.classes;
|
|
||||||
const Ci = Components.interfaces;
|
|
||||||
const Cr = Components.results;
|
|
||||||
const Cu = Components.utils;
|
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
const plugins = {};
|
const plugins = {};
|
||||||
@@ -684,18 +679,18 @@ const liberator = (function () //{{{
|
|||||||
return false; // so you can do: if (...) return liberator.beep();
|
return false; // so you can do: if (...) return liberator.beep();
|
||||||
},
|
},
|
||||||
|
|
||||||
newThread: function () service["threadManager"].newThread(0),
|
newThread: function () services.get("threadManager").newThread(0),
|
||||||
|
|
||||||
callAsync: function (thread, self, func)
|
callAsync: function (thread, self, func)
|
||||||
{
|
{
|
||||||
thread = thread || service["threadManager"].newThread(0);
|
thread = thread || services.get("threadManager").newThread(0);
|
||||||
thread.dispatch(new Runnable(self, func, Array.slice(arguments, 3)), thread.DISPATCH_NORMAL);
|
thread.dispatch(new Runnable(self, func, Array.slice(arguments, 3)), thread.DISPATCH_NORMAL);
|
||||||
},
|
},
|
||||||
|
|
||||||
// be sure to call GUI related methods like alert() or dump() ONLY in the main thread
|
// be sure to call GUI related methods like alert() or dump() ONLY in the main thread
|
||||||
callFunctionInThread: function (thread, func)
|
callFunctionInThread: function (thread, func)
|
||||||
{
|
{
|
||||||
thread = thread || service["threadManager"].newThread(0);
|
thread = thread || services.get("threadManager").newThread(0);
|
||||||
|
|
||||||
// DISPATCH_SYNC is necessary, otherwise strange things will happen
|
// DISPATCH_SYNC is necessary, otherwise strange things will happen
|
||||||
thread.dispatch(new Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC);
|
thread.dispatch(new Runnable(null, func, Array.slice(arguments, 2)), thread.DISPATCH_SYNC);
|
||||||
@@ -767,7 +762,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
loadScript: function (uri, context)
|
loadScript: function (uri, context)
|
||||||
{
|
{
|
||||||
service["subscriptLoader"].loadSubScript(uri, context);
|
services.get("subscriptLoader").loadSubScript(uri, context);
|
||||||
},
|
},
|
||||||
|
|
||||||
eval: function (str, context)
|
eval: function (str, context)
|
||||||
@@ -901,7 +896,7 @@ const liberator = (function () //{{{
|
|||||||
// if clearFocusedElement, also blur a focused link
|
// if clearFocusedElement, also blur a focused link
|
||||||
focusContent: function (clearFocusedElement)
|
focusContent: function (clearFocusedElement)
|
||||||
{
|
{
|
||||||
if (window != service["windowWatcher"].activeWindow)
|
if (window != services.get("windowWatcher").activeWindow)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let elem = config.mainWidget || window.content;
|
let elem = config.mainWidget || window.content;
|
||||||
@@ -934,7 +929,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
hasExtension: function (name)
|
hasExtension: function (name)
|
||||||
{
|
{
|
||||||
let extensions = service["extensionManager"].getItemList(Ci.nsIUpdateItem.TYPE_EXTENSION, {});
|
let extensions = services.get("extensionManager").getItemList(Ci.nsIUpdateItem.TYPE_EXTENSION, {});
|
||||||
|
|
||||||
return extensions.some(function (e) e.name == name);
|
return extensions.some(function (e) e.name == name);
|
||||||
},
|
},
|
||||||
@@ -1112,8 +1107,8 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
case liberator.NEW_WINDOW:
|
case liberator.NEW_WINDOW:
|
||||||
window.open();
|
window.open();
|
||||||
service["windowMediator"].getMostRecentWindow("navigator:browser")
|
services.get("windowMediator").getMostRecentWindow("navigator:browser")
|
||||||
.loadURI(url, null, postdata);
|
.loadURI(url, null, postdata);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1154,7 +1149,7 @@ const liberator = (function () //{{{
|
|||||||
options.setPref("browser.startup.page", 1); // start with default homepage session
|
options.setPref("browser.startup.page", 1); // start with default homepage session
|
||||||
|
|
||||||
if (force)
|
if (force)
|
||||||
service["appStartup"].quit(Ci.nsIAppStartup.eForceQuit);
|
services.get("appStartup").quit(Ci.nsIAppStartup.eForceQuit);
|
||||||
else
|
else
|
||||||
window.goQuitApplication();
|
window.goQuitApplication();
|
||||||
},
|
},
|
||||||
@@ -1184,24 +1179,24 @@ const liberator = (function () //{{{
|
|||||||
{
|
{
|
||||||
// notify all windows that an application quit has been requested.
|
// notify all windows that an application quit has been requested.
|
||||||
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
|
||||||
service["observer"].notifyObservers(cancelQuit, "quit-application-requested", null);
|
services.get("observer").notifyObservers(cancelQuit, "quit-application-requested", null);
|
||||||
|
|
||||||
// something aborted the quit process.
|
// something aborted the quit process.
|
||||||
if (cancelQuit.data)
|
if (cancelQuit.data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// notify all windows that an application quit has been granted.
|
// notify all windows that an application quit has been granted.
|
||||||
service["observer"].notifyObservers(null, "quit-application-granted", null);
|
services.get("observer").notifyObservers(null, "quit-application-granted", null);
|
||||||
|
|
||||||
// enumerate all windows and call shutdown handlers
|
// enumerate all windows and call shutdown handlers
|
||||||
let windows = service["windowMediator"].getEnumerator(null);
|
let windows = services.get("windowMediator").getEnumerator(null);
|
||||||
while (windows.hasMoreElements())
|
while (windows.hasMoreElements())
|
||||||
{
|
{
|
||||||
let win = windows.getNext();
|
let win = windows.getNext();
|
||||||
if (("tryToClose" in win) && !win.tryToClose())
|
if (("tryToClose" in win) && !win.tryToClose())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
service["appStartup"].quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
services.get("appStartup").quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: move to {muttator,vimperator,...}.js
|
// TODO: move to {muttator,vimperator,...}.js
|
||||||
@@ -1228,10 +1223,10 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
let infoPath = service.getFile();
|
let infoPath = services.create("file");
|
||||||
infoPath.initWithPath(IO.expandPath(IO.runtimePath.replace(/,.*/, "")));
|
infoPath.initWithPath(IO.expandPath(IO.runtimePath.replace(/,.*/, "")));
|
||||||
infoPath.append("info");
|
infoPath.append("info");
|
||||||
infoPath.append(service["profile"].selectedProfile.name);
|
infoPath.append(services.get("profile").selectedProfile.name);
|
||||||
storage.infoPath = infoPath;
|
storage.infoPath = infoPath;
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
@@ -1280,7 +1275,7 @@ const liberator = (function () //{{{
|
|||||||
// make sourcing asynchronous, otherwise commands that open new tabs won't work
|
// make sourcing asynchronous, otherwise commands that open new tabs won't work
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
|
||||||
let init = service["environment"].get(config.name.toUpperCase() + "_INIT");
|
let init = services.get("environment").get(config.name.toUpperCase() + "_INIT");
|
||||||
if (init)
|
if (init)
|
||||||
liberator.execute(init);
|
liberator.execute(init);
|
||||||
else
|
else
|
||||||
@@ -1337,7 +1332,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
sleep: function (delay)
|
sleep: function (delay)
|
||||||
{
|
{
|
||||||
let mainThread = service["threadManager"].mainThread;
|
let mainThread = services.get("threadManager").mainThread;
|
||||||
|
|
||||||
let end = Date.now() + delay;
|
let end = Date.now() + delay;
|
||||||
while (Date.now() < end)
|
while (Date.now() < end)
|
||||||
@@ -1347,8 +1342,8 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
callInMainThread: function (callback, self)
|
callInMainThread: function (callback, self)
|
||||||
{
|
{
|
||||||
let mainThread = service["threadManager"].mainThread;
|
let mainThread = services.get("threadManager").mainThread;
|
||||||
if (!service["threadManager"].isMainThread)
|
if (!services.get("threadManager").isMainThread)
|
||||||
mainThread.dispatch({ run: callback.call(self) }, mainThread.DISPATCH_NORMAL);
|
mainThread.dispatch({ run: callback.call(self) }, mainThread.DISPATCH_NORMAL);
|
||||||
else
|
else
|
||||||
callback.call(self);
|
callback.call(self);
|
||||||
@@ -1356,7 +1351,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
threadYield: function (flush, interruptable)
|
threadYield: function (flush, interruptable)
|
||||||
{
|
{
|
||||||
let mainThread = service["threadManager"].mainThread;
|
let mainThread = services.get("threadManager").mainThread;
|
||||||
liberator.interrupted = false;
|
liberator.interrupted = false;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -1396,7 +1391,7 @@ const liberator = (function () //{{{
|
|||||||
get windows()
|
get windows()
|
||||||
{
|
{
|
||||||
let windows = [];
|
let windows = [];
|
||||||
let enumerator = service["windowMediator"].getEnumerator("navigator:browser");
|
let enumerator = services.get("windowMediator").getEnumerator("navigator:browser");
|
||||||
while (enumerator.hasMoreElements())
|
while (enumerator.hasMoreElements())
|
||||||
windows.push(enumerator.getNext());
|
windows.push(enumerator.getNext());
|
||||||
|
|
||||||
|
|||||||
@@ -304,8 +304,6 @@ function Options() //{{{
|
|||||||
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
|
||||||
|
|
||||||
const SAVED = "liberator.saved.";
|
const SAVED = "liberator.saved.";
|
||||||
|
|
||||||
const optionHash = {};
|
const optionHash = {};
|
||||||
@@ -332,27 +330,27 @@ function Options() //{{{
|
|||||||
prefContexts[prefContexts.length - 1][name] = val;
|
prefContexts[prefContexts.length - 1][name] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
let type = prefService.getPrefType(name);
|
let type = services.get("pref").getPrefType(name);
|
||||||
switch (typeof value)
|
switch (typeof value)
|
||||||
{
|
{
|
||||||
case "string":
|
case "string":
|
||||||
if (type == prefService.PREF_INVALID || type == prefService.PREF_STRING)
|
if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_STRING)
|
||||||
prefService.setCharPref(name, value);
|
services.get("pref").setCharPref(name, value);
|
||||||
else if (type == prefService.PREF_INT)
|
else if (type == Ci.nsIPrefBranch.PREF_INT)
|
||||||
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
||||||
else
|
else
|
||||||
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
||||||
break;
|
break;
|
||||||
case "number":
|
case "number":
|
||||||
if (type == prefService.PREF_INVALID || type == prefService.PREF_INT)
|
if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_INT)
|
||||||
prefService.setIntPref(name, value);
|
services.get("pref").setIntPref(name, value);
|
||||||
else
|
else
|
||||||
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case "boolean":
|
||||||
if (type == prefService.PREF_INVALID || type == prefService.PREF_BOOL)
|
if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_BOOL)
|
||||||
prefService.setBoolPref(name, value);
|
services.get("pref").setBoolPref(name, value);
|
||||||
else if (type == prefService.PREF_INT)
|
else if (type == Ci.nsIPrefBranch.PREF_INT)
|
||||||
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
liberator.echoerr("E521: Number required after =: " + name + "=" + value);
|
||||||
else
|
else
|
||||||
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
liberator.echoerr("E474: Invalid argument: " + name + "=" + value);
|
||||||
@@ -368,22 +366,22 @@ function Options() //{{{
|
|||||||
if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history)
|
if (forcedDefault != null) // this argument sets defaults for non-user settable options (like extensions.history.comp_history)
|
||||||
defaultValue = forcedDefault;
|
defaultValue = forcedDefault;
|
||||||
|
|
||||||
let branch = defaultBranch ? prefService.getDefaultBranch("") : prefService;
|
let branch = defaultBranch ? services.get("pref").getDefaultBranch("") : services.get("pref");
|
||||||
let type = prefService.getPrefType(name);
|
let type = services.get("pref").getPrefType(name);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case prefService.PREF_STRING:
|
case Ci.nsIPrefBranch.PREF_STRING:
|
||||||
let value = branch.getComplexValue(name, Ci.nsISupportsString).data;
|
let value = branch.getComplexValue(name, Ci.nsISupportsString).data;
|
||||||
// try in case it's a localized string (will throw an exception if not)
|
// try in case it's a localized string (will throw an exception if not)
|
||||||
if (!prefService.prefIsLocked(name) && !prefService.prefHasUserValue(name) &&
|
if (!services.get("pref").prefIsLocked(name) && !services.get("pref").prefHasUserValue(name) &&
|
||||||
/^chrome:\/\/.+\/locale\/.+\.properties/.test(value))
|
RegExp("chrome://.+/locale/.+\\.properties").test(value))
|
||||||
value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data;
|
value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data;
|
||||||
return value;
|
return value;
|
||||||
case prefService.PREF_INT:
|
case Ci.nsIPrefBranch.PREF_INT:
|
||||||
return branch.getIntPref(name);
|
return branch.getIntPref(name);
|
||||||
case prefService.PREF_BOOL:
|
case Ci.nsIPrefBranch.PREF_BOOL:
|
||||||
return branch.getBoolPref(name);
|
return branch.getBoolPref(name);
|
||||||
default:
|
default:
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@@ -788,8 +786,9 @@ function Options() //{{{
|
|||||||
{
|
{
|
||||||
completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]);
|
completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]);
|
||||||
completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref],
|
completion.setFunctionCompleter([options.getPref, options.safeSetPref, options.setPref, options.resetPref, options.invertPref],
|
||||||
[function () prefService.getChildList("", { value: 0 })
|
[function () services.get("pref")
|
||||||
.map(function (pref) [pref, ""])]);
|
.getChildList("", { value: 0 })
|
||||||
|
.map(function (pref) [pref, ""])]);
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -890,12 +889,12 @@ function Options() //{{{
|
|||||||
if (!filter)
|
if (!filter)
|
||||||
filter = "";
|
filter = "";
|
||||||
|
|
||||||
let prefArray = prefService.getChildList("", { value: 0 });
|
let prefArray = services.get("pref").getChildList("", { value: 0 });
|
||||||
prefArray.sort();
|
prefArray.sort();
|
||||||
let prefs = function () {
|
let prefs = function () {
|
||||||
for each (let pref in prefArray)
|
for (let [,pref] in Iterator(prefArray))
|
||||||
{
|
{
|
||||||
let userValue = prefService.prefHasUserValue(pref);
|
let userValue = services.get("pref").prefHasUserValue(pref);
|
||||||
if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1)
|
if (onlyNonDefault && !userValue || pref.indexOf(filter) == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -990,7 +989,7 @@ function Options() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return prefService.clearUserPref(name);
|
return services.get("pref").clearUserPref(name);
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
@@ -1001,7 +1000,7 @@ function Options() //{{{
|
|||||||
// this works only for booleans
|
// this works only for booleans
|
||||||
invertPref: function (name)
|
invertPref: function (name)
|
||||||
{
|
{
|
||||||
if (prefService.getPrefType(name) == prefService.PREF_BOOL)
|
if (services.get("pref").getPrefType(name) == Ci.nsIPrefBranch.PREF_BOOL)
|
||||||
this.setPref(name, !this.getPref(name));
|
this.setPref(name, !this.getPref(name));
|
||||||
else
|
else
|
||||||
liberator.echoerr("E488: Trailing characters: " + name + "!");
|
liberator.echoerr("E488: Trailing characters: " + name + "!");
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
/** @scope modules */
|
|
||||||
|
|
||||||
let (cc = function (class, iface, meth) { try { return Components.classes[class][meth || "getService"](iface) } catch (e) {} })
|
|
||||||
{
|
|
||||||
// var Ci = Components.interfaces; // quick fix for muttator, will change/remove service.js anyway after the vacation
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cached XPCOM services and instances.
|
|
||||||
*
|
|
||||||
* @singleton
|
|
||||||
*/
|
|
||||||
const service = {
|
|
||||||
appStartup: cc("@mozilla.org/toolkit/app-startup;1", Components.interfaces.nsIAppStartup),
|
|
||||||
autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", Components.interfaces.nsIAutoCompleteSearch),
|
|
||||||
browserSearch: cc("@mozilla.org/browser/search-service;1", Components.interfaces.nsIBrowserSearchService),
|
|
||||||
cache: cc("@mozilla.org/network/cache-service;1", Components.interfaces.nsICacheService),
|
|
||||||
console: cc("@mozilla.org/consoleservice;1", Components.interfaces.nsIConsoleService),
|
|
||||||
directory: cc("@mozilla.org/file/directory_service;1", Components.interfaces.nsIProperties),
|
|
||||||
environment: cc("@mozilla.org/process/environment;1", Components.interfaces.nsIEnvironment),
|
|
||||||
extensionManager: cc("@mozilla.org/extensions/manager;1", Components.interfaces.nsIExtensionManager),
|
|
||||||
json: cc("@mozilla.org/dom/json;1", Components.interfaces.nsIJSON, "createInstance"),
|
|
||||||
observer: cc("@mozilla.org/observer-service;1", Components.interfaces.nsIObserverService),
|
|
||||||
profile: cc("@mozilla.org/toolkit/profile-service;1", Components.interfaces.nsIToolkitProfileService),
|
|
||||||
sessionStore: cc("@mozilla.org/browser/sessionstore;1", Components.interfaces.nsISessionStore),
|
|
||||||
subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", Components.interfaces.mozIJSSubScriptLoader),
|
|
||||||
threadManager: cc("@mozilla.org/thread-manager;1", Components.interfaces.nsIThreadManager),
|
|
||||||
windowMediator: cc("@mozilla.org/appshell/window-mediator;1", Components.interfaces.nsIWindowMediator),
|
|
||||||
windowWatcher: cc("@mozilla.org/embedcomp/window-watcher;1", Components.interfaces.nsIWindowWatcher),
|
|
||||||
getFile: function () Cc["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile),
|
|
||||||
getFind: function () Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Components.interfaces.nsIFind),
|
|
||||||
getProcess: function () Cc["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess)
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
73
common/content/services.js
Normal file
73
common/content/services.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/***** BEGIN LICENSE BLOCK ***** {{{
|
||||||
|
©2008 Kris Maglione <maglione.k at Gmail>
|
||||||
|
Distributable under the terms of the MIT license, which allows
|
||||||
|
for sublicensing under any compatible license, including the MPL,
|
||||||
|
GPL, and MPL. Anyone who changes this file is welcome to relicense
|
||||||
|
it under any or all of those licenseses.
|
||||||
|
}}} ***** END LICENSE BLOCK *****/
|
||||||
|
|
||||||
|
/** @scope modules */
|
||||||
|
|
||||||
|
const Cc = Components.classes;
|
||||||
|
const Ci = Components.interfaces;
|
||||||
|
const Cr = Components.results;
|
||||||
|
const Cu = Components.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cached XPCOM services and instances.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function Services()
|
||||||
|
{
|
||||||
|
const classes = {};
|
||||||
|
const services = {};
|
||||||
|
function create(classes, ifaces, meth)
|
||||||
|
{
|
||||||
|
ifaces = Array.concat(ifaces);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
let res = Cc[classes][meth || "getService"](ifaces.shift())
|
||||||
|
ifaces.forEach(function (iface) res.QueryInterface(iface));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
}
|
||||||
|
const self = {
|
||||||
|
add: function (name, class, ifaces, meth)
|
||||||
|
{
|
||||||
|
return services[name] = create(class, ifaces, meth);
|
||||||
|
},
|
||||||
|
addClass: function (name, class, ifaces)
|
||||||
|
{
|
||||||
|
return classes[name] = function () create(class, ifaces, "createInstance");
|
||||||
|
},
|
||||||
|
get: function (name) services[name],
|
||||||
|
create: function (name) classes[name]()
|
||||||
|
};
|
||||||
|
self.add("appStartup", "@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup);
|
||||||
|
self.add("autoCompleteSearch", "@mozilla.org/browser/global-history;2", Ci.nsIAutoCompleteSearch);
|
||||||
|
self.add("browserSearch", "@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService);
|
||||||
|
self.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService);
|
||||||
|
self.add("console", "@mozilla.org/consoleservice;1", Ci.nsIConsoleService);
|
||||||
|
self.add("directory", "@mozilla.org/file/directory_service;1", Ci.nsIProperties);
|
||||||
|
self.add("environment", "@mozilla.org/process/environment;1", Ci.nsIEnvironment);
|
||||||
|
self.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager);
|
||||||
|
self.add("json", "@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance");
|
||||||
|
self.add("observer", "@mozilla.org/observer-service;1", Ci.nsIObserverService);
|
||||||
|
self.add("pref", "@mozilla.org/preferences-service;1", [Ci.nsIPrefService, Ci.nsIPrefBranch, Ci.nsIPrefBranch2]);
|
||||||
|
self.add("profile", "@mozilla.org/toolkit/profile-service;1", Ci.nsIToolkitProfileService);
|
||||||
|
self.add("sessionStore", "@mozilla.org/browser/sessionstore;1", Ci.nsISessionStore);
|
||||||
|
self.add("subscriptLoader", "@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader);
|
||||||
|
self.add("threadManager", "@mozilla.org/thread-manager;1", Ci.nsIThreadManager);
|
||||||
|
self.add("windowMediator", "@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator);
|
||||||
|
self.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher);
|
||||||
|
|
||||||
|
self.addClass("file", "@mozilla.org/file/local;1", Ci.nsILocalFile);
|
||||||
|
self.addClass("find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
|
||||||
|
self.addClass("process", "@mozilla.org/process/util;1", Ci.nsIProcess);
|
||||||
|
return self;
|
||||||
|
};
|
||||||
|
|
||||||
|
var services = Services();
|
||||||
|
|
||||||
@@ -102,8 +102,8 @@ function Tabs() //{{{
|
|||||||
if (!from)
|
if (!from)
|
||||||
from = getBrowser().mTabContainer.selectedItem;
|
from = getBrowser().mTabContainer.selectedItem;
|
||||||
|
|
||||||
let tabState = service["sessionStore"].getTabState(from);
|
let tabState = services.get("sessionStore").getTabState(from);
|
||||||
service["sessionStore"].setTabState(to, tabState);
|
services.get("sessionStore").setTabState(to, tabState);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hide tabs initially
|
// hide tabs initially
|
||||||
@@ -743,7 +743,7 @@ function Tabs() //{{{
|
|||||||
|
|
||||||
get closedTabs()
|
get closedTabs()
|
||||||
{
|
{
|
||||||
return service["json"].decode(service["sessionStore"].getClosedTabData(window));
|
return services.get("json").decode(services.get("sessionStore").getClosedTabData(window));
|
||||||
},
|
},
|
||||||
|
|
||||||
list: function (filter)
|
list: function (filter)
|
||||||
@@ -970,7 +970,7 @@ function Tabs() //{{{
|
|||||||
tab = getBrowser().mTabContainer.selectedItem;
|
tab = getBrowser().mTabContainer.selectedItem;
|
||||||
|
|
||||||
window.open();
|
window.open();
|
||||||
let win = service["windowMediator"].getMostRecentWindow("navigator:browser");
|
let win = services.get("windowMediator").getMostRecentWindow("navigator:browser");
|
||||||
|
|
||||||
copyTab(win.getBrowser().mCurrentTab, tab);
|
copyTab(win.getBrowser().mCurrentTab, tab);
|
||||||
this.remove(tab, 1, false, 1);
|
this.remove(tab, 1, false, 1);
|
||||||
|
|||||||
@@ -659,8 +659,8 @@ function CommandLine() //{{{
|
|||||||
{
|
{
|
||||||
completer: function completer(value)
|
completer: function completer(value)
|
||||||
{
|
{
|
||||||
let engines = service["browserSearch"].getEngines({})
|
let engines = services.get("browserSearch").getEngines({})
|
||||||
.filter(function (engine) engine.supportsResponseType("application/x-suggestions+json"));
|
.filter(function (engine) engine.supportsResponseType("application/x-suggestions+json"));
|
||||||
|
|
||||||
return engines.map(function (engine) [engine.alias, engine.description]);
|
return engines.map(function (engine) [engine.alias, engine.description]);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ function Bookmarks() //{{{
|
|||||||
const historyService = PlacesUtils.history;
|
const historyService = PlacesUtils.history;
|
||||||
const bookmarksService = PlacesUtils.bookmarks;
|
const bookmarksService = PlacesUtils.bookmarks;
|
||||||
const taggingService = PlacesUtils.tagging;
|
const taggingService = PlacesUtils.tagging;
|
||||||
const searchService = service.browserSearch;
|
|
||||||
const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
|
const faviconService = Cc["@mozilla.org/browser/favicon-service;1"].getService(Ci.nsIFaviconService);
|
||||||
|
|
||||||
const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id");
|
const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id");
|
||||||
@@ -533,7 +532,7 @@ function Bookmarks() //{{{
|
|||||||
getSearchEngines: function getSearchEngines()
|
getSearchEngines: function getSearchEngines()
|
||||||
{
|
{
|
||||||
let searchEngines = [];
|
let searchEngines = [];
|
||||||
let firefoxEngines = searchService.getVisibleEngines({});
|
let firefoxEngines = services.get("browserSearch").getVisibleEngines({});
|
||||||
for (let [,engine] in Iterator(firefoxEngines))
|
for (let [,engine] in Iterator(firefoxEngines))
|
||||||
{
|
{
|
||||||
let alias = engine.alias;
|
let alias = engine.alias;
|
||||||
@@ -563,10 +562,9 @@ function Bookmarks() //{{{
|
|||||||
|
|
||||||
getSuggestions: function getSuggestions(engineName, query, callback)
|
getSuggestions: function getSuggestions(engineName, query, callback)
|
||||||
{
|
{
|
||||||
let ss = service.browserSearch;
|
|
||||||
const responseType = "application/x-suggestions+json";
|
const responseType = "application/x-suggestions+json";
|
||||||
|
|
||||||
let engine = ss.getEngineByAlias(engineName);
|
let engine = services.get("browserSearch").getEngineByAlias(engineName);
|
||||||
if (engine && engine.supportsResponseType(responseType))
|
if (engine && engine.supportsResponseType(responseType))
|
||||||
var queryURI = engine.getSubmission(query, responseType).uri.spec;
|
var queryURI = engine.getSubmission(query, responseType).uri.spec;
|
||||||
if (!queryURI)
|
if (!queryURI)
|
||||||
@@ -574,11 +572,10 @@ function Bookmarks() //{{{
|
|||||||
|
|
||||||
function process(resp)
|
function process(resp)
|
||||||
{
|
{
|
||||||
const json = service.json;
|
|
||||||
let results = [];
|
let results = [];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
results = json.decode(resp.responseText)[1];
|
results = services.get("json").decode(resp.responseText)[1];
|
||||||
results = [[item, ""] for ([k, item] in Iterator(results)) if (typeof item == "string")];
|
results = [[item, ""] for ([k, item] in Iterator(results)) if (typeof item == "string")];
|
||||||
}
|
}
|
||||||
catch (e) {}
|
catch (e) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user