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

Added liberator.commandline.input() to prompt the user. Added prompt when opening too many tabs.

This commit is contained in:
Kris Maglione
2008-09-10 04:28:11 +00:00
parent 161278a172
commit 4b6c27b1e7
8 changed files with 98 additions and 63 deletions

View File

@@ -429,16 +429,7 @@ liberator.Bookmarks = function () //{{{
} }
if (openItems) if (openItems)
{ return liberator.openTabs((i[0] for (i in items)), items.length);
// FIXME: use yes/no question
if (items.length > 50)
return liberator.echoerr("For now, you can only open a hard limit of 50 items at once");
for (var i = 0; i < items.length; i++)
liberator.open(items[i][0], liberator.NEW_TAB);
return;
}
var title, url, tags, keyword, extra; var title, url, tags, keyword, extra;
var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" + var list = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" +
@@ -739,14 +730,7 @@ liberator.History = function () //{{{
if (openItems) if (openItems)
{ {
// FIXME: use yes/no question return liberator.openTabs((i[0] for (i in items)), items.length);
if (items.length > 50)
return liberator.echoerr("For now, you can only open a hard limit of 50 items at once");
for (var i = 0; i < items.length; i++)
liberator.open(items[i][0], liberator.NEW_TAB);
return;
} }
else else
{ {

View File

@@ -338,9 +338,8 @@ liberator.Buffer = function () //{{{
"//xhtml:input[not(@type) or @type='text' or @type='password'] | //xhtml:textarea[not(@disabled) and not(@readonly)]" "//xhtml:input[not(@type) or @type='text' or @type='password'] | //xhtml:textarea[not(@disabled) and not(@readonly)]"
); );
for (let i = 0; i < matches.snapshotLength; i++) for (match in matches)
{ {
let match = matches.snapshotItem(i);
let computedStyle = window.content.getComputedStyle(match, null); let computedStyle = window.content.getComputedStyle(match, null);
if (computedStyle.getPropertyValue("visibility") != "hidden" && computedStyle.getPropertyValue("display") != "none") if (computedStyle.getPropertyValue("visibility") != "hidden" && computedStyle.getPropertyValue("display") != "none")
@@ -693,6 +692,10 @@ liberator.Buffer = function () //{{{
null null
); );
result.__iterator__ = asIterator
? function() { let elem; while((elem = this.iterateNext())) yield elem }
: function() { for(let i = 0; i < this.snapshotLength; i++) yield this.snapshotItem(i) };
return result; return result;
}, },

View File

@@ -242,18 +242,12 @@ liberator.Completion = function () //{{{
{ {
var wigRegexp = new RegExp("(^" + liberator.options["wildignore"].replace(",", "|", "g") + ")$"); var wigRegexp = new RegExp("(^" + liberator.options["wildignore"].replace(",", "|", "g") + ")$");
files = files.filter(function (f) { files = files.filter(function (f) f.isDirectory() || !wigRegexp.test(f.leafName))
return f.isDirectory() || !wigRegexp.test(f.leafName);
});
} }
mapped = files.map(function (file) { mapped = files.map(function (file) [tail ? file.leafName : (dir + file.leafName),
return [tail ? file.leafName : (dir + file.leafName), file.isDirectory() ? "Directory" : "File"]; file.isDirectory() ? "Directory" : "File"])
}).sort(function (a, b) { .sort(function (a, b) a[1].localeCompare(b[1]) || a[0].localeCompare(b[0]))
return a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0;
}).sort(function (a, b) {
return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
});
} }
catch (e) catch (e)
{ {

View File

@@ -96,7 +96,7 @@ liberator.Hints = function () //{{{
var fragment = doc.createDocumentFragment(); var fragment = doc.createDocumentFragment();
var start = hints.length; var start = hints.length;
while ((elem = res.iterateNext()) != null) for (let elem in res)
{ {
// TODO: for iframes, this calculation is wrong // TODO: for iframes, this calculation is wrong
rect = elem.getBoundingClientRect(); rect = elem.getBoundingClientRect();
@@ -604,8 +604,8 @@ liberator.Hints = function () //{{{
}); });
liberator.options.add(["wordseparators", "wsp"], liberator.options.add(["wordseparators", "wsp"],
"How words are splitted for hintmatching", "How words are split for hintmatching",
"string", '[\\.,!\\?:;/\\\"\\^\\$%&§\\(\\)\\[\\]\\{\\}<>#\\*\\+\\|=~ _\\-]'); "string", '[\\.,!\\?:;/\\\"\\^\\$%&?\\(\\)\\[\\]\\{\\}<>#\\*\\+\\|=~ _\\-]');
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// MAPPINGS //////////////////////////////////////////////// ////////////////////// MAPPINGS ////////////////////////////////////////////////

View File

@@ -759,8 +759,9 @@ lookup:
} }
catch (e) catch (e)
{ {
Components.utils.reportError("Sourcing file: " + filename + ": " + e);
if (!silent) if (!silent)
liberator.echoerr(e); liberator.echoerr("Sourcing file: " + filename + ": " + e);
} }
} }
}; //}}} }; //}}}

View File

@@ -37,6 +37,7 @@ const liberator = (function () //{{{
function loadModule(name, func) function loadModule(name, func)
{ {
liberator.log("Loading module " + name + "...", 0); liberator.log("Loading module " + name + "...", 0);
liberator.dump("Loading module " + name + "...");
liberator[name] = func(); liberator[name] = func();
} }
@@ -915,6 +916,24 @@ const liberator = (function () //{{{
return true; return true;
}, },
/* Not really ideal. I'd like open to do this. */
openTabs: function(uris, length)
{
let open = function()
{
for each (let uri in uris)
liberator.open(uri, liberator.NEW_TAB);
}
if ((length || uris.length) > 50)
liberator.commandline.input("This will open " + (length || uris.length) + " new tabs. Would you like to continue? (yes/[no])",
function(resp) { if(resp.match(/^y(es)?$/i)) open() },
{
completer: function(filter) [0, [["yes", "Open all in tabs"], ["no", "Cancel"]]],
});
else
open();
},
// namespace for plugins/scripts. Actually (only) the active plugin must/can set a // namespace for plugins/scripts. Actually (only) the active plugin must/can set a
// v.plugins.mode = <str> string to show on v.modes.CUSTOM // v.plugins.mode = <str> string to show on v.modes.CUSTOM
// v.plugins.stop = <func> hooked on a v.modes.reset() // v.plugins.stop = <func> hooked on a v.modes.reset()
@@ -967,7 +986,7 @@ const liberator = (function () //{{{
// TODO: move to {muttator,vimperator,...}.js // TODO: move to {muttator,vimperator,...}.js
// this function is called, when the chrome is ready // this function is called when the chrome is ready
startup: function () startup: function ()
{ {
liberator.log("Initializing liberator object...", 0); liberator.log("Initializing liberator object...", 0);
@@ -1030,7 +1049,7 @@ const liberator = (function () //{{{
{ {
var files = liberator.io.readDirectory(pluginDir.path); var files = liberator.io.readDirectory(pluginDir.path);
liberator.log("Sourcing plugin directory...", 3); liberator.log("Sourcing plugin directory...", 3);
files.forEach(function (file) { files.sort(function(a, b) String(a.path).localeCompare(b.path)).forEach(function (file) {
if (!file.isDirectory() && /\.(js|vimp)$/i.test(file.path)) if (!file.isDirectory() && /\.(js|vimp)$/i.test(file.path))
liberator.io.source(file.path, false); liberator.io.source(file.path, false);
}); });

View File

@@ -40,6 +40,8 @@ liberator.modes = (function () //{{{
var isRecording = false; var isRecording = false;
var isReplaying = false; // playing a macro var isReplaying = false; // playing a macro
var modeStack = [];
function getModeMessage() function getModeMessage()
{ {
if (passNextKey && !passAllKeys) if (passNextKey && !passAllKeys)
@@ -179,6 +181,7 @@ liberator.modes = (function () //{{{
MENU: 1 << 19, // a popupmenu is active MENU: 1 << 19, // a popupmenu is active
LINE: 1 << 20, // linewise visual mode LINE: 1 << 20, // linewise visual mode
RECORDING: 1 << 21, RECORDING: 1 << 21,
PROMPT: 1 << 22,
__iterator__: function () __iterator__: function ()
{ {
@@ -237,6 +240,18 @@ liberator.modes = (function () //{{{
this.show(); this.show();
}, },
push: function(mainMode, extendedMode, silent)
{
modeStack.push([main, extended]);
this.set(mainMode, extendedMode, silent);
},
pop: function() {
var a = modeStack.pop();
if (a)
[main, extended] = a;
},
setCustomMode: function (modestr, oneventfunc, stopfunc) setCustomMode: function (modestr, oneventfunc, stopfunc)
{ {
// TODO this.plugin[id]... ('id' maybe submode or what..) // TODO this.plugin[id]... ('id' maybe submode or what..)
@@ -248,6 +263,7 @@ liberator.modes = (function () //{{{
// keeps recording state // keeps recording state
reset: function (silent) reset: function (silent)
{ {
modeStack = [];
if (liberator.config.isComposeWindow) if (liberator.config.isComposeWindow)
this.set(liberator.modes.COMPOSE, liberator.modes.NONE, silent); this.set(liberator.modes.COMPOSE, liberator.modes.NONE, silent);
else else
@@ -260,19 +276,19 @@ liberator.modes = (function () //{{{
this.show(); this.show();
}, },
get passNextKey() { return passNextKey; }, get passNextKey() passNextKey,
set passNextKey(value) { passNextKey = value; this.show(); }, set passNextKey(value) { passNextKey = value; this.show(); },
get passAllKeys() { return passAllKeys; }, get passAllKeys() passAllKeys,
set passAllKeys(value) { passAllKeys = value; this.show(); }, set passAllKeys(value) { passAllKeys = value; this.show(); },
get isRecording() { return isRecording; }, get isRecording() isRecording,
set isRecording(value) { isRecording = value; this.show(); }, set isRecording(value) { isRecording = value; this.show(); },
get isReplaying() { return isReplaying; }, get isReplaying() isReplaying,
set isReplaying(value) { isReplaying = value; }, set isReplaying(value) { isReplaying = value; },
get main() { return main; }, get main() main,
set main(value) { set main(value) {
if (value != main) if (value != main)
handleModeChange(main, value); handleModeChange(main, value);
@@ -283,7 +299,7 @@ liberator.modes = (function () //{{{
this.show(); this.show();
}, },
get extended() { return extended; }, get extended() extended,
set extended(value) { set extended(value) {
extended = value; this.show(); extended = value; this.show();
} }

View File

@@ -123,13 +123,15 @@ liberator.CommandLine = function () //{{{
var currentExtendedMode = null; // the extended mode which we last openend the command line for var currentExtendedMode = null; // the extended mode which we last openend the command line for
var currentPrompt = null; var currentPrompt = null;
var currentCommand = null; var currentCommand = null;
var oldMode = null; // when we leave the command prompt this mode is restored
var oldExtendedMode = null;
// save the arguments for the inputMultiline method which are needed in the event handler // save the arguments for the inputMultiline method which are needed in the event handler
var multilineRegexp = null; var multilineRegexp = null;
var multilineCallback = null; var multilineCallback = null;
// callback for prompt mode
var promptCallback = null;
var promptCompleter = null;
liberator.registerCallback("change", liberator.modes.EX, function (command) { liberator.registerCallback("change", liberator.modes.EX, function (command) {
if (liberator.options["wildoptions"].indexOf("auto") >= 0) if (liberator.options["wildoptions"].indexOf("auto") >= 0)
{ {
@@ -138,13 +140,26 @@ liberator.CommandLine = function () //{{{
} }
}); });
function closePrompt(value)
{
let callback = promptCallback;
promptCallback = null;
currentExtendedMode = null;
liberator.commandline.clear();
callback(value);
}
liberator.registerCallback("cancel", liberator.modes.PROMPT, closePrompt);
liberator.registerCallback("submit", liberator.modes.PROMPT, closePrompt);
liberator.registerCallback("complete", liberator.modes.PROMPT,
function (str) { if (promptCompleter) return promptCompleter(str); });
function setHighlightGroup(group) function setHighlightGroup(group)
{ {
commandlineWidget.setAttribute("class", group); commandlineWidget.setAttribute("class", group);
} }
// sets the prompt - for example, : or / // sets the prompt - for example, : or /
function setPrompt(pmt) function setPrompt(pmt, highlightGroup)
{ {
promptWidget.value = pmt; promptWidget.value = pmt;
@@ -157,6 +172,7 @@ liberator.CommandLine = function () //{{{
{ {
promptWidget.collapsed = true; promptWidget.collapsed = true;
} }
promptWidget.setAttribute("class", highlightGroup || liberator.commandline.HL_QUESTION);
} }
// sets the command - e.g. 'tabopen', 'open http://example.com/' // sets the command - e.g. 'tabopen', 'open http://example.com/'
@@ -232,7 +248,7 @@ liberator.CommandLine = function () //{{{
multilineOutputWidget.contentWindow.focus(); multilineOutputWidget.contentWindow.focus();
liberator.modes.set(liberator.modes.COMMAND_LINE, liberator.modes.OUTPUT_MULTILINE); liberator.modes.push(liberator.modes.COMMAND_LINE, liberator.modes.OUTPUT_MULTILINE);
} }
function autosizeMultilineInputWidget() function autosizeMultilineInputWidget()
@@ -439,6 +455,8 @@ liberator.CommandLine = function () //{{{
// FORCE_MULTILINE is given, FORCE_MULTILINE takes precedence // FORCE_MULTILINE is given, FORCE_MULTILINE takes precedence
APPEND_TO_MESSAGES : 1 << 3, // will show the string in :messages APPEND_TO_MESSAGES : 1 << 3, // will show the string in :messages
get mode() (liberator.modes.extended == liberator.modes.EX) ? "cmd" : "search",
getCommand: function () getCommand: function ()
{ {
return commandWidget.value; return commandWidget.value;
@@ -455,10 +473,7 @@ liberator.CommandLine = function () //{{{
historyIndex = UNINITIALIZED; historyIndex = UNINITIALIZED;
completionIndex = UNINITIALIZED; completionIndex = UNINITIALIZED;
// save the mode, because we need to restore it liberator.modes.push(liberator.modes.COMMAND_LINE, currentExtendedMode);
oldMode = liberator.mode;
oldExtendedMode = liberator.mode.extended;
liberator.modes.set(liberator.modes.COMMAND_LINE, currentExtendedMode);
setHighlightGroup(this.HL_NORMAL); setHighlightGroup(this.HL_NORMAL);
setPrompt(currentPrompt); setPrompt(currentPrompt);
setCommand(currentCommand); setCommand(currentCommand);
@@ -536,13 +551,17 @@ liberator.CommandLine = function () //{{{
// this will prompt the user for a string // this will prompt the user for a string
// liberator.commandline.input("(s)ave or (o)pen the file?") // liberator.commandline.input("(s)ave or (o)pen the file?")
input: function (str) input: function (prompt, callback, extra)
{ {
// TODO: unfinished, need to find out how/if we can block the execution of code extra = extra || {};
// to make this code synchronous or at least use a callback
setLine(str, this.HL_QUESTION); promptCallback = callback;
promptCompleter = extra.completer;
liberator.modes.push(liberator.modes.COMMAND_LINE, liberator.modes.PROMPT);
currentExtendedMode = liberator.modes.PROMPT;
setPrompt(prompt + " ", this.HL_QUESTION);
setCommand(extra.default || "");
commandWidget.focus(); commandWidget.focus();
return "not implemented";
}, },
// reads a multi line input and returns the string once the last line matches // reads a multi line input and returns the string once the last line matches
@@ -550,9 +569,7 @@ liberator.CommandLine = function () //{{{
inputMultiline: function (untilRegexp, callbackFunc) inputMultiline: function (untilRegexp, callbackFunc)
{ {
// save the mode, because we need to restore it // save the mode, because we need to restore it
oldMode = liberator.mode; liberator.modes.push(liberator.modes.COMMAND_LINE, liberator.modes.INPUT_MULTILINE);
oldExtendedMode = liberator.mode.extended;
liberator.modes.set(liberator.modes.COMMAND_LINE, liberator.modes.INPUT_MULTILINE);
// 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;
@@ -600,11 +617,12 @@ liberator.CommandLine = function () //{{{
// user pressed ENTER to carry out a command // user pressed ENTER to carry out a command
// user pressing ESCAPE is handled in the global onEscape // user pressing ESCAPE is handled in the global onEscape
// FIXME: <Esc> should trigger "cancel" event
if (liberator.events.isAcceptKey(key)) if (liberator.events.isAcceptKey(key))
{ {
var mode = currentExtendedMode; // save it here, as setMode() resets it var mode = currentExtendedMode; // save it here, as setMode() resets it
history.add(command); history.add(command);
liberator.modes.reset(true); //FIXME: use mode stack liberator.modes.pop();
completionlist.hide(); completionlist.hide();
liberator.focusContent(false); liberator.focusContent(false);
liberator.statusline.updateProgress(""); // we may have a "match x of y" visible liberator.statusline.updateProgress(""); // we may have a "match x of y" visible
@@ -790,7 +808,7 @@ liberator.CommandLine = function () //{{{
if (command.length == 0) if (command.length == 0)
{ {
liberator.triggerCallback("cancel", currentExtendedMode); liberator.triggerCallback("cancel", currentExtendedMode);
liberator.modes.reset(); // FIXME: use mode stack liberator.modes.pop(); // FIXME: use mode stack
} }
} }
else // any other key else // any other key
@@ -812,14 +830,14 @@ liberator.CommandLine = function () //{{{
if (text.match(multilineRegexp)) if (text.match(multilineRegexp))
{ {
text = text.replace(multilineRegexp, ""); text = text.replace(multilineRegexp, "");
liberator.modes.set(oldMode, oldExtendedMode); liberator.modes.pop();
multilineInputWidget.collapsed = true; multilineInputWidget.collapsed = true;
multilineCallback.call(this, text); multilineCallback.call(this, text);
} }
} }
else if (liberator.events.isCancelKey(key)) else if (liberator.events.isCancelKey(key))
{ {
liberator.modes.set(oldMode, oldExtendedMode); liberator.modes.pop();
multilineInputWidget.collapsed = true; multilineInputWidget.collapsed = true;
} }
} }
@@ -1016,7 +1034,7 @@ liberator.CommandLine = function () //{{{
if (passEvent || closeWindow) if (passEvent || closeWindow)
{ {
// FIXME: use mode stack // FIXME: use mode stack
liberator.modes.reset(); liberator.modes.pop();
this.clear(); this.clear();
if (passEvent) if (passEvent)