1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-08 07:04:14 +01:00

Move liberator.{register,trigger}Callback to CommandLine.

This commit is contained in:
Doug Kearns
2009-07-11 00:03:10 +10:00
parent 6bea2bb081
commit c062cf48df
4 changed files with 89 additions and 86 deletions

View File

@@ -58,13 +58,13 @@ function Finder() //{{{
var linksOnly = false; // search is limited to link text only var linksOnly = false; // search is limited to link text only
// Event handlers for search - closure is needed // Event handlers for search - closure is needed
liberator.registerCallback("change", modes.SEARCH_FORWARD, function (str) { finder.onKeyPress(str); }); commandline.registerCallback("change", modes.SEARCH_FORWARD, function (str) { finder.onKeyPress(str); });
liberator.registerCallback("submit", modes.SEARCH_FORWARD, function (str) { finder.onSubmit(str); }); commandline.registerCallback("submit", modes.SEARCH_FORWARD, function (str) { finder.onSubmit(str); });
liberator.registerCallback("cancel", modes.SEARCH_FORWARD, function () { finder.onCancel(); }); commandline.registerCallback("cancel", modes.SEARCH_FORWARD, function () { finder.onCancel(); });
// TODO: allow advanced myModes in register/triggerCallback // TODO: allow advanced myModes in register/triggerCallback
liberator.registerCallback("change", modes.SEARCH_BACKWARD, function (str) { finder.onKeyPress(str); }); commandline.registerCallback("change", modes.SEARCH_BACKWARD, function (str) { finder.onKeyPress(str); });
liberator.registerCallback("submit", modes.SEARCH_BACKWARD, function (str) { finder.onSubmit(str); }); commandline.registerCallback("submit", modes.SEARCH_BACKWARD, function (str) { finder.onSubmit(str); });
liberator.registerCallback("cancel", modes.SEARCH_BACKWARD, function () { finder.onCancel(); }); commandline.registerCallback("cancel", modes.SEARCH_BACKWARD, function () { finder.onCancel(); });
// set searchString, searchPattern, caseSensitive, linksOnly // set searchString, searchPattern, caseSensitive, linksOnly
function processUserPattern(pattern) function processUserPattern(pattern)

View File

@@ -54,7 +54,6 @@ const liberator = (function () //{{{
run: function () { this.func.apply(this.self, this.args); } run: function () { this.func.apply(this.self, this.args); }
}; };
const callbacks = {};
const observers = {}; const observers = {};
function registerObserver(type, callback) function registerObserver(type, callback)
@@ -867,27 +866,6 @@ const liberator = (function () //{{{
postCommand: null postCommand: null
}, },
// @param type can be:
// "submit": when the user pressed enter in the command line
// "change"
// "cancel"
// "complete"
// TODO: "zoom": if the zoom value of the current buffer changed
// TODO: move to ui.js?
registerCallback: function (type, mode, func)
{
if (!(type in callbacks))
callbacks[type] = {};
callbacks[type][mode] = func;
},
triggerCallback: function (type, mode, data)
{
if (callbacks[type] && callbacks[type][mode])
return callbacks[type][mode].call(this, data);
return false;
},
registerObserver: registerObserver, registerObserver: registerObserver,
unregisterObserver: function (type, callback) unregisterObserver: function (type, callback)
@@ -896,6 +874,7 @@ const liberator = (function () //{{{
observers[type] = observers[type].filter(function (c) c != callback); observers[type] = observers[type].filter(function (c) c != callback);
}, },
// TODO: "zoom": if the zoom value of the current buffer changed
triggerObserver: function (type) triggerObserver: function (type)
{ {
let args = Array.slice(arguments, 1); let args = Array.slice(arguments, 1);

View File

@@ -40,6 +40,8 @@ function CommandLine() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
const callbacks = {};
storage.newArray("history-search", true, { privateData: true }); storage.newArray("history-search", true, { privateData: true });
storage.newArray("history-command", true, { privateData: true }); storage.newArray("history-command", true, { privateData: true });
@@ -126,7 +128,7 @@ function CommandLine() //{{{
replace: function (val) replace: function (val)
{ {
this.input.value = val; this.input.value = val;
liberator.triggerCallback("change", currentExtendedMode, val); commandline.triggerCallback("change", currentExtendedMode, val);
}, },
/** /**
@@ -259,7 +261,7 @@ function CommandLine() //{{{
{ {
this.context.reset(); this.context.reset();
this.context.tabPressed = tabPressed; this.context.tabPressed = tabPressed;
liberator.triggerCallback("complete", currentExtendedMode, this.context); commandline.triggerCallback("complete", currentExtendedMode, this.context);
this.context.updateAsync = true; this.context.updateAsync = true;
this.reset(show, tabPressed); this.reset(show, tabPressed);
this.wildIndex = 0; this.wildIndex = 0;
@@ -522,52 +524,6 @@ function CommandLine() //{{{
completions.tab(event.shiftKey); completions.tab(event.shiftKey);
}); });
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// CALLBACKS ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
var input = {};
liberator.registerCallback("submit", modes.EX, function (command) {
commands.repeat = command;
liberator.execute(command);
});
liberator.registerCallback("complete", modes.EX, function (context) {
context.fork("ex", 0, completion, "ex");
});
liberator.registerCallback("change", modes.EX, function (command) {
autocompleteTimer.tell(false);
});
liberator.registerCallback("cancel", modes.PROMPT, cancelPrompt);
liberator.registerCallback("submit", modes.PROMPT, closePrompt);
liberator.registerCallback("change", modes.PROMPT, function (str) {
if (input.complete)
autocompleteTimer.tell(false);
if (input.change)
return input.change.call(commandline, str);
});
liberator.registerCallback("complete", modes.PROMPT, function (context) {
if (input.complete)
context.fork("input", 0, commandline, input.complete);
});
function cancelPrompt(value)
{
let callback = input.cancel;
input = {};
if (callback)
callback.call(commandline, value != null ? value : commandline.command);
}
function closePrompt(value)
{
let callback = input.submit;
input = {};
if (callback)
callback.call(commandline, value != null ? value : commandline.command);
}
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// VARIABLES /////////////////////////////////////////////// ////////////////////// VARIABLES ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
@@ -1007,7 +963,7 @@ function CommandLine() //{{{
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
return { const self = {
HL_NORMAL: "Normal", HL_NORMAL: "Normal",
HL_ERRORMSG: "ErrorMsg", HL_ERRORMSG: "ErrorMsg",
@@ -1038,6 +994,25 @@ function CommandLine() //{{{
}); });
}, },
// @param type can be:
// "submit": when the user pressed enter in the command line
// "change"
// "cancel"
// "complete"
registerCallback: function (type, mode, func)
{
if (!(type in callbacks))
callbacks[type] = {};
callbacks[type][mode] = func;
},
triggerCallback: function (type, mode, data)
{
if (callbacks[type] && callbacks[type][mode])
return callbacks[type][mode].call(this, data);
return false;
},
runSilently: function (func, self) runSilently: function (func, self)
{ {
let wasSilent = this.silent; let wasSilent = this.silent;
@@ -1071,7 +1046,7 @@ function CommandLine() //{{{
* Open the command line. The main mode is set to * Open the command line. The main mode is set to
* COMMAND_LINE, the extended mode to <b>extendedMode</b>. * COMMAND_LINE, the extended mode to <b>extendedMode</b>.
* Further, callbacks defined for <b>extendedMode</b> are * Further, callbacks defined for <b>extendedMode</b> are
* triggered as appropriate (see {@link liberator#registerCallback}). * triggered as appropriate (see {@link #registerCallback}).
* *
* @param {string} prompt * @param {string} prompt
* @param {string} cmd * @param {string} cmd
@@ -1099,7 +1074,7 @@ function CommandLine() //{{{
// open the completion list automatically if wanted // open the completion list automatically if wanted
if (cmd.length) if (cmd.length)
liberator.triggerCallback("change", currentExtendedMode, cmd); commandline.triggerCallback("change", currentExtendedMode, cmd);
}, },
/** /**
@@ -1111,7 +1086,7 @@ function CommandLine() //{{{
{ {
let mode = currentExtendedMode; let mode = currentExtendedMode;
currentExtendedMode = null; currentExtendedMode = null;
liberator.triggerCallback("cancel", mode); commandline.triggerCallback("cancel", mode);
if (history) if (history)
history.save(); history.save();
@@ -1313,7 +1288,7 @@ function CommandLine() //{{{
else if (event.type == "input") else if (event.type == "input")
{ {
this.resetCompletions(); this.resetCompletions();
liberator.triggerCallback("change", currentExtendedMode, command); commandline.triggerCallback("change", currentExtendedMode, command);
} }
else if (event.type == "keypress") else if (event.type == "keypress")
{ {
@@ -1333,7 +1308,7 @@ function CommandLine() //{{{
currentExtendedMode = null; // Don't let modes.pop trigger "cancel" currentExtendedMode = null; // Don't let modes.pop trigger "cancel"
modes.pop(!this.silent); modes.pop(!this.silent);
return liberator.triggerCallback("submit", mode, command); return commandline.triggerCallback("submit", mode, command);
} }
// user pressed UP or DOWN arrow to cycle history completion // user pressed UP or DOWN arrow to cycle history completion
else if (/^(<Up>|<Down>|<S-Up>|<S-Down>|<PageUp>|<PageDown>)$/.test(key)) else if (/^(<Up>|<Down>|<S-Up>|<S-Down>|<PageUp>|<PageDown>)$/.test(key))
@@ -1363,7 +1338,7 @@ function CommandLine() //{{{
// and blur the command line if there is no text left // and blur the command line if there is no text left
if (command.length == 0) if (command.length == 0)
{ {
liberator.triggerCallback("cancel", currentExtendedMode); commandline.triggerCallback("cancel", currentExtendedMode);
modes.pop(); modes.pop();
} }
} }
@@ -1702,7 +1677,56 @@ function CommandLine() //{{{
history.reset(); history.reset();
} }
}; };
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// CALLBACKS ///////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
var input = {};
self.registerCallback("submit", modes.EX, function (command) {
commands.repeat = command;
liberator.execute(command);
});
self.registerCallback("complete", modes.EX, function (context) {
context.fork("ex", 0, completion, "ex");
});
self.registerCallback("change", modes.EX, function (command) {
autocompleteTimer.tell(false);
});
self.registerCallback("cancel", modes.PROMPT, cancelPrompt);
self.registerCallback("submit", modes.PROMPT, closePrompt);
self.registerCallback("change", modes.PROMPT, function (str) {
if (input.complete)
autocompleteTimer.tell(false);
if (input.change)
return input.change.call(commandline, str);
});
self.registerCallback("complete", modes.PROMPT, function (context) {
if (input.complete)
context.fork("input", 0, commandline, input.complete);
});
function cancelPrompt(value)
{
let callback = input.cancel;
input = {};
if (callback)
callback.call(commandline, value != null ? value : commandline.command);
}
function closePrompt(value)
{
let callback = input.submit;
input = {};
if (callback)
callback.call(commandline, value != null ? value : commandline.command);
}
//}}} //}}}
return self;
}; //}}} }; //}}}
/** /**

View File

@@ -15,9 +15,9 @@ function Player() // {{{
services.add("propertyManager","@songbirdnest.com/Songbird/Properties/PropertyManager;1", Ci.sbIPropertyManager); services.add("propertyManager","@songbirdnest.com/Songbird/Properties/PropertyManager;1", Ci.sbIPropertyManager);
// Register Callbacks for searching. // Register Callbacks for searching.
liberator.registerCallback("change", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchKeyPress(str); }); commandline.registerCallback("change", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchKeyPress(str); });
liberator.registerCallback("submit", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchSubmit(str); }); commandline.registerCallback("submit", modes.SEARCH_VIEW_FORWARD, function (str) { player.onSearchSubmit(str); });
liberator.registerCallback("cancel", modes.SEARCH_VIEW_FORWARD, function () { player.onSearchCancel(); }); commandline.registerCallback("cancel", modes.SEARCH_VIEW_FORWARD, function () { player.onSearchCancel(); });
// interval (milliseconds) // interval (milliseconds)
function seek(interval, direction) function seek(interval, direction)