mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 14:27:59 +01:00
Merge branch 'master' into vimperator-2.1
Conflicts: common/content/io.js
This commit is contained in:
@@ -752,7 +752,7 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -1009,7 +1009,7 @@ function Buffer() //{{{
|
|||||||
if (elemTagName == "frame" || elemTagName == "iframe")
|
if (elemTagName == "frame" || elemTagName == "iframe")
|
||||||
{
|
{
|
||||||
elem.contentWindow.focus();
|
elem.contentWindow.focus();
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
elem.focus();
|
elem.focus();
|
||||||
@@ -1110,7 +1110,7 @@ function Buffer() //{{{
|
|||||||
if (localName == "frame" || localName == "iframe") // broken?
|
if (localName == "frame" || localName == "iframe") // broken?
|
||||||
{
|
{
|
||||||
elem.contentWindow.focus();
|
elem.contentWindow.focus();
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
else if (localName == "area") // for imagemap
|
else if (localName == "area") // for imagemap
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -923,7 +923,8 @@ function Commands() //{{{
|
|||||||
[["-bang"], commandManager.OPTION_NOARG],
|
[["-bang"], commandManager.OPTION_NOARG],
|
||||||
[["-count"], commandManager.OPTION_NOARG],
|
[["-count"], commandManager.OPTION_NOARG],
|
||||||
[["-complete"], commandManager.OPTION_STRING,
|
[["-complete"], commandManager.OPTION_STRING,
|
||||||
function (arg) arg in completeOptionMap || /custom,\w+/.test(arg)]
|
function (arg) arg in completeOptionMap || /custom,\w+/.test(arg),
|
||||||
|
function (context) [[k, ''] for ([k, v] in Iterator(completeOptionMap))]]
|
||||||
],
|
],
|
||||||
literal: 1,
|
literal: 1,
|
||||||
serial: function () [
|
serial: function () [
|
||||||
|
|||||||
@@ -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,7 +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 = service["pref"].getChildList("", { value: 0 });
|
context.completions = services.get("pref").getChildList("", { value: 0 });
|
||||||
},
|
},
|
||||||
|
|
||||||
search: function search(context, noSuggest)
|
search: function search(context, noSuggest)
|
||||||
@@ -1702,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) || [];
|
||||||
@@ -1725,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))
|
||||||
|
|||||||
@@ -1143,7 +1143,7 @@ function Events() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
urlbar = document.getElementById("urlbar");
|
urlbar = document.getElementById("urlbar");
|
||||||
if (focus == null && urlbar && urlbar.inputField == lastFocus)
|
if (elem == null && urlbar && urlbar.inputField == lastFocus)
|
||||||
liberator.threadYield(true);
|
liberator.threadYield(true);
|
||||||
|
|
||||||
if (liberator.mode & (modes.INSERT | modes.TEXTAREA | modes.MESSAGE | modes.VISUAL))
|
if (liberator.mode & (modes.INSERT | modes.TEXTAREA | modes.MESSAGE | modes.VISUAL))
|
||||||
@@ -1644,8 +1644,8 @@ function Events() //{{{
|
|||||||
prefObserver: {
|
prefObserver: {
|
||||||
register: function ()
|
register: function ()
|
||||||
{
|
{
|
||||||
this._branch = service["pref"].getBranch("") // better way to monitor all changes?
|
// better way to monitor all changes?
|
||||||
.QueryInterface(Ci.nsIPrefBranch2);
|
this._branch = services.get("pref").getBranch("").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;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const win = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|||||||
const liberator = win.liberator;
|
const liberator = win.liberator;
|
||||||
|
|
||||||
let page = liberator.findHelp(decodeURIComponent(document.location.search.substr(1)));
|
let page = liberator.findHelp(decodeURIComponent(document.location.search.substr(1)));
|
||||||
let url = "chrome://liberator/locale/" + page;
|
let url = page ? "chrome://liberator/locale/" + page : content.history.previous;
|
||||||
|
|
||||||
win.getBrowser().loadURIWithFlags(url, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY, null, null, null);
|
win.getBrowser().loadURIWithFlags(url, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY, null, null, null);
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ function Hints() //{{{
|
|||||||
T: Mode("Open new tab based on hint", function (elem, loc) commandline.open(":", "tabopen " + loc, modes.EX)),
|
T: Mode("Open new tab based on hint", function (elem, loc) commandline.open(":", "tabopen " + loc, modes.EX)),
|
||||||
W: Mode("Open new window based on hint", function (elem, loc) commandline.open(":", "winopen " + loc, modes.EX)),
|
W: Mode("Open new window based on hint", function (elem, loc) commandline.open(":", "winopen " + loc, modes.EX)),
|
||||||
y: Mode("Yank hint location", function (elem, loc) util.copyToClipboard(loc, true)),
|
y: Mode("Yank hint location", function (elem, loc) util.copyToClipboard(loc, true)),
|
||||||
Y: Mode("Yank hint description", function (elem) util.copyToClipboard(elem.textContent || "", true), extended),
|
Y: Mode("Yank hint description", function (elem) util.copyToClipboard(elem.textContent || "", true), extended)
|
||||||
};
|
};
|
||||||
|
|
||||||
// reset all important variables
|
// reset all important variables
|
||||||
@@ -527,7 +527,7 @@ function Hints() //{{{
|
|||||||
////////////////////// OPTIONS /////////////////////////////////////////////////
|
////////////////////// OPTIONS /////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
const DEFAULT_HINTTAGS = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s' or @role='link'] | " +
|
const DEFAULT_HINTTAGS = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @role='link'] | " +
|
||||||
"//input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select | " +
|
"//input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select | " +
|
||||||
"//xhtml:input[not(@type='hidden')] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select";
|
"//xhtml:input[not(@type='hidden')] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | //xhtml:button | //xhtml:select";
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,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);
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -76,7 +76,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)
|
||||||
@@ -88,7 +88,7 @@ function IO() //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shell = service["environment"].get("SHELL") || "sh";
|
shell = services.get("environment").get("SHELL") || "sh";
|
||||||
shellcmdflag = "-c";
|
shellcmdflag = "-c";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ function IO() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
service.getFile().initWithPath(path);
|
services.create("file").initWithPath(path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
@@ -473,7 +473,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))
|
||||||
{
|
{
|
||||||
@@ -514,7 +514,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);
|
||||||
|
|
||||||
@@ -620,7 +620,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);
|
||||||
@@ -638,7 +638,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);
|
||||||
@@ -657,7 +657,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);
|
||||||
@@ -771,7 +771,7 @@ lookup:
|
|||||||
liberator.echomsg("sourcing " + filename.quote(), 2);
|
liberator.echomsg("sourcing " + filename.quote(), 2);
|
||||||
|
|
||||||
let str = ioManager.readFile(file);
|
let str = ioManager.readFile(file);
|
||||||
let uri = service["io"].newFileURI(file);
|
let uri = ioService.newFileURI(file);
|
||||||
|
|
||||||
// handle pure javascript files specially
|
// handle pure javascript files specially
|
||||||
if (/\.js$/.test(filename))
|
if (/\.js$/.test(filename))
|
||||||
@@ -863,7 +863,7 @@ lookup:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// execute a normal liberator command
|
// execute a normal liberator command
|
||||||
liberator.execute(line);
|
liberator.execute(line, null, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -936,20 +936,20 @@ 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);
|
||||||
|
|
||||||
// expand ~
|
// expand ~
|
||||||
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)
|
||||||
{
|
{
|
||||||
hread = thread || service["threadManager"].newThread(0);
|
thread = thread || services.get("threadManager").newThread(0);
|
||||||
thread.dispatch(new Runnable(self, func, Array.slice(arguments, 2)), 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)
|
||||||
@@ -861,7 +856,7 @@ const liberator = (function () //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Execute an Ex command like str=":zoom 300"
|
// Execute an Ex command like str=":zoom 300"
|
||||||
execute: function (str, modifiers)
|
execute: function (str, modifiers, silent)
|
||||||
{
|
{
|
||||||
// skip comments and blank lines
|
// skip comments and blank lines
|
||||||
if (/^\s*("|$)/.test(str))
|
if (/^\s*("|$)/.test(str))
|
||||||
@@ -893,6 +888,7 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return liberator.echoerr(err);
|
return liberator.echoerr(err);
|
||||||
|
if (!silent)
|
||||||
commandline.command = str.replace(/^\s*:\s*/, "");
|
commandline.command = str.replace(/^\s*:\s*/, "");
|
||||||
command.execute(args, special, count, modifiers);
|
command.execute(args, special, count, modifiers);
|
||||||
},
|
},
|
||||||
@@ -901,7 +897,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 +930,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);
|
||||||
},
|
},
|
||||||
@@ -950,7 +946,7 @@ const liberator = (function () //{{{
|
|||||||
{
|
{
|
||||||
if (item[0] == topic)
|
if (item[0] == topic)
|
||||||
return format(item);
|
return format(item);
|
||||||
else if (partialMatch == -1 && item[0].indexOf(topic) > -1)
|
else if (!partialMatch && item[0].indexOf(topic) > -1)
|
||||||
{
|
{
|
||||||
partialMatch = item;
|
partialMatch = item;
|
||||||
}
|
}
|
||||||
@@ -1053,7 +1049,8 @@ const liberator = (function () //{{{
|
|||||||
if (typeof msg == "object")
|
if (typeof msg == "object")
|
||||||
msg = util.objectToString(msg, false);
|
msg = util.objectToString(msg, false);
|
||||||
|
|
||||||
service["console"].logStringMessage(config.name.toLowerCase() + ": " + msg);
|
const consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
|
||||||
|
consoleService.logStringMessage(config.name.toLowerCase() + ": " + msg);
|
||||||
},
|
},
|
||||||
|
|
||||||
// open one or more URLs
|
// open one or more URLs
|
||||||
@@ -1111,7 +1108,7 @@ 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;
|
||||||
|
|
||||||
@@ -1153,7 +1150,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();
|
||||||
},
|
},
|
||||||
@@ -1183,24 +1180,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
|
||||||
@@ -1227,10 +1224,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)
|
||||||
@@ -1279,7 +1276,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
|
||||||
@@ -1336,7 +1333,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)
|
||||||
@@ -1346,8 +1343,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);
|
||||||
@@ -1355,7 +1352,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
|
||||||
{
|
{
|
||||||
@@ -1395,7 +1392,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());
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ const modes = (function () //{{{
|
|||||||
options.setPref("accessibility.browsewithcaret", false);
|
options.setPref("accessibility.browsewithcaret", false);
|
||||||
|
|
||||||
statusline.updateUrl();
|
statusline.updateUrl();
|
||||||
liberator.focusContent(false);
|
liberator.focusContent(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ Option.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
get values() this.parseValues(this.value),
|
get values() this.parseValues(this.value),
|
||||||
set values(values) this.setValues(this.scope, values),
|
set values(values) this.setValues(values, this.scope),
|
||||||
|
|
||||||
getValues: function (scope) this.parseValues(this.get(scope)),
|
getValues: function (scope) this.parseValues(this.get(scope)),
|
||||||
|
|
||||||
@@ -330,27 +330,27 @@ function Options() //{{{
|
|||||||
prefContexts[prefContexts.length - 1][name] = val;
|
prefContexts[prefContexts.length - 1][name] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
let type = service["pref"].getPrefType(name);
|
let type = services.get("pref").getPrefType(name);
|
||||||
switch (typeof value)
|
switch (typeof value)
|
||||||
{
|
{
|
||||||
case "string":
|
case "string":
|
||||||
if (type == service["pref"].PREF_INVALID || type == service["pref"].PREF_STRING)
|
if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_STRING)
|
||||||
service["pref"].setCharPref(name, value);
|
services.get("pref").setCharPref(name, value);
|
||||||
else if (type == service["pref"].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 == service["pref"].PREF_INVALID || type == service["pref"].PREF_INT)
|
if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_INT)
|
||||||
service["pref"].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 == service["pref"].PREF_INVALID || type == service["pref"].PREF_BOOL)
|
if (type == Ci.nsIPrefBranch.PREF_INVALID || type == Ci.nsIPrefBranch.PREF_BOOL)
|
||||||
service["pref"].setBoolPref(name, value);
|
services.get("pref").setBoolPref(name, value);
|
||||||
else if (type == service["pref"].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);
|
||||||
@@ -366,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 ? service["pref"].getDefaultBranch("") : service["pref"];
|
let branch = defaultBranch ? services.get("pref").getDefaultBranch("") : services.get("pref");
|
||||||
let type = service["pref"].getPrefType(name);
|
let type = services.get("pref").getPrefType(name);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case service["pref"].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 (!service["pref"].prefIsLocked(name) && !service["pref"].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 service["pref"].PREF_INT:
|
case Ci.nsIPrefBranch.PREF_INT:
|
||||||
return branch.getIntPref(name);
|
return branch.getIntPref(name);
|
||||||
case service["pref"].PREF_BOOL:
|
case Ci.nsIPrefBranch.PREF_BOOL:
|
||||||
return branch.getBoolPref(name);
|
return branch.getBoolPref(name);
|
||||||
default:
|
default:
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
@@ -741,8 +741,8 @@ function Options() //{{{
|
|||||||
serial: function () [
|
serial: function () [
|
||||||
{
|
{
|
||||||
command: this.name,
|
command: this.name,
|
||||||
literalArg: opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name
|
arguments: [opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name
|
||||||
: opt.name + "=" + opt.value
|
: opt.name + "=" + opt.value]
|
||||||
}
|
}
|
||||||
for (opt in options)
|
for (opt in options)
|
||||||
if (!opt.getter && opt.value != opt.defaultValue && (opt.scope & options.OPTION_SCOPE_GLOBAL))
|
if (!opt.getter && opt.value != opt.defaultValue && (opt.scope & options.OPTION_SCOPE_GLOBAL))
|
||||||
@@ -786,7 +786,8 @@ 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 () service["pref"].getChildList("", { value: 0 })
|
[function () services.get("pref")
|
||||||
|
.getChildList("", { value: 0 })
|
||||||
.map(function (pref) [pref, ""])]);
|
.map(function (pref) [pref, ""])]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -888,12 +889,12 @@ function Options() //{{{
|
|||||||
if (!filter)
|
if (!filter)
|
||||||
filter = "";
|
filter = "";
|
||||||
|
|
||||||
let prefArray = service["pref"].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 = service["pref"].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;
|
||||||
|
|
||||||
@@ -986,13 +987,20 @@ function Options() //{{{
|
|||||||
|
|
||||||
resetPref: function (name)
|
resetPref: function (name)
|
||||||
{
|
{
|
||||||
return service["pref"].clearUserPref(name);
|
try
|
||||||
|
{
|
||||||
|
return services.get("pref").clearUserPref(name);
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
// ignore - thrown if not a user set value
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// this works only for booleans
|
// this works only for booleans
|
||||||
invertPref: function (name)
|
invertPref: function (name)
|
||||||
{
|
{
|
||||||
if (service["pref"].getPrefType(name) == service["pref"].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 + "!");
|
||||||
@@ -1020,7 +1028,7 @@ function Options() //{{{
|
|||||||
{
|
{
|
||||||
this.popContext();
|
this.popContext();
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
//}}}
|
//}}}
|
||||||
}; //}}}
|
}; //}}}
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
/** @scope modules */
|
|
||||||
|
|
||||||
let (cc = function (class, iface, meth) { try { return Cc[class][meth || "getService"](iface) } catch (e) {} })
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Cached XPCOM services and instances.
|
|
||||||
*
|
|
||||||
* @singleton
|
|
||||||
*/
|
|
||||||
const service = {
|
|
||||||
appStartup: cc("@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup),
|
|
||||||
autoCompleteSearch: cc("@mozilla.org/browser/global-history;2", Ci.nsIAutoCompleteSearch),
|
|
||||||
browserSearch: cc("@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService),
|
|
||||||
cache: cc("@mozilla.org/network/cache-service;1", Ci.nsICacheService),
|
|
||||||
console: cc("@mozilla.org/consoleservice;1", Ci.nsIConsoleService),
|
|
||||||
directory: cc("@mozilla.org/file/directory_service;1", Ci.nsIProperties),
|
|
||||||
environment: cc("@mozilla.org/process/environment;1", Ci.nsIEnvironment),
|
|
||||||
extensionManager: cc("@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager),
|
|
||||||
io: cc("@mozilla.org/network/io-service;1", Ci.nsIIOService).QueryInterface(Ci.nsIIOService2),
|
|
||||||
json: cc("@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance"),
|
|
||||||
observer: cc("@mozilla.org/observer-service;1", Ci.nsIObserverService),
|
|
||||||
profile: cc("@mozilla.org/toolkit/profile-service;1", Ci.nsIToolkitProfileService),
|
|
||||||
pref: cc("@mozilla.org/preferences-service;1", Ci.nsIPrefService)
|
|
||||||
.QueryInterface(Ci.nsIPrefBranch).QueryInterface(Ci.nsIPrefBranch2),
|
|
||||||
sessionStore: cc("@mozilla.org/browser/sessionstore;1", Ci.nsISessionStore),
|
|
||||||
subscriptLoader: cc("@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader),
|
|
||||||
threadManager: cc("@mozilla.org/thread-manager;1", Ci.nsIThreadManager),
|
|
||||||
windowMediator: cc("@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator),
|
|
||||||
windowWatcher: cc("@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher),
|
|
||||||
getFile: function () Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile),
|
|
||||||
getFind: function () Cc["@mozilla.org/embedcomp/rangefind;1"].createInstance(Ci.nsIFind),
|
|
||||||
getProcess: function () Cc["@mozilla.org/process/util;1"].createInstance(Ci.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();
|
||||||
|
|
||||||
@@ -135,9 +135,9 @@ Highlights.prototype.CSS = <![CDATA[
|
|||||||
*/
|
*/
|
||||||
function Highlights(name, store, serial)
|
function Highlights(name, store, serial)
|
||||||
{
|
{
|
||||||
var self = this;
|
let self = this;
|
||||||
var highlight = {};
|
let highlight = {};
|
||||||
var styles = storage.styles;
|
let styles = storage.styles;
|
||||||
|
|
||||||
const Highlight = Struct("class", "selector", "filter", "default", "value");
|
const Highlight = Struct("class", "selector", "filter", "default", "value");
|
||||||
Highlight.defaultValue("filter", function () "chrome://liberator/content/buffer.xhtml" + "," + config.styleableChrome);
|
Highlight.defaultValue("filter", function () "chrome://liberator/content/buffer.xhtml" + "," + config.styleableChrome);
|
||||||
@@ -248,8 +248,8 @@ function Styles(name, store, serial)
|
|||||||
const util = modules.util;
|
const util = modules.util;
|
||||||
const sleep = liberator.sleep;
|
const sleep = liberator.sleep;
|
||||||
const storage = modules.storage;
|
const storage = modules.storage;
|
||||||
const consoleService = service["console"];
|
const consoleService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
|
||||||
const ios = service["io"];
|
const ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||||
const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
|
const sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
|
||||||
const namespace = '@namespace html "' + XHTML + '";\n' +
|
const namespace = '@namespace html "' + XHTML + '";\n' +
|
||||||
'@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' +
|
'@namespace xul "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";\n' +
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -123,7 +123,7 @@ function Tabs() //{{{
|
|||||||
let tabStrip = tabs.tabStrip;
|
let tabStrip = tabs.tabStrip;
|
||||||
|
|
||||||
if (!tabStrip)
|
if (!tabStrip)
|
||||||
return;
|
return options['showtabline']; // XXX
|
||||||
|
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
{
|
{
|
||||||
@@ -463,7 +463,7 @@ function Tabs() //{{{
|
|||||||
"Switch to a buffer",
|
"Switch to a buffer",
|
||||||
function (args)
|
function (args)
|
||||||
{
|
{
|
||||||
let special = args.special;
|
let special = args.bang;
|
||||||
let count = args.count;
|
let count = args.count;
|
||||||
let arg = args.literalArg;
|
let arg = args.literalArg;
|
||||||
|
|
||||||
@@ -689,10 +689,14 @@ function Tabs() //{{{
|
|||||||
|
|
||||||
get tabStrip()
|
get tabStrip()
|
||||||
{
|
{
|
||||||
|
let tabStrip = null;
|
||||||
|
|
||||||
if (config.hostApplication == "Firefox")
|
if (config.hostApplication == "Firefox")
|
||||||
return getBrowser().mStrip.getElementsByClassName("tabbrowser-tabs")[0];
|
tabStrip = getBrowser().mStrip.getElementsByClassName("tabbrowser-tabs")[0];
|
||||||
else if (config.hostApplication == "Thunderbird")
|
else if (config.hostApplication == "Thunderbird")
|
||||||
return getBrowser().mStrip;
|
tabStrip = getBrowser().mStrip;
|
||||||
|
|
||||||
|
return tabStrip;
|
||||||
},
|
},
|
||||||
|
|
||||||
// @returns the index of the currently selected tab starting with 0
|
// @returns the index of the currently selected tab starting with 0
|
||||||
@@ -739,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)
|
||||||
@@ -966,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);
|
||||||
|
|||||||
@@ -518,8 +518,7 @@ function CommandLine() //{{{
|
|||||||
|
|
||||||
// Whether the command line must be open.
|
// Whether the command line must be open.
|
||||||
function commandShown() modes.main == modes.COMMAND_LINE &&
|
function commandShown() modes.main == modes.COMMAND_LINE &&
|
||||||
!(modes.extended & modes.INPUT_MULTILINE) &&
|
!(modes.extended & (modes.INPUT_MULTILINE | modes.OUTPUT_MULTILINE));
|
||||||
!(modes.extended & modes.OUTPUT_MULTILINE);
|
|
||||||
|
|
||||||
// sets the prompt - for example, : or /
|
// sets the prompt - for example, : or /
|
||||||
function setPrompt(val, highlightGroup)
|
function setPrompt(val, highlightGroup)
|
||||||
@@ -603,7 +602,7 @@ function CommandLine() //{{{
|
|||||||
{
|
{
|
||||||
let lines = multilineInputWidget.value.split("\n").length - 1;
|
let lines = multilineInputWidget.value.split("\n").length - 1;
|
||||||
|
|
||||||
multilineInputWidget.setAttribute("rows", Math.min(lines, 1));
|
multilineInputWidget.setAttribute("rows", Math.max(lines, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for the :echo[err] commands
|
// used for the :echo[err] commands
|
||||||
@@ -660,7 +659,7 @@ 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]);
|
||||||
@@ -1047,8 +1046,11 @@ function CommandLine() //{{{
|
|||||||
// @param untilRegexp
|
// @param untilRegexp
|
||||||
inputMultiline: function inputMultiline(untilRegexp, callbackFunc)
|
inputMultiline: function inputMultiline(untilRegexp, callbackFunc)
|
||||||
{
|
{
|
||||||
// save the mode, because we need to restore it
|
// Kludge.
|
||||||
|
let cmd = !commandWidget.collapsed && this.command;
|
||||||
modes.push(modes.COMMAND_LINE, modes.INPUT_MULTILINE);
|
modes.push(modes.COMMAND_LINE, modes.INPUT_MULTILINE);
|
||||||
|
if (cmd != false)
|
||||||
|
echoLine(cmd, this.HL_NORMAL);
|
||||||
|
|
||||||
// save the arguments, they are needed in the event handler onEvent
|
// save the arguments, they are needed in the event handler onEvent
|
||||||
multilineRegexp = untilRegexp;
|
multilineRegexp = untilRegexp;
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ const util = { //{{{
|
|||||||
* Returns a shallow copy of <b>obj</b>.
|
* Returns a shallow copy of <b>obj</b>.
|
||||||
*
|
*
|
||||||
* @param {Object} obj
|
* @param {Object} obj
|
||||||
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
cloneObject: function cloneObject(obj)
|
cloneObject: function cloneObject(obj)
|
||||||
{
|
{
|
||||||
@@ -335,6 +336,12 @@ const util = { //{{{
|
|||||||
return ary;
|
return ary;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
newURI: function (url)
|
||||||
|
{
|
||||||
|
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||||
|
return ioService.newURI(url, null, null);
|
||||||
|
},
|
||||||
|
|
||||||
// if color = true it uses HTML markup to color certain items
|
// if color = true it uses HTML markup to color certain items
|
||||||
objectToString: function objectToString(object, color)
|
objectToString: function objectToString(object, color)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -311,11 +311,22 @@ var storage = {
|
|||||||
|
|
||||||
addObserver: function addObserver(key, callback, ref)
|
addObserver: function addObserver(key, callback, ref)
|
||||||
{
|
{
|
||||||
|
if (ref)
|
||||||
|
{
|
||||||
|
if (!ref.liberatorStorageRefs)
|
||||||
|
ref.liberatorStorageRefs = [];
|
||||||
|
ref.liberatorStorageRefs.push(callback);
|
||||||
|
var callbackRef = Cu.getWeakReference(callback);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
callbackRef = { get: function () callback };
|
||||||
|
}
|
||||||
this.removeDeadObservers();
|
this.removeDeadObservers();
|
||||||
if (!(key in observers))
|
if (!(key in observers))
|
||||||
observers[key] = [];
|
observers[key] = [];
|
||||||
if (observers[key].indexOf(callback) == -1)
|
if (!observers[key].some(function (o) o.callback.get() == callback))
|
||||||
observers[key].push({ ref: ref && Cu.getWeakReference(ref), callback: callback });
|
observers[key].push({ ref: ref && Cu.getWeakReference(ref), callback: callbackRef });
|
||||||
},
|
},
|
||||||
|
|
||||||
removeObserver: function (key, callback)
|
removeObserver: function (key, callback)
|
||||||
@@ -323,7 +334,7 @@ var storage = {
|
|||||||
this.removeDeadObservers();
|
this.removeDeadObservers();
|
||||||
if (!(key in observers))
|
if (!(key in observers))
|
||||||
return;
|
return;
|
||||||
observers[key] = observers[key].filter(function (elem) elem.callback != callback);
|
observers[key] = observers[key].filter(function (elem) elem.callback.get() != callback);
|
||||||
if (observers[key].length == 0)
|
if (observers[key].length == 0)
|
||||||
delete obsevers[key];
|
delete obsevers[key];
|
||||||
},
|
},
|
||||||
@@ -332,18 +343,20 @@ var storage = {
|
|||||||
{
|
{
|
||||||
for (let [key, ary] in Iterator(observers))
|
for (let [key, ary] in Iterator(observers))
|
||||||
{
|
{
|
||||||
observers[key] = ary = ary.filter(function (o) !o.ref || o.ref.get());
|
observers[key] = ary = ary.filter(function (o) o.callback.get() && (!o.ref || o.ref.get() && o.ref.get().liberatorStorageRefs))
|
||||||
if (!ary.length)
|
if (!ary.length)
|
||||||
delete observers[key];
|
delete observers[key];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get observers() observers,
|
||||||
|
|
||||||
fireEvent: function fireEvent(key, event, arg)
|
fireEvent: function fireEvent(key, event, arg)
|
||||||
{
|
{
|
||||||
this.removeDeadObservers();
|
this.removeDeadObservers();
|
||||||
// Safe, since we have our own Array object here.
|
// Safe, since we have our own Array object here.
|
||||||
for each (let observer in observers[key])
|
for each (let observer in observers[key])
|
||||||
observer.callback(key, event, arg);
|
observer.callback.get()(key, event, arg);
|
||||||
timers[key].tell();
|
timers[key].tell();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -28,26 +28,26 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
|||||||
|
|
||||||
const DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png";
|
const DEFAULT_FAVICON = "chrome://mozapps/skin/places/defaultFavicon.png";
|
||||||
|
|
||||||
if (liberator.options.getPref("extensions.vimperator.commandline_cmd_history"))
|
// Try to import older command line history, quick marks, etc.
|
||||||
{
|
liberator.registerObserver("load_options", function () {
|
||||||
// Try to import older command line history, quick marks, etc.
|
if (!options.getPref("extensions.vimperator.commandline_cmd_history"))
|
||||||
liberator.registerObserver("load_options", function () {
|
return;
|
||||||
let store = liberator.storage["history-command"];
|
|
||||||
let pref = liberator.options.getPref("extensions.vimperator.commandline_cmd_history");
|
let store = storage["history-command"];
|
||||||
|
let pref = options.getPref("extensions.vimperator.commandline_cmd_history");
|
||||||
for (let [k, v] in Iterator(pref.split("\n")))
|
for (let [k, v] in Iterator(pref.split("\n")))
|
||||||
store.push(v);
|
store.push(v);
|
||||||
|
|
||||||
store = liberator.storage["quickmarks"];
|
store = storage["quickmarks"];
|
||||||
pref = liberator.options.getPref("extensions.vimperator.quickmarks")
|
pref = options.getPref("extensions.vimperator.quickmarks")
|
||||||
.split("\n");
|
.split("\n");
|
||||||
while (pref.length > 0)
|
while (pref.length > 0)
|
||||||
store.set(pref.shift(), pref.shift());
|
store.set(pref.shift(), pref.shift());
|
||||||
|
|
||||||
liberator.options.resetPref("extensions.vimperator.commandline_cmd_history");
|
options.resetPref("extensions.vimperator.commandline_cmd_history");
|
||||||
liberator.options.resetPref("extensions.vimperator.commandline_search_history");
|
options.resetPref("extensions.vimperator.commandline_search_history");
|
||||||
liberator.options.resetPref("extensions.vimperator.quickmarks");
|
options.resetPref("extensions.vimperator.quickmarks");
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// also includes methods for dealing with keywords and search engines
|
// also includes methods for dealing with keywords and search engines
|
||||||
function Bookmarks() //{{{
|
function Bookmarks() //{{{
|
||||||
@@ -59,8 +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 ioService = service.io;
|
|
||||||
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");
|
||||||
@@ -77,8 +75,8 @@ function Bookmarks() //{{{
|
|||||||
const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder];
|
const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder];
|
||||||
const sleep = liberator.sleep;
|
const sleep = liberator.sleep;
|
||||||
|
|
||||||
var bookmarks = [];
|
let bookmarks = [];
|
||||||
var self = this;
|
let self = this;
|
||||||
|
|
||||||
this.__defineGetter__("name", function () name);
|
this.__defineGetter__("name", function () name);
|
||||||
this.__defineGetter__("store", function () store);
|
this.__defineGetter__("store", function () store);
|
||||||
@@ -91,11 +89,14 @@ function Bookmarks() //{{{
|
|||||||
|
|
||||||
function loadBookmark(node)
|
function loadBookmark(node)
|
||||||
{
|
{
|
||||||
let uri = ioService.newURI(node.uri, null, null);
|
let uri = util.newURI(node.uri);
|
||||||
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
let keyword = bookmarksService.getKeywordForBookmark(node.itemId);
|
||||||
let tags = taggingService.getTagsForURI(uri, {}) || [];
|
let tags = taggingService.getTagsForURI(uri, {}) || [];
|
||||||
|
let bmark = new Bookmark(node.uri, node.title, node.icon && node.icon.spec, keyword, tags, node.itemId);
|
||||||
|
|
||||||
return bookmarks.push(new Bookmark(node.uri, node.title, node.icon && node.icon.spec, keyword, tags, node.itemId));
|
bookmarks.push(bmark);
|
||||||
|
|
||||||
|
return bmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readBookmark(id)
|
function readBookmark(id)
|
||||||
@@ -109,7 +110,7 @@ function Bookmarks() //{{{
|
|||||||
|
|
||||||
function deleteBookmark(id)
|
function deleteBookmark(id)
|
||||||
{
|
{
|
||||||
var length = bookmarks.length;
|
let length = bookmarks.length;
|
||||||
bookmarks = bookmarks.filter(function (item) item.id != id);
|
bookmarks = bookmarks.filter(function (item) item.id != id);
|
||||||
return bookmarks.length < length;
|
return bookmarks.length < length;
|
||||||
}
|
}
|
||||||
@@ -195,11 +196,11 @@ function Bookmarks() //{{{
|
|||||||
if (isAnnotation)
|
if (isAnnotation)
|
||||||
return;
|
return;
|
||||||
// liberator.dump("onItemChanged(" + itemId + ", " + property + ", " + value + ")\n");
|
// liberator.dump("onItemChanged(" + itemId + ", " + property + ", " + value + ")\n");
|
||||||
var bookmark = bookmarks.filter(function (item) item.id == itemId)[0];
|
let bookmark = bookmarks.filter(function (item) item.id == itemId)[0];
|
||||||
if (bookmark)
|
if (bookmark)
|
||||||
{
|
{
|
||||||
if (property == "tags")
|
if (property == "tags")
|
||||||
value = taggingService.getTagsForURI(ioService.newURI(bookmark.url, null, null), {});
|
value = taggingService.getTagsForURI(util.newURI(bookmark.url), {});
|
||||||
if (property in bookmark)
|
if (property in bookmark)
|
||||||
bookmark[property] = value;
|
bookmark[property] = value;
|
||||||
storage.fireEvent(name, "change", itemId);
|
storage.fireEvent(name, "change", itemId);
|
||||||
@@ -220,7 +221,7 @@ function Bookmarks() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec;
|
return faviconService.getFaviconImageForPage(util.newURI(uri)).spec;
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
@@ -277,7 +278,7 @@ function Bookmarks() //{{{
|
|||||||
"Open a prompt to bookmark the current URL",
|
"Open a prompt to bookmark the current URL",
|
||||||
function ()
|
function ()
|
||||||
{
|
{
|
||||||
var title = "";
|
let title = "";
|
||||||
if (buffer.title != buffer.URL)
|
if (buffer.title != buffer.URL)
|
||||||
title = " -title=\"" + buffer.title + "\"";
|
title = " -title=\"" + buffer.title + "\"";
|
||||||
commandline.open(":", "bmark " + buffer.URL + title, modes.EX);
|
commandline.open(":", "bmark " + buffer.URL + title, modes.EX);
|
||||||
@@ -295,7 +296,7 @@ function Bookmarks() //{{{
|
|||||||
"Show jumplist",
|
"Show jumplist",
|
||||||
function ()
|
function ()
|
||||||
{
|
{
|
||||||
var sh = window.getWebNavigation().sessionHistory;
|
let sh = window.getWebNavigation().sessionHistory;
|
||||||
|
|
||||||
let entries = [sh.getEntryAtIndex(i, false) for (i in util.range(0, sh.count))];
|
let entries = [sh.getEntryAtIndex(i, false) for (i in util.range(0, sh.count))];
|
||||||
let list = template.jumps(sh.index, entries);
|
let list = template.jumps(sh.index, entries);
|
||||||
@@ -338,10 +339,10 @@ function Bookmarks() //{{{
|
|||||||
"Add a bookmark",
|
"Add a bookmark",
|
||||||
function (args)
|
function (args)
|
||||||
{
|
{
|
||||||
var url = args.length == 0 ? buffer.URL : args[0];
|
let url = args.length == 0 ? buffer.URL : args[0];
|
||||||
var title = args["-title"] || (args.length == 0 ? buffer.title : null);
|
let title = args["-title"] || (args.length == 0 ? buffer.title : null);
|
||||||
var keyword = args["-keyword"] || null;
|
let keyword = args["-keyword"] || null;
|
||||||
var tags = args["-tags"] || [];
|
let tags = args["-tags"] || [];
|
||||||
|
|
||||||
if (bookmarks.add(false, title, url, keyword, tags, args.bang))
|
if (bookmarks.add(false, title, url, keyword, tags, args.bang))
|
||||||
{
|
{
|
||||||
@@ -427,7 +428,7 @@ function Bookmarks() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var uri = util.createURI(url);
|
let uri = util.createURI(url);
|
||||||
if (!force)
|
if (!force)
|
||||||
{
|
{
|
||||||
for (let bmark in cache)
|
for (let bmark in cache)
|
||||||
@@ -467,15 +468,15 @@ function Bookmarks() //{{{
|
|||||||
if (!url)
|
if (!url)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var count = this.remove(url);
|
let count = this.remove(url);
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
commandline.echo("Removed bookmark: " + url, commandline.HL_NORMAL, commandline.FORCE_SINGLELINE);
|
commandline.echo("Removed bookmark: " + url, commandline.HL_NORMAL, commandline.FORCE_SINGLELINE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var title = buffer.title || url;
|
let title = buffer.title || url;
|
||||||
var extra = "";
|
let extra = "";
|
||||||
if (title != url)
|
if (title != url)
|
||||||
extra = " (" + title + ")";
|
extra = " (" + title + ")";
|
||||||
this.add(true, title, url);
|
this.add(true, title, url);
|
||||||
@@ -487,7 +488,7 @@ function Bookmarks() //{{{
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var uri = ioService.newURI(url, null, null);
|
let uri = util.newURI(url);
|
||||||
return (bookmarksService.getBookmarkedURIFor(uri) != null);
|
return (bookmarksService.getBookmarkedURIFor(uri) != null);
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
@@ -502,12 +503,12 @@ function Bookmarks() //{{{
|
|||||||
if (!url)
|
if (!url)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
var i = 0;
|
let i = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var uri = ioService.newURI(url, null, null);
|
let uri = util.newURI(url);
|
||||||
var count = {};
|
var count = {};
|
||||||
var bmarks = bookmarksService.getBookmarkIdsForURI(uri, count);
|
let bmarks = bookmarksService.getBookmarkIdsForURI(uri, count);
|
||||||
|
|
||||||
for (; i < bmarks.length; i++)
|
for (; i < bmarks.length; i++)
|
||||||
bookmarksService.removeItem(bmarks[i]);
|
bookmarksService.removeItem(bmarks[i]);
|
||||||
@@ -530,18 +531,18 @@ function Bookmarks() //{{{
|
|||||||
// also ensures that each search engine has a Vimperator-friendly alias
|
// also ensures that each search engine has a Vimperator-friendly alias
|
||||||
getSearchEngines: function getSearchEngines()
|
getSearchEngines: function getSearchEngines()
|
||||||
{
|
{
|
||||||
var searchEngines = [];
|
let searchEngines = [];
|
||||||
var firefoxEngines = searchService.getVisibleEngines({});
|
let firefoxEngines = services.get("browserSearch").getVisibleEngines({});
|
||||||
for (let [,engine] in Iterator(firefoxEngines))
|
for (let [,engine] in Iterator(firefoxEngines))
|
||||||
{
|
{
|
||||||
var alias = engine.alias;
|
let alias = engine.alias;
|
||||||
if (!alias || !/^[a-z0-9_-]+$/.test(alias))
|
if (!alias || !/^[a-z0-9_-]+$/.test(alias))
|
||||||
alias = engine.name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
|
alias = engine.name.replace(/^\W*([a-zA-Z_-]+).*/, "$1").toLowerCase();
|
||||||
if (!alias)
|
if (!alias)
|
||||||
alias = "search"; // for search engines which we can't find a suitable alias
|
alias = "search"; // for search engines which we can't find a suitable alias
|
||||||
|
|
||||||
// make sure we can use search engines which would have the same alias (add numbers at the end)
|
// make sure we can use search engines which would have the same alias (add numbers at the end)
|
||||||
var newAlias = alias;
|
let newAlias = alias;
|
||||||
for (let j = 1; j <= 10; j++) // <=10 is intentional
|
for (let j = 1; j <= 10; j++) // <=10 is intentional
|
||||||
{
|
{
|
||||||
if (!searchEngines.some(function (item) item[0] == newAlias))
|
if (!searchEngines.some(function (item) item[0] == newAlias))
|
||||||
@@ -553,7 +554,7 @@ function Bookmarks() //{{{
|
|||||||
if (engine.alias != newAlias)
|
if (engine.alias != newAlias)
|
||||||
engine.alias = newAlias;
|
engine.alias = newAlias;
|
||||||
|
|
||||||
searchEngines.push([engine.alias, engine.description, engine.iconURI.spec]);
|
searchEngines.push([engine.alias, engine.description, engine.iconURI && engine.iconURI.spec]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return searchEngines;
|
return searchEngines;
|
||||||
@@ -561,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)
|
||||||
@@ -572,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) {}
|
||||||
@@ -604,9 +603,9 @@ function Bookmarks() //{{{
|
|||||||
// if the search also requires a postData, [url, postData] is returned
|
// if the search also requires a postData, [url, postData] is returned
|
||||||
getSearchURL: function getSearchURL(text, useDefsearch)
|
getSearchURL: function getSearchURL(text, useDefsearch)
|
||||||
{
|
{
|
||||||
var url = null;
|
let url = null;
|
||||||
var aPostDataRef = {};
|
let aPostDataRef = {};
|
||||||
var searchString = (useDefsearch ? options["defsearch"] + " " : "") + text;
|
let searchString = (useDefsearch ? options["defsearch"] + " " : "") + text;
|
||||||
|
|
||||||
// we need to make sure our custom alias have been set, even if the user
|
// we need to make sure our custom alias have been set, even if the user
|
||||||
// did not :open <tab> once before
|
// did not :open <tab> once before
|
||||||
@@ -703,7 +702,7 @@ function History() //{{{
|
|||||||
{
|
{
|
||||||
if (args)
|
if (args)
|
||||||
{
|
{
|
||||||
var sh = window.getWebNavigation().sessionHistory;
|
let sh = window.getWebNavigation().sessionHistory;
|
||||||
for (let i = sh.index - 1; i >= 0; i--)
|
for (let i = sh.index - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (sh.getEntryAtIndex(i, false).URI.spec == args)
|
if (sh.getEntryAtIndex(i, false).URI.spec == args)
|
||||||
@@ -749,7 +748,7 @@ function History() //{{{
|
|||||||
{
|
{
|
||||||
if (args)
|
if (args)
|
||||||
{
|
{
|
||||||
var sh = window.getWebNavigation().sessionHistory;
|
let sh = window.getWebNavigation().sessionHistory;
|
||||||
for (let i in util.range(sh.index + 1, sh.count))
|
for (let i in util.range(sh.index + 1, sh.count))
|
||||||
{
|
{
|
||||||
if (sh.getEntryAtIndex(i, false).URI.spec == args)
|
if (sh.getEntryAtIndex(i, false).URI.spec == args)
|
||||||
@@ -962,7 +961,7 @@ function QuickMarks() //{{{
|
|||||||
"Mark a URL with a letter for quick access",
|
"Mark a URL with a letter for quick access",
|
||||||
function (args)
|
function (args)
|
||||||
{
|
{
|
||||||
var matches = args.string.match(/^([a-zA-Z0-9])(?:\s+(.+))?$/);
|
let matches = args.string.match(/^([a-zA-Z0-9])(?:\s+(.+))?$/);
|
||||||
if (!matches)
|
if (!matches)
|
||||||
liberator.echoerr("E488: Trailing characters");
|
liberator.echoerr("E488: Trailing characters");
|
||||||
else if (!matches[2])
|
else if (!matches[2])
|
||||||
@@ -985,7 +984,7 @@ function QuickMarks() //{{{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var filter = args.replace(/[^a-zA-Z0-9]/g, "");
|
let filter = args.replace(/[^a-zA-Z0-9]/g, "");
|
||||||
quickmarks.list(filter);
|
quickmarks.list(filter);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1003,7 +1002,7 @@ function QuickMarks() //{{{
|
|||||||
|
|
||||||
remove: function remove(filter)
|
remove: function remove(filter)
|
||||||
{
|
{
|
||||||
var pattern = RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
let pattern = RegExp("[" + filter.replace(/\s+/g, "") + "]");
|
||||||
|
|
||||||
for (let [qmark,] in qmarks)
|
for (let [qmark,] in qmarks)
|
||||||
{
|
{
|
||||||
@@ -1019,7 +1018,7 @@ function QuickMarks() //{{{
|
|||||||
|
|
||||||
jumpTo: function jumpTo(qmark, where)
|
jumpTo: function jumpTo(qmark, where)
|
||||||
{
|
{
|
||||||
var url = qmarks.get(qmark);
|
let url = qmarks.get(qmark);
|
||||||
|
|
||||||
if (url)
|
if (url)
|
||||||
liberator.open(url, where);
|
liberator.open(url, where);
|
||||||
@@ -1029,11 +1028,11 @@ function QuickMarks() //{{{
|
|||||||
|
|
||||||
list: function list(filter)
|
list: function list(filter)
|
||||||
{
|
{
|
||||||
var marks = [key for ([key, val] in qmarks)];
|
let marks = [key for ([key, val] in qmarks)];
|
||||||
// This was a lot nicer without the lambda...
|
// This was a lot nicer without the lambda...
|
||||||
var lowercaseMarks = marks.filter(function (x) /[a-z]/.test(x)).sort();
|
let lowercaseMarks = marks.filter(function (x) /[a-z]/.test(x)).sort();
|
||||||
var uppercaseMarks = marks.filter(function (x) /[A-Z]/.test(x)).sort();
|
let uppercaseMarks = marks.filter(function (x) /[A-Z]/.test(x)).sort();
|
||||||
var numberMarks = marks.filter(function (x) /[0-9]/.test(x)).sort();
|
let numberMarks = marks.filter(function (x) /[0-9]/.test(x)).sort();
|
||||||
|
|
||||||
marks = Array.concat(lowercaseMarks, uppercaseMarks, numberMarks);
|
marks = Array.concat(lowercaseMarks, uppercaseMarks, numberMarks);
|
||||||
|
|
||||||
|
|||||||
@@ -127,26 +127,38 @@ const config = { //{{{
|
|||||||
|
|
||||||
init: function ()
|
init: function ()
|
||||||
{
|
{
|
||||||
// TODO: support 'nrformats'?
|
// TODO: support 'nrformats'? -> probably not worth it --mst
|
||||||
function incrementURL(count)
|
function incrementURL(count)
|
||||||
{
|
{
|
||||||
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
|
let matches = buffer.URL.match(/(.*?)(\d+)(\D*)$/);
|
||||||
|
|
||||||
if (!matches)
|
if (!matches)
|
||||||
{
|
{
|
||||||
liberator.beep();
|
liberator.beep();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[, pre, number, post] = matches;
|
let [, pre, number, post] = matches;
|
||||||
let newNumber = parseInt(number, 10) + count;
|
let newNumber = parseInt(number, 10) + count;
|
||||||
|
let newNumberStr = String(newNumber > 0 ? newNumber : 0);
|
||||||
|
if (number.match(/^0/)) // add 0009<C-a> should become 0010
|
||||||
|
{
|
||||||
|
while (newNumberStr.length < number.length)
|
||||||
|
newNumberStr = "0" + newNumberStr;
|
||||||
|
}
|
||||||
|
|
||||||
liberator.open(pre + (newNumber > 0 ? newNumber : 0) + post);
|
liberator.open(pre + newNumberStr + post);
|
||||||
}
|
}
|
||||||
|
|
||||||
// load Vimperator specific modules
|
// load Vimperator specific modules
|
||||||
// FIXME: Why aren't these listed in config.scripts?
|
// FIXME: Why aren't these listed in config.scripts?
|
||||||
// FIXME: Why isn't this automatic?
|
// FIXME: Why isn't this automatic? -> how would one know which classes to load where? --mst
|
||||||
|
// Something like:
|
||||||
|
// liberator.addModule("search", function Search() { ...
|
||||||
|
// for all modules, or something similar. For modules which
|
||||||
|
// require other modules, well, there's addObserver("load_foo",
|
||||||
|
// or we could just make sure that they're all sourced in order.
|
||||||
|
// The scripts could even just instantiate them themselves.
|
||||||
|
// --Kris
|
||||||
liberator.loadModule("search", Search);
|
liberator.loadModule("search", Search);
|
||||||
liberator.loadModule("bookmarks", Bookmarks);
|
liberator.loadModule("bookmarks", Bookmarks);
|
||||||
liberator.loadModule("history", History);
|
liberator.loadModule("history", History);
|
||||||
@@ -162,7 +174,7 @@ const config = { //{{{
|
|||||||
let img = Image();
|
let img = Image();
|
||||||
img.src = "chrome://vimperator/content/vimperator.png";
|
img.src = "chrome://vimperator/content/vimperator.png";
|
||||||
img.onload = function () {
|
img.onload = function () {
|
||||||
styles.addSheet("logo", "chrome://liberator/locale/*",
|
styles.addSheet(true, "logo", "chrome://liberator/locale/*",
|
||||||
".vimperator-logo {" + <>
|
".vimperator-logo {" + <>
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
background: url({img.src});
|
background: url({img.src});
|
||||||
@@ -418,13 +430,15 @@ const config = { //{{{
|
|||||||
{
|
{
|
||||||
setter: function (value)
|
setter: function (value)
|
||||||
{
|
{
|
||||||
service.io.offline = !value;
|
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService2);
|
||||||
gPrefService.setBoolPref("browser.offline", service.io.offline);
|
ioService.offline = !value;
|
||||||
|
gPrefService.setBoolPref("browser.offline", ioService.offline);
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
getter: function ()
|
getter: function ()
|
||||||
{
|
{
|
||||||
return service.io.offline;
|
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService2);
|
||||||
|
return ioService.offline;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user