mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 16:12:26 +01:00
cleaned up completion.js a lot, probaby still something to do
This commit is contained in:
@@ -40,21 +40,31 @@ liberator.Completion = function () //{{{
|
|||||||
function buildLongestCommonSubstring(list, filter)
|
function buildLongestCommonSubstring(list, filter)
|
||||||
{
|
{
|
||||||
var filtered = [];
|
var filtered = [];
|
||||||
|
|
||||||
var ignorecase = false;
|
var ignorecase = false;
|
||||||
if (filter == filter.toLowerCase())
|
if (filter == filter.toLowerCase())
|
||||||
ignorecase = true;
|
ignorecase = true;
|
||||||
|
|
||||||
|
var longest = false;
|
||||||
|
if (liberator.options["wildmode"].indexOf("longest") >= 0)
|
||||||
|
longest = true;
|
||||||
|
|
||||||
for (var i = 0; i < list.length; i++)
|
for (var i = 0; i < list.length; i++)
|
||||||
{
|
{
|
||||||
for (var j = 0; j < list[i][0].length; j++)
|
var complist = list[i][0] instanceof Array ? list[i][0] : [list[i][0]];
|
||||||
|
for (var j = 0; j < complist.length; j++)
|
||||||
{
|
{
|
||||||
var item = list[i][0][j];
|
var item = complist[j];
|
||||||
if (ignorecase)
|
if (ignorecase)
|
||||||
item = item.toLowerCase();
|
item = item.toLowerCase();
|
||||||
|
|
||||||
if (item.indexOf(filter) == -1)
|
if (item.indexOf(filter) == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
filtered.push([complist[j], list[i][1]]);
|
||||||
|
|
||||||
|
if (longest)
|
||||||
|
{
|
||||||
if (substrings.length == 0)
|
if (substrings.length == 0)
|
||||||
{
|
{
|
||||||
var lastIndex = item.lastIndexOf(filter);
|
var lastIndex = item.lastIndexOf(filter);
|
||||||
@@ -62,46 +72,56 @@ liberator.Completion = function () //{{{
|
|||||||
for (var k = item.indexOf(filter); k != -1 && k <= lastIndex; k = item.indexOf(filter, k + 1))
|
for (var k = item.indexOf(filter); k != -1 && k <= lastIndex; k = item.indexOf(filter, k + 1))
|
||||||
{
|
{
|
||||||
for (var l = k + filter.length; l <= length; l++)
|
for (var l = k + filter.length; l <= length; l++)
|
||||||
substrings.push(list[i][0][j].substring(k, l));
|
substrings.push(complist[j].substring(k, l));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
substrings = substrings.filter(function ($_) {
|
substrings = substrings.filter(function ($_) {
|
||||||
return list[i][0][j].indexOf($_) >= 0;
|
return complist[j].indexOf($_) >= 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
filtered.push([list[i][0][j], list[i][1]]);
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filtered;
|
return filtered;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function is case sensitive and should be documented about input and output ;)
|
// this function is case sensitive
|
||||||
function buildLongestStartingSubstring(list, filter)
|
function buildLongestStartingSubstring(list, filter)
|
||||||
{
|
{
|
||||||
var filtered = [];
|
var filtered = [];
|
||||||
|
|
||||||
|
var longest = false;
|
||||||
|
if (liberator.options["wildmode"].indexOf("longest") >= 0)
|
||||||
|
longest = true;
|
||||||
|
|
||||||
for (var i = 0; i < list.length; i++)
|
for (var i = 0; i < list.length; i++)
|
||||||
{
|
{
|
||||||
for (var j = 0; j < list[i][0].length; j++)
|
var complist = list[i][0] instanceof Array ? list[i][0] : [list[i][0]];
|
||||||
|
for (var j = 0; j < complist.length; j++)
|
||||||
{
|
{
|
||||||
if (list[i][0][j].indexOf(filter) != 0)
|
if (complist[j].indexOf(filter) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
filtered.push([complist[j], list[i][1]]);
|
||||||
|
|
||||||
|
if (longest)
|
||||||
|
{
|
||||||
if (substrings.length == 0)
|
if (substrings.length == 0)
|
||||||
{
|
{
|
||||||
var length = list[i][0][j].length;
|
var length = complist[j].length;
|
||||||
for (var k = filter.length; k <= length; k++)
|
for (var k = filter.length; k <= length; k++)
|
||||||
substrings.push(list[i][0][j].substring(0, k));
|
substrings.push(complist[j].substring(0, k));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
substrings = substrings.filter(function ($_) {
|
substrings = substrings.filter(function ($_) {
|
||||||
return list[i][0][j].indexOf($_) == 0;
|
return complist[j].indexOf($_) == 0;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
filtered.push([list[i][0][j], list[i][1]]);
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,56 +150,20 @@ liberator.Completion = function () //{{{
|
|||||||
return longest;
|
return longest;
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: move "nodes" to {muttator,vimperator}.js
|
// generic filter function, also builds substrings needed
|
||||||
autocommands: function (filter)
|
// for :set wildmode=list:longest, if necessary
|
||||||
|
filter: function (array, filter, matchFromBeginning)
|
||||||
{
|
{
|
||||||
var nodes = [
|
|
||||||
["BrowserExit", "when firefox exits"],
|
|
||||||
["BrowserRestart", "when firefox restarts"],
|
|
||||||
["PageLoad", "when a page gets (re)loaded/opened"],
|
|
||||||
["FolderLoaded", "when a new folder in Thunderbird is opened"]
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!filter)
|
if (!filter)
|
||||||
return [0, nodes];
|
return array;
|
||||||
|
|
||||||
var mapped = nodes.map(function (node) {
|
if (matchFromBeginning)
|
||||||
return [[node[0]], node[1]];
|
return buildLongestStartingSubstring(array, filter);
|
||||||
});
|
else
|
||||||
|
return buildLongestCommonSubstring(array, filter);
|
||||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
|
||||||
},
|
|
||||||
|
|
||||||
dialog: function (filter)
|
|
||||||
{
|
|
||||||
var nodes = liberator.config.dialogs || [];
|
|
||||||
|
|
||||||
if (!filter)
|
|
||||||
return [0, nodes];
|
|
||||||
|
|
||||||
var mapped = nodes.map(function (node) {
|
|
||||||
return [[node[0]], node[1]];
|
|
||||||
});
|
|
||||||
|
|
||||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
|
||||||
},
|
|
||||||
|
|
||||||
macros: function (filter)
|
|
||||||
{
|
|
||||||
var macros = [];
|
|
||||||
var tmp = liberator.events.getMacros();
|
|
||||||
for (var item in tmp)
|
|
||||||
macros.push([item, tmp[item]]);
|
|
||||||
|
|
||||||
if (!filter)
|
|
||||||
return [0, macros];
|
|
||||||
|
|
||||||
var mapped = macros.map(function (macro) {
|
|
||||||
return [[macro[0]], macro[1]];
|
|
||||||
});
|
|
||||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// XXX: Move to bookmarks.js?
|
||||||
searchEngineSuggest: function (filter, engineAliases)
|
searchEngineSuggest: function (filter, engineAliases)
|
||||||
{
|
{
|
||||||
if (!filter)
|
if (!filter)
|
||||||
@@ -239,7 +223,6 @@ liberator.Completion = function () //{{{
|
|||||||
url: function (filter, complete)
|
url: function (filter, complete)
|
||||||
{
|
{
|
||||||
var completions = [];
|
var completions = [];
|
||||||
|
|
||||||
var start = 0;
|
var start = 0;
|
||||||
var skip = filter.match(/^(.*,\s+)(.*)/); // start after the last ", "
|
var skip = filter.match(/^(.*,\s+)(.*)/); // start after the last ", "
|
||||||
if (skip)
|
if (skip)
|
||||||
@@ -271,14 +254,7 @@ liberator.Completion = function () //{{{
|
|||||||
search: function (filter)
|
search: function (filter)
|
||||||
{
|
{
|
||||||
var engines = liberator.bookmarks.getSearchEngines().concat(liberator.bookmarks.getKeywords());
|
var engines = liberator.bookmarks.getSearchEngines().concat(liberator.bookmarks.getKeywords());
|
||||||
|
return [0, this.filter(engines, filter)];
|
||||||
if (!filter)
|
|
||||||
return [0, engines];
|
|
||||||
|
|
||||||
var mapped = engines.map(function (engine) {
|
|
||||||
return [[engine[0]], engine[1]];
|
|
||||||
});
|
|
||||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: support file:// and \ or / path separators on both platforms
|
// TODO: support file:// and \ or / path separators on both platforms
|
||||||
@@ -293,8 +269,8 @@ liberator.Completion = function () //{{{
|
|||||||
dir = matches[1] || ""; // "" is expanded inside readDirectory to the current dir
|
dir = matches[1] || ""; // "" is expanded inside readDirectory to the current dir
|
||||||
compl = matches[2] || "";
|
compl = matches[2] || "";
|
||||||
}
|
}
|
||||||
var files = [], mapped = [];
|
|
||||||
|
|
||||||
|
var files = [], mapped = [];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
files = liberator.io.readDirectory(dir);
|
files = liberator.io.readDirectory(dir);
|
||||||
@@ -340,13 +316,7 @@ liberator.Completion = function () //{{{
|
|||||||
res.push([elems[i].textContent, files[file]]);
|
res.push([elems[i].textContent, files[file]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filter)
|
return [0, this.filter(res, filter)];
|
||||||
return [0, res];
|
|
||||||
|
|
||||||
var mapped = res.map(function (node) {
|
|
||||||
return [[node[0]], node[1]];
|
|
||||||
});
|
|
||||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
command: function (filter)
|
command: function (filter)
|
||||||
@@ -366,137 +336,6 @@ liberator.Completion = function () //{{{
|
|||||||
return [0, buildLongestStartingSubstring(completions, filter)];
|
return [0, buildLongestStartingSubstring(completions, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
mail: function (filter)
|
|
||||||
{
|
|
||||||
var completions = [];
|
|
||||||
var folders = liberator.mail.getFolders();
|
|
||||||
for (var folder in folders)
|
|
||||||
{
|
|
||||||
completions.push([folders[folder].server.prettyName + ": "
|
|
||||||
+ folders[folder].name,
|
|
||||||
"Unread: " + folders[folder].getNumUnread(false)]);
|
|
||||||
}
|
|
||||||
if (!filter)
|
|
||||||
return [0, completions];
|
|
||||||
var mapped = completions.map(function (node) {
|
|
||||||
return [[node[0]], node[1]];
|
|
||||||
});
|
|
||||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
|
||||||
},
|
|
||||||
|
|
||||||
option: function (filter, special, unfiltered)
|
|
||||||
{
|
|
||||||
var optionCompletions = [];
|
|
||||||
var prefix = filter.match(/^no|inv/) || "";
|
|
||||||
|
|
||||||
if (prefix)
|
|
||||||
filter = filter.replace(prefix, "");
|
|
||||||
|
|
||||||
// needed for help-completions, don't return [start, options], just options
|
|
||||||
// FIXME: doesn't belong here to be honest (rather v.options.get(filter)) --mst
|
|
||||||
if (unfiltered)
|
|
||||||
{
|
|
||||||
var options = [];
|
|
||||||
for (var option in liberator.options)
|
|
||||||
{
|
|
||||||
if (prefix && option.type != "boolean")
|
|
||||||
continue;
|
|
||||||
options.push([option.names, option.description]);
|
|
||||||
}
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (special)
|
|
||||||
{
|
|
||||||
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
|
||||||
.getService(Components.interfaces.nsIPrefBranch);
|
|
||||||
var prefArray = prefs.getChildList("", { value: 0 });
|
|
||||||
prefArray.sort();
|
|
||||||
|
|
||||||
if (filter.length > 0 && filter.lastIndexOf("=") == filter.length - 1)
|
|
||||||
{
|
|
||||||
for (var i = 0; i < prefArray.length; i++)
|
|
||||||
{
|
|
||||||
var name = prefArray[i];
|
|
||||||
if (name.match("^" + filter.substr(0, filter.length - 1) + "$" ))
|
|
||||||
{
|
|
||||||
var value = liberator.options.getPref(name) + "";
|
|
||||||
return [filter.length + 1, [[value, ""]]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [0, []];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < prefArray.length; i++)
|
|
||||||
{
|
|
||||||
if (!filter)
|
|
||||||
optionCompletions.push([prefArray[i], liberator.options.getPref(prefArray[i])]);
|
|
||||||
else
|
|
||||||
optionCompletions.push([[prefArray[i]], liberator.options.getPref(prefArray[i])]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!filter)
|
|
||||||
return [0, optionCompletions];
|
|
||||||
|
|
||||||
return [0, buildLongestCommonSubstring(optionCompletions, filter)];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!filter)
|
|
||||||
{
|
|
||||||
var options = [];
|
|
||||||
for (var option in liberator.options)
|
|
||||||
{
|
|
||||||
if (prefix && option.type != "boolean")
|
|
||||||
continue;
|
|
||||||
options.push([prefix + option.name, option.description]);
|
|
||||||
}
|
|
||||||
return [0, options];
|
|
||||||
}
|
|
||||||
// check if filter ends with =, then complete current value
|
|
||||||
else if (filter.length > 0 && filter.lastIndexOf("=") == filter.length - 1)
|
|
||||||
{
|
|
||||||
filter = filter.substr(0, filter.length - 1);
|
|
||||||
for (var option in liberator.options)
|
|
||||||
{
|
|
||||||
if (option.hasName(filter))
|
|
||||||
return [filter.length + 1, [[option.value + "", ""]]];
|
|
||||||
}
|
|
||||||
return [0, optionCompletions];
|
|
||||||
}
|
|
||||||
|
|
||||||
// can't use b_l_s_s, since this has special requirements (the prefix)
|
|
||||||
var filterLength = filter.length;
|
|
||||||
for (var option in liberator.options)
|
|
||||||
{
|
|
||||||
if (prefix && option.type != "boolean")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (var j = 0; j < option.names.length; j++)
|
|
||||||
{
|
|
||||||
if (option.names[j].indexOf(filter) != 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (substrings.length == 0)
|
|
||||||
{
|
|
||||||
var length = option.names[j].length;
|
|
||||||
for (var k = filterLength; k <= length; k++)
|
|
||||||
substrings.push(prefix + option.names[j].substring(0, k));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
substrings = substrings.filter(function ($_) {
|
|
||||||
return option.names[j].indexOf($_) == 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
optionCompletions.push([prefix + option.names[j], option.description]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [0, optionCompletions];
|
|
||||||
},
|
|
||||||
|
|
||||||
// FIXME: items shouldn't be [[[a], b]], but [[a, b]] and only mapped if at all for bLCS --mst
|
// FIXME: items shouldn't be [[[a], b]], but [[a, b]] and only mapped if at all for bLCS --mst
|
||||||
buffer: function (filter)
|
buffer: function (filter)
|
||||||
{
|
{
|
||||||
@@ -534,24 +373,6 @@ liberator.Completion = function () //{{{
|
|||||||
return [0, buildLongestCommonSubstring(items, filter)];
|
return [0, buildLongestCommonSubstring(items, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
sidebar: function (filter)
|
|
||||||
{
|
|
||||||
var menu = document.getElementById("viewSidebarMenu");
|
|
||||||
var nodes = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < menu.childNodes.length; i++)
|
|
||||||
nodes.push([menu.childNodes[i].label, ""]);
|
|
||||||
|
|
||||||
if (!filter)
|
|
||||||
return [0, nodes];
|
|
||||||
|
|
||||||
var mapped = nodes.map(function (node) {
|
|
||||||
return [[node[0]], node[1]];
|
|
||||||
});
|
|
||||||
|
|
||||||
return [0, buildLongestCommonSubstring(mapped, filter)];
|
|
||||||
},
|
|
||||||
|
|
||||||
javascript: function (str)
|
javascript: function (str)
|
||||||
{
|
{
|
||||||
var matches = str.match(/^(.*?)(\s*\.\s*)?(\w*)$/);
|
var matches = str.match(/^(.*?)(\s*\.\s*)?(\w*)$/);
|
||||||
|
|||||||
@@ -89,7 +89,10 @@ liberator.AutoCommands = function () //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (filter) { return liberator.completion.autocommands(filter); }
|
completer: function (filter)
|
||||||
|
{
|
||||||
|
return [0, liberator.completion.filter(liberator.config.autocommands || [], filter)];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
@@ -386,6 +389,16 @@ liberator.Events = function () //{{{
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMacroCompletions(filter)
|
||||||
|
{
|
||||||
|
var macros = [];
|
||||||
|
var tmp = liberator.events.getMacros();
|
||||||
|
for (var item in tmp)
|
||||||
|
macros.push([item, tmp[item]]);
|
||||||
|
|
||||||
|
return [0, liberator.completion.filter(macros, filter)];
|
||||||
|
}
|
||||||
|
|
||||||
function isFormElemFocused()
|
function isFormElemFocused()
|
||||||
{
|
{
|
||||||
var elt = window.document.commandDispatcher.focusedElement;
|
var elt = window.document.commandDispatcher.focusedElement;
|
||||||
@@ -587,6 +600,9 @@ liberator.Events = function () //{{{
|
|||||||
liberator.echoerr("E474: Invalid argument");
|
liberator.echoerr("E474: Invalid argument");
|
||||||
else
|
else
|
||||||
liberator.events.deleteMacros(arg);
|
liberator.events.deleteMacros(arg);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
completer: function (filter) { return getMacroCompletions(filter); }
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["macros"],
|
liberator.commands.add(["macros"],
|
||||||
@@ -602,6 +618,9 @@ liberator.Events = function () //{{{
|
|||||||
str += "</table>";
|
str += "</table>";
|
||||||
|
|
||||||
liberator.echo(str, liberator.commandline.FORCE_MULTILINE);
|
liberator.echo(str, liberator.commandline.FORCE_MULTILINE);
|
||||||
|
},
|
||||||
|
{
|
||||||
|
completer: function (filter) { return getMacroCompletions(filter); }
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["pl[ay]"],
|
liberator.commands.add(["pl[ay]"],
|
||||||
@@ -614,7 +633,7 @@ liberator.Events = function () //{{{
|
|||||||
liberator.events.playMacro(arg);
|
liberator.events.playMacro(arg);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (filter) { return liberator.completion.macros(filter); }
|
completer: function (filter) { return getMacroCompletions(filter); }
|
||||||
});
|
});
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////}}}
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
|
|||||||
@@ -161,7 +161,10 @@ const liberator = (function () //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (filter) { return liberator.completion.dialog(filter); }
|
completer: function (filter)
|
||||||
|
{
|
||||||
|
return [0, liberator.completion.filter(liberator.config.dialogs || [], filter)];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["exe[cute]"],
|
liberator.commands.add(["exe[cute]"],
|
||||||
@@ -750,7 +753,7 @@ const liberator = (function () //{{{
|
|||||||
// quit liberator, no matter how many tabs/windows are open
|
// quit liberator, no matter how many tabs/windows are open
|
||||||
quit: function (saveSession)
|
quit: function (saveSession)
|
||||||
{
|
{
|
||||||
liberator.autocommands.trigger("BrowserExit", "");
|
liberator.autocommands.trigger("Quit", "");
|
||||||
|
|
||||||
if (saveSession)
|
if (saveSession)
|
||||||
liberator.options.setPref("browser.startup.page", 3); // start with saved session
|
liberator.options.setPref("browser.startup.page", 3); // start with saved session
|
||||||
@@ -762,8 +765,6 @@ const liberator = (function () //{{{
|
|||||||
|
|
||||||
restart: function ()
|
restart: function ()
|
||||||
{
|
{
|
||||||
liberator.autocommands.trigger("BrowserRestart", "");
|
|
||||||
|
|
||||||
const nsIAppStartup = Components.interfaces.nsIAppStartup;
|
const nsIAppStartup = Components.interfaces.nsIAppStartup;
|
||||||
|
|
||||||
// notify all windows that an application quit has been requested.
|
// notify all windows that an application quit has been requested.
|
||||||
@@ -912,6 +913,8 @@ const liberator = (function () //{{{
|
|||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
liberator.statusline.update();
|
liberator.statusline.update();
|
||||||
|
|
||||||
|
liberator.autocommands.trigger("Startup", "");
|
||||||
liberator.log(liberator.config.name + " fully initialized", 1);
|
liberator.log(liberator.config.name + " fully initialized", 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,20 @@ liberator.Mail = function () //{{{
|
|||||||
var notifyFlags = nsIFolderListener.intPropertyChanged | nsIFolderListener.event;
|
var notifyFlags = nsIFolderListener.intPropertyChanged | nsIFolderListener.event;
|
||||||
mailSession.AddFolderListener(folderListener, notifyFlags);
|
mailSession.AddFolderListener(folderListener, notifyFlags);
|
||||||
|
|
||||||
|
function getFolderCompletions(filter)
|
||||||
|
{
|
||||||
|
var completions = [];
|
||||||
|
var folders = liberator.mail.getFolders();
|
||||||
|
for (var folder in folders)
|
||||||
|
{
|
||||||
|
completions.push([folders[folder].server.prettyName + ": "
|
||||||
|
+ folders[folder].name,
|
||||||
|
"Unread: " + folders[folder].getNumUnread(false)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [0, liberator.filter(completions, filter)];
|
||||||
|
}
|
||||||
|
|
||||||
function moveOrCopy(copy, destinationFolder, operateOnThread)
|
function moveOrCopy(copy, destinationFolder, operateOnThread)
|
||||||
{
|
{
|
||||||
if (!destinationFolder)
|
if (!destinationFolder)
|
||||||
@@ -616,7 +630,7 @@ liberator.Mail = function () //{{{
|
|||||||
SelectFolder(folder.URI);
|
SelectFolder(folder.URI);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (filter) { return liberator.completion.mail(filter); }
|
completer: function (filter) { return getFolderCompletions(filter); }
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["m[essage]"],
|
liberator.commands.add(["m[essage]"],
|
||||||
@@ -668,14 +682,14 @@ liberator.Mail = function () //{{{
|
|||||||
"Copy selected messages",
|
"Copy selected messages",
|
||||||
function (args, special) { moveOrCopy(true, args); },
|
function (args, special) { moveOrCopy(true, args); },
|
||||||
{
|
{
|
||||||
completer: function (filter) { return liberator.completion.mail(filter); }
|
completer: function (filter) { return getFolderCompletions(filter); }
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["move[to]"],
|
liberator.commands.add(["move[to]"],
|
||||||
"Move selected messages",
|
"Move selected messages",
|
||||||
function (args, special) { moveOrCopy(false, args); },
|
function (args, special) { moveOrCopy(false, args); },
|
||||||
{
|
{
|
||||||
completer: function (filter) { return liberator.completion.mail(filter); }
|
completer: function (filter) { return getFolderCompletions(filter); }
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["empty[trash]"],
|
liberator.commands.add(["empty[trash]"],
|
||||||
@@ -769,7 +783,7 @@ liberator.Mail = function () //{{{
|
|||||||
msgComposeService.OpenComposeWindowWithParams(null, params);
|
msgComposeService.OpenComposeWindowWithParams(null, params);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// returns an array of nsIMsgFolder objects
|
||||||
getFolders: function (filter, includeServers, includeMsgFolders)
|
getFolders: function (filter, includeServers, includeMsgFolders)
|
||||||
{
|
{
|
||||||
var folders = [];
|
var folders = [];
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ liberator.config = {
|
|||||||
get mainWindowID() { return this.isComposeWindow ? "msgcomposeWindow" : "messengerWindow"; },
|
get mainWindowID() { return this.isComposeWindow ? "msgcomposeWindow" : "messengerWindow"; },
|
||||||
isComposeWindow: false,
|
isComposeWindow: false,
|
||||||
|
|
||||||
|
autocommands: [["FolderLoaded", "Triggered after switching folders in Thunderbird"],
|
||||||
|
["PageLoad", "Triggered when a page gets (re)loaded/opened"],
|
||||||
|
["Quit", "Triggered before exiting Thunderbird"],
|
||||||
|
["Startup", "Triggered after Thunderbird starts"]],
|
||||||
|
|
||||||
dialogs: [
|
dialogs: [
|
||||||
["about", "About Thunderbird",
|
["about", "About Thunderbird",
|
||||||
function () { openAboutDialog(); }],
|
function () { openAboutDialog(); }],
|
||||||
|
|||||||
@@ -560,7 +560,82 @@ liberator.Options = function () //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (filter, special) { return liberator.completion.option(filter, special); }
|
completer: function (filter, special)
|
||||||
|
{
|
||||||
|
var optionCompletions = [];
|
||||||
|
var prefix = filter.match(/^no|inv/) || "";
|
||||||
|
|
||||||
|
if (prefix)
|
||||||
|
filter = filter.replace(prefix, "");
|
||||||
|
|
||||||
|
if (special) // list completions for about:config entries
|
||||||
|
{
|
||||||
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
|
||||||
|
.getService(Components.interfaces.nsIPrefBranch);
|
||||||
|
var prefArray = prefs.getChildList("", { value: 0 });
|
||||||
|
prefArray.sort();
|
||||||
|
|
||||||
|
if (filter.length > 0 && filter.lastIndexOf("=") == filter.length - 1)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < prefArray.length; i++)
|
||||||
|
{
|
||||||
|
var name = prefArray[i];
|
||||||
|
if (name.match("^" + filter.substr(0, filter.length - 1) + "$" ))
|
||||||
|
{
|
||||||
|
var value = liberator.options.getPref(name) + "";
|
||||||
|
return [filter.length + 1, [[value, ""]]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [0, []];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < prefArray.length; i++)
|
||||||
|
optionCompletions.push([prefArray[i], liberator.options.getPref(prefArray[i])]);
|
||||||
|
|
||||||
|
return [0, liberator.completion.filter(optionCompletions, filter)];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filter)
|
||||||
|
{
|
||||||
|
var options = [];
|
||||||
|
for (var option in liberator.options)
|
||||||
|
{
|
||||||
|
if (prefix && option.type != "boolean")
|
||||||
|
continue;
|
||||||
|
options.push([prefix + option.name, option.description]);
|
||||||
|
}
|
||||||
|
return [0, options];
|
||||||
|
}
|
||||||
|
// check if filter ends with =, then complete current value
|
||||||
|
else if (filter.length > 0 && filter.lastIndexOf("=") == filter.length - 1)
|
||||||
|
{
|
||||||
|
filter = filter.substr(0, filter.length - 1);
|
||||||
|
for (var option in liberator.options)
|
||||||
|
{
|
||||||
|
if (option.hasName(filter))
|
||||||
|
return [filter.length + 1, [[option.value + "", ""]]];
|
||||||
|
}
|
||||||
|
return [0, optionCompletions];
|
||||||
|
}
|
||||||
|
|
||||||
|
var filterLength = filter.length;
|
||||||
|
for (var option in liberator.options)
|
||||||
|
{
|
||||||
|
if (prefix && option.type != "boolean")
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (var j = 0; j < option.names.length; j++)
|
||||||
|
{
|
||||||
|
if (option.names[j].indexOf(filter) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
optionCompletions.push([prefix + option.names[j], option.description]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [0, liberator.completion.filter(optionCompletions, prefix + filter, true)];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["unl[et]"],
|
liberator.commands.add(["unl[et]"],
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ liberator.config = { //{{{
|
|||||||
features: ["bookmarks", "hints", "history", "marks", "quickmarks", "session", "tabs", "windows"],
|
features: ["bookmarks", "hints", "history", "marks", "quickmarks", "session", "tabs", "windows"],
|
||||||
guioptions: { m: ["toolbar-menubar"], T: ["nav-bar"], b: ["PersonalToolbar"] },
|
guioptions: { m: ["toolbar-menubar"], T: ["nav-bar"], b: ["PersonalToolbar"] },
|
||||||
|
|
||||||
|
autocommands: [["PageLoad", "Triggered when a page gets (re)loaded/opened"],
|
||||||
|
["Quit", "Triggered before exiting Thunderbird"],
|
||||||
|
["Startup", "Triggered after Thunderbird starts"]],
|
||||||
|
|
||||||
dialogs: [
|
dialogs: [
|
||||||
["about", "About Firefox",
|
["about", "About Firefox",
|
||||||
function () { openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
|
function () { openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
|
||||||
@@ -308,7 +312,16 @@ liberator.config = { //{{{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
completer: function (filter) { return liberator.completion.sidebar(filter); }
|
completer: function (filter)
|
||||||
|
{
|
||||||
|
var menu = document.getElementById("viewSidebarMenu");
|
||||||
|
var nodes = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < menu.childNodes.length; i++)
|
||||||
|
nodes.push([menu.childNodes[i].label, ""]);
|
||||||
|
|
||||||
|
return [0, liberator.completion.filter(nodes, filter)];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
liberator.commands.add(["winc[lose]", "wc[lose]"],
|
liberator.commands.add(["winc[lose]", "wc[lose]"],
|
||||||
|
|||||||
Reference in New Issue
Block a user