mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 21:07:59 +01:00
merge MOW improvements
This commit is contained in:
105
content/ui.js
105
content/ui.js
@@ -133,41 +133,42 @@ function CommandLine() //{{{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sets the prompt - for example, : or /
|
// sets the prompt - for example, : or /
|
||||||
function setPrompt(prompt)
|
function setPrompt(pmt)
|
||||||
{
|
{
|
||||||
if (typeof prompt != "string")
|
prompt_widget.value = pmt;
|
||||||
prompt = "";
|
|
||||||
|
|
||||||
prompt_widget.value = prompt;
|
if (pmt)
|
||||||
if (prompt)
|
|
||||||
{
|
{
|
||||||
// initially (in the xul) the prompt is 'collapsed', this makes
|
prompt_widget.size = pmt.length;
|
||||||
// sure it's visible, then we toggle the display which works better
|
prompt_widget.collapsed = false;
|
||||||
prompt_widget.style.visibility = 'visible';
|
|
||||||
prompt_widget.style.display = 'inline';
|
|
||||||
prompt_widget.size = prompt.length;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
prompt_widget.style.display = 'none';
|
prompt_widget.collapsed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sets the command - e.g. 'tabopen', 'open http://example.com/'
|
// sets the command - e.g. 'tabopen', 'open http://example.com/'
|
||||||
function setCommand(cmd)
|
function setCommand(cmd)
|
||||||
{
|
{
|
||||||
command_widget.hidden = false;
|
|
||||||
command_widget.value = cmd;
|
command_widget.value = cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setLine(str, highlight_group)
|
||||||
|
{
|
||||||
|
setHighlightGroup(highlight_group);
|
||||||
|
setPrompt("");
|
||||||
|
setCommand(str);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: extract CSS
|
// TODO: extract CSS
|
||||||
// : resize upon a window resize
|
// : resize upon a window resize
|
||||||
// : echoed lines longer than v-c-c.width should wrap and use MOW
|
// : echoed lines longer than v-c-c.width should wrap and use MOW
|
||||||
function setMultiline(str)
|
function setMultiline(str, highlight_group)
|
||||||
{
|
{
|
||||||
multiline_input_widget.collapsed = true;
|
multiline_input_widget.collapsed = true;
|
||||||
|
|
||||||
var output = "<div class=\"ex-command-output\">" + str + "</div>";
|
var output = "<div class=\"ex-command-output " + highlight_group + "\">" + str + "</div>";
|
||||||
if (!multiline_output_widget.collapsed)
|
if (!multiline_output_widget.collapsed)
|
||||||
{
|
{
|
||||||
// FIXME: need to make sure an open MOW is closed when commands
|
// FIXME: need to make sure an open MOW is closed when commands
|
||||||
@@ -197,23 +198,18 @@ function CommandLine() //{{{
|
|||||||
if (vimperator.options["more"] && multiline_output_widget.contentWindow.scrollMaxY > 0)
|
if (vimperator.options["more"] && multiline_output_widget.contentWindow.scrollMaxY > 0)
|
||||||
{
|
{
|
||||||
// start the last executed command's output at the top of the screen
|
// start the last executed command's output at the top of the screen
|
||||||
var elements = multiline_output_widget.contentDocument.getElementsByTagName("div");
|
var elements = vimperator.buffer.evaluateXPath("//div[contains(@class, 'ex-command-output')]", multiline_output_widget.contentDocument);
|
||||||
for (var i = 0; i < elements.length; i++)
|
elements.snapshotItem(elements.snapshotLength - 1).scrollIntoView(true);
|
||||||
{
|
|
||||||
if (elements[i].className != "ex-command-output")
|
|
||||||
elements.splice(i, 1);
|
|
||||||
}
|
|
||||||
elements[elements.length - 1].scrollIntoView(true);
|
|
||||||
|
|
||||||
if (multiline_output_widget.contentWindow.scrollY >= multiline_output_widget.contentWindow.scrollMaxY)
|
if (multiline_output_widget.contentWindow.scrollY >= multiline_output_widget.contentWindow.scrollMaxY)
|
||||||
vimperator.commandline.echo("Press ENTER or type command to continue", vimperator.commandline.HL_QUESTION);
|
setLine("Press ENTER or type command to continue", vimperator.commandline.HL_QUESTION);
|
||||||
else
|
else
|
||||||
vimperator.commandline.echo("-- More --", vimperator.commandline.HL_MOREMSG);
|
setLine("-- More --", vimperator.commandline.HL_QUESTION);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
multiline_output_widget.contentWindow.scrollTo(0, content_height);
|
multiline_output_widget.contentWindow.scrollTo(0, content_height);
|
||||||
vimperator.commandline.echo("Press ENTER or type command to continue", vimperator.commandline.HL_QUESTION);
|
setLine("Press ENTER or type command to continue", vimperator.commandline.HL_QUESTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
multiline_output_widget.contentWindow.focus();
|
multiline_output_widget.contentWindow.focus();
|
||||||
@@ -253,7 +249,10 @@ function CommandLine() //{{{
|
|||||||
// not yet used
|
// not yet used
|
||||||
this.FORCE_MULTILINE = 1 << 0;
|
this.FORCE_MULTILINE = 1 << 0;
|
||||||
this.FORCE_SINGLELINE = 1 << 1;
|
this.FORCE_SINGLELINE = 1 << 1;
|
||||||
this.FORCE_ECHO = 1 << 2; // also echoes if the commandline has focus
|
this.DISALLOW_MULTILINE = 1 << 2; // if an echo() should try to use the single line,
|
||||||
|
// but output nothing when the MOW is open; when also
|
||||||
|
// FORCE_MULTILINE is given, FORCE_MULTILINE takes precedence
|
||||||
|
this.APPEND_TO_MESSAGES = 1 << 3; // will show the string in :messages
|
||||||
|
|
||||||
this.getCommand = function()
|
this.getCommand = function()
|
||||||
{
|
{
|
||||||
@@ -268,13 +267,13 @@ function CommandLine() //{{{
|
|||||||
cur_command = cmd || "";
|
cur_command = cmd || "";
|
||||||
cur_extended_mode = ext_mode || null;
|
cur_extended_mode = ext_mode || null;
|
||||||
|
|
||||||
setHighlightGroup(this.HL_NORMAL);
|
|
||||||
history_index = UNINITIALIZED;
|
history_index = UNINITIALIZED;
|
||||||
completion_index = UNINITIALIZED;
|
completion_index = UNINITIALIZED;
|
||||||
|
|
||||||
// save the mode, because we need to restore it
|
// save the mode, because we need to restore it
|
||||||
[old_mode, old_extended_mode] = vimperator.getMode();
|
[old_mode, old_extended_mode] = vimperator.getMode();
|
||||||
vimperator.setMode(vimperator.modes.COMMAND_LINE, cur_extended_mode, true);
|
vimperator.setMode(vimperator.modes.COMMAND_LINE, cur_extended_mode, true);
|
||||||
|
setHighlightGroup(this.HL_NORMAL);
|
||||||
setPrompt(cur_prompt);
|
setPrompt(cur_prompt);
|
||||||
setCommand(cur_command);
|
setCommand(cur_command);
|
||||||
|
|
||||||
@@ -291,40 +290,36 @@ function CommandLine() //{{{
|
|||||||
this.clear();
|
this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: flags not yet really functional --mst
|
// TODO: add :messages entry
|
||||||
// multiline string don't obey highlight_group
|
// vimperator.echo uses different order of flags as it omits the hightlight group, change v.commandline.echo argument order? --mst
|
||||||
this.echo = function(str, highlight_group, flags)
|
this.echo = function(str, highlight_group, flags)
|
||||||
{
|
{
|
||||||
var focused = document.commandDispatcher.focusedElement;
|
var focused = document.commandDispatcher.focusedElement;
|
||||||
if (focused && focused == command_widget.inputField || focused == multiline_input_widget.inputField)
|
if (focused && focused == command_widget.inputField || focused == multiline_input_widget.inputField)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (typeof str != "string")
|
|
||||||
str = "";
|
|
||||||
|
|
||||||
highlight_group = highlight_group || this.HL_NORMAL;
|
highlight_group = highlight_group || this.HL_NORMAL;
|
||||||
setHighlightGroup(highlight_group);
|
|
||||||
if (flags /*|| !multiline_output_widget.collapsed*/ || /\n|<br\/?>/.test(str))
|
var where = setLine;
|
||||||
|
if (flags & this.FORCE_MULTILINE)
|
||||||
|
where = setMultiline;
|
||||||
|
else if (flags & this.FORCE_SINGLELINE)
|
||||||
|
where = setLine;
|
||||||
|
else if (!multiline_output_widget.collapsed)
|
||||||
{
|
{
|
||||||
setMultiline(str);
|
if (flags & this.DISALLOW_MULTILINE)
|
||||||
}
|
where = null;
|
||||||
else
|
else
|
||||||
{
|
where = setMultiline;
|
||||||
if (!str)
|
|
||||||
str = "";
|
|
||||||
|
|
||||||
setCommand("");
|
|
||||||
setPrompt(str);
|
|
||||||
// FIXME: this causes the commandline to lose focus in FF2
|
|
||||||
//command_widget.hidden = true;
|
|
||||||
|
|
||||||
// initially (in the xul) the prompt is 'collapsed', this makes
|
|
||||||
// sure it's visible, then we toggle the display which works better
|
|
||||||
prompt_widget.style.visibility = 'visible';
|
|
||||||
prompt_widget.style.display = 'inline';
|
|
||||||
prompt_widget.size = str.length;
|
|
||||||
}
|
}
|
||||||
|
else if (/\n|<br\/?>/.test(str))
|
||||||
|
where = setMultiline;
|
||||||
|
|
||||||
|
if (where)
|
||||||
|
where(str, highlight_group);
|
||||||
|
|
||||||
cur_extended_mode = null;
|
cur_extended_mode = null;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -334,9 +329,7 @@ function CommandLine() //{{{
|
|||||||
{
|
{
|
||||||
// TODO: unfinished, need to find out how/if we can block the execution of code
|
// TODO: unfinished, need to find out how/if we can block the execution of code
|
||||||
// to make this code synchronous or at least use a callback
|
// to make this code synchronous or at least use a callback
|
||||||
setHighlightGroup(this.HL_QUESTION);
|
setLine(str, this.HL_QUESTION);
|
||||||
setPrompt(str);
|
|
||||||
setCommand("");
|
|
||||||
command_widget.focus();
|
command_widget.focus();
|
||||||
return "not implemented";
|
return "not implemented";
|
||||||
};
|
};
|
||||||
@@ -368,7 +361,7 @@ function CommandLine() //{{{
|
|||||||
multiline_output_widget.collapsed = true;
|
multiline_output_widget.collapsed = true;
|
||||||
completionlist.hide();
|
completionlist.hide();
|
||||||
|
|
||||||
this.echo("");
|
setLine("", this.HL_NORMAL);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.onEvent = function(event)
|
this.onEvent = function(event)
|
||||||
@@ -811,11 +804,11 @@ function CommandLine() //{{{
|
|||||||
else // set update the prompt string
|
else // set update the prompt string
|
||||||
{
|
{
|
||||||
if (show_more_help_prompt)
|
if (show_more_help_prompt)
|
||||||
this.echo("-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit", this.HL_MOREMSG);
|
setLine("-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit", this.HL_MOREMSG);
|
||||||
else if (show_more_prompt || (vimperator.options["more"] && isScrollable() && !atEnd()))
|
else if (show_more_prompt || (vimperator.options["more"] && isScrollable() && !atEnd()))
|
||||||
this.echo("-- More --", this.HL_MOREMSG);
|
setLine("-- More --", this.HL_MOREMSG);
|
||||||
else
|
else
|
||||||
this.echo("Press ENTER or type command to continue", this.HL_QUESTION);
|
setLine("Press ENTER or type command to continue", this.HL_QUESTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
|
|||||||
|
|
||||||
<hbox id="vimperator-commandline" hidden="false" class="hl-Normal">
|
<hbox id="vimperator-commandline" hidden="false" class="hl-Normal">
|
||||||
<label class="plain" id="vimperator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/>
|
<label class="plain" id="vimperator-commandline-prompt" flex="0" crop="end" value="" collapsed="true"/>
|
||||||
<textbox class="plain" id="vimperator-commandline-command" flex="1" hidden="false" type="timed" timeout="100"
|
<textbox class="plain" id="vimperator-commandline-command" flex="1" type="timed" timeout="100"
|
||||||
onkeypress="vimperator.commandline.onEvent(event);"
|
onkeypress="vimperator.commandline.onEvent(event);"
|
||||||
oninput="vimperator.commandline.onEvent(event);"
|
oninput="vimperator.commandline.onEvent(event);"
|
||||||
onfocus="vimperator.commandline.onEvent(event);"
|
onfocus="vimperator.commandline.onEvent(event);"
|
||||||
|
|||||||
Reference in New Issue
Block a user