1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 15:02:26 +01:00

Move template.listCompleter to completion. Some other cleanup/fixes

This commit is contained in:
Kris Maglione
2008-11-25 19:31:51 +00:00
parent 4462bb3768
commit 48172401fa
7 changed files with 51 additions and 76 deletions

View File

@@ -233,11 +233,8 @@ function Bookmarks() //{{{
"Set the default search engine", "Set the default search engine",
"string", "google", "string", "google",
{ {
completer: function (filter) completion._url(filter, "s").items, completer: function (filter) completion.runCompleter("search", filter, true),
validator: function (value) validator: function (value) completion.runCompleter("search", "", true).some(function ([s]) s == value)
{
return completion._url("", "s").items.some(function (s) s.text == value);
}
}); });
options.add(["preload"], options.add(["preload"],
@@ -560,7 +557,7 @@ function Bookmarks() //{{{
list: function (filter, tags, openItems) list: function (filter, tags, openItems)
{ {
if (!openItems) if (!openItems)
return template.listCompleter("bookmark", filter, tags); return completion.listCompleter("bookmark", filter, tags);
let items = this.get(filter, tags, false); let items = this.get(filter, tags, false);
if (items.length) if (items.length)
@@ -802,7 +799,7 @@ function History() //{{{
list: function (filter, openItems) list: function (filter, openItems)
{ {
if (!openItems) if (!openItems)
return template.listCompleter("history", filter); return completion.listCompleter("history", filter);
var items = this.get({ searchTerms: filter }, 1000); var items = this.get({ searchTerms: filter }, 1000);
if (items.length) if (items.length)

View File

@@ -34,6 +34,8 @@ modules._cleanEval = function _cleanEval(__liberator_eval_arg, __liberator_eval_
function CompletionContext(editor, name, offset) function CompletionContext(editor, name, offset)
{ {
if (!(this instanceof arguments.callee))
return new arguments.callee(editor, name, offset);
if (!name) if (!name)
name = ""; name = "";
@@ -949,10 +951,10 @@ function Completion() //{{{
runCompleter: function (name, filter) runCompleter: function (name, filter)
{ {
let context = new CompletionContext(filter); let context = CompletionContext(filter);
context.__defineGetter__("background", function () false); this[name].apply(this, [context].concat(Array.slice(arguments, 1)));
context.__defineSetter__("background", function () false); while (context.incomplete)
this[name](context); liberator.threadYield(true, true);
return context.items.map(function (i) i.item); return context.items.map(function (i) i.item);
}, },
@@ -1060,6 +1062,23 @@ function Completion() //{{{
return filter.split(/\s+/).every(function strIndex(str) itemsStr.indexOf(str) > -1); return filter.split(/\s+/).every(function strIndex(str) itemsStr.indexOf(str) > -1);
}, },
listCompleter: function (name, filter)
{
let context = CompletionContext(filter || "");
context.fork.apply(context, ["list", 0, completion, name].concat(Array.slice(arguments, 2)));
context = context.contexts["/list"];
while (context.incomplete)
liberator.threadYield(true, true);
let list = template.generic(
<div class="hl-Completions">
{ template.completionRow(context.title, "hl-CompTitle") }
{ template.map(context.items, function (item) context.createRow(item)) }
</div>);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
},
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
////////////////////// COMPLETION TYPES //////////////////////////////////////// ////////////////////// COMPLETION TYPES ////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
@@ -1275,10 +1294,7 @@ function Completion() //{{{
get javascriptCompleter() javascript, get javascriptCompleter() javascript,
javascript: function _javascript(context) javascript: function _javascript(context) javascript.complete(context),
{
return javascript.complete(context);
},
location: function (context) location: function (context)
{ {
@@ -1309,11 +1325,10 @@ function Completion() //{{{
}); });
}, },
macro: function macro(filter) macro: function macro(context)
{ {
var macros = [item for (item in events.getMacros())]; context.title = ["Macro", "Keys"];
context.completions = [item for (item in events.getMacros())];
return [0, this.filter(macros, filter)];
}, },
menuItem: function menuItem(filter) commands.get("emenu").completer(filter), // XXX menuItem: function menuItem(filter) commands.get("emenu").completer(filter), // XXX
@@ -1322,7 +1337,7 @@ function Completion() //{{{
preference: function preference(filter) commands.get("set").completer(filter, true), // XXX preference: function preference(filter) commands.get("set").completer(filter, true), // XXX
search: function search(context) search: function search(context, noSuggest)
{ {
let [, keyword, space, args] = context.filter.match(/^\s*(\S*)(\s*)(.*)$/); let [, keyword, space, args] = context.filter.match(/^\s*(\S*)(\s*)(.*)$/);
let keywords = bookmarks.getKeywords(); let keywords = bookmarks.getKeywords();
@@ -1333,7 +1348,7 @@ function Completion() //{{{
context.completions = keywords.concat(engines); context.completions = keywords.concat(engines);
context.anchored = true; context.anchored = true;
if (!space) if (!space || noSuggest)
return; return;
context.fork("suggest", keyword.length + space.length, this, "searchEngineSuggest", context.fork("suggest", keyword.length + space.length, this, "searchEngineSuggest",
@@ -1467,14 +1482,6 @@ function Completion() //{{{
this.urlCompleters[opt] = UrlCompleter.apply(null, Array.slice(arguments)); this.urlCompleters[opt] = UrlCompleter.apply(null, Array.slice(arguments));
}, },
// FIXME: Temporary
_url: function _url(filter, complete)
{
let context = new CompletionContext(filter);
this.url(context, complete);
return context.allItems;
},
userCommand: function userCommand(filter) userCommand: function userCommand(filter)
{ {
let cmds = commands.getUserCommands(); let cmds = commands.getUserCommands();

View File

@@ -719,21 +719,16 @@ function Events() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (context) completion.macro(context.filter), completer: function (context) completion.macro(context),
literal: true literal: true
}); });
commands.add(["macros"], commands.add(["macros"],
"List all macros", "List all macros",
function (args) function (args) { completion.listCompleter("macro", args.arguments[0]) },
{ {
XML.prettyPrinting = false; argCount: "1",
var str = template.tabular(["Macro", "Keys"], [], events.getMacros(args.string)); completer: function (context) completion.macro(context),
liberator.echo(str, commandline.FORCE_MULTILINE);
},
{
completer: function (context) completion.macro(context.filter),
literal: true
}); });
commands.add(["pl[ay]"], commands.add(["pl[ay]"],
@@ -741,7 +736,7 @@ function Events() //{{{
function (args) { events.playMacro(args.arguments[0]); }, function (args) { events.playMacro(args.arguments[0]); },
{ {
argCount: "1", argCount: "1",
completer: function (context) completion.macro(context.filter) completer: function (context) completion.macro(context)
}); });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}

View File

@@ -208,30 +208,28 @@ const liberator = (function () //{{{
// TODO: move this // TODO: move this
function getMenuItems() function getMenuItems()
{ {
var menubar = document.getElementById(config.guioptions["m"]); function addChildren(node, parent)
var items = [];
for (let i = 0; i < menubar.childNodes.length; i++)
{ {
(function (item, path) for (let [,item] in Iterator(node.childNodes))
{ {
if (item.childNodes.length == 0 && item.localName == "menuitem" if (item.childNodes.length == 0 && item.localName == "menuitem"
&& !/rdf:http:/.test(item.label)) // FIXME && !/rdf:http:/.test(item.label)) // FIXME
{ {
item.fullMenuPath = path += item.label; item.fullMenuPath = parent + item.label;
items.push(item); items.push(item);
} }
else else
{ {
path = parent;
if (item.localName == "menu") if (item.localName == "menu")
path += item.label + "."; path += item.label + ".";
addChildren(item, path);
for (let j = 0; j < item.childNodes.length; j++) }
arguments.callee(item.childNodes[j], path);
} }
})(menubar.childNodes[i], "");
} }
let items = [];
addChildren(document.getElementById(config.guioptions["m"]), "");
return items; return items;
} }
@@ -259,8 +257,9 @@ const liberator = (function () //{{{
// TODO: add this as a standard menu completion function // TODO: add this as a standard menu completion function
completer: function (context) completer: function (context)
{ {
let completions = getMenuItems().map(function (item) [item.fullMenuPath, item.label]); context.title = ["Menu Path", "Label"];
return [0, completion.filter(completions, context.filter)]; context.keys = { text: "fullMenuPath", description: "label" };
context.completions = getMenuItems();
}, },
literal: true literal: true
}); });

View File

@@ -748,7 +748,7 @@ function Tabs() //{{{
list: function (filter) list: function (filter)
{ {
template.listCompleter("buffer", filter); completion.listCompleter("buffer", filter);
}, },
// wrap causes the movement to wrap around the start and end of the tab list // wrap causes the movement to wrap around the start and end of the tab list

View File

@@ -32,23 +32,6 @@ const template = {
return <>{xml}</>; return <>{xml}</>;
}, },
listCompleter: function (name, filter)
{
let context = new CompletionContext(filter || "");
context.fork.apply(context, ["list", 0, completion, name].concat(Array.slice(arguments, 2)));
context = context.contexts["/list"];
while (context.incomplete)
liberator.threadYield(true, true);
let list = this.generic(
<div class="hl-Completions">
{ this.completionRow(context.title, "hl-CompTitle") }
{ template.map(context.items, function (item) context.createRow(item)) }
</div>);
commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
},
completionRow: function completionRow(item, class) completionRow: function completionRow(item, class)
{ {
if (typeof icon == "function") if (typeof icon == "function")

View File

@@ -143,12 +143,6 @@ function CommandLine() //{{{
completionPostfix = command.substring(commandWidget.selectionStart); completionPostfix = command.substring(commandWidget.selectionStart);
completions = liberator.triggerCallback("complete", currentExtendedMode, completionPrefix); completions = liberator.triggerCallback("complete", currentExtendedMode, completionPrefix);
// sort the completion list
// TODO: might not make sense anymore with our advanced completions, we should just sort when necessary
// FIXME: CompletionContext
//if (options.get("wildoptions").has("sort"))
// completions.items.sort(function (a, b) String.localeCompare(a[0], b[0]));
completionList.setItems(completionContext); completionList.setItems(completionContext);
} }
@@ -682,7 +676,7 @@ function CommandLine() //{{{
commandWidget.focus(); commandWidget.focus();
completionContext = new CompletionContext(commandWidget.inputField.editor); completionContext = CompletionContext(commandWidget.inputField.editor);
completionContext.onUpdate = function () completionContext.onUpdate = function ()
{ {
commandline.setCompletions(this.allItems); commandline.setCompletions(this.allItems);