Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max number of rows option for keyboard event viewer #365

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tools/key-event-viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
font-size: 10pt;
}

#maxNumberOfRows {
width: 40px;
}

.opttable {
border: 1px solid black;
}
Expand Down Expand Up @@ -95,6 +99,10 @@ input[type=checkbox]:disabled+label {
color: #a0a0a0;
}

input[type=text] {
margin: 0 3px 0 3px;
}

.keyevent_hilight {
border: 1px solid #404040;
border-radius: 4px;
Expand Down
22 changes: 20 additions & 2 deletions tools/key-event-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ function init() {
'onclick': "toggleReadonly()",
'checked': false,
}],
["input","maxNumberOfRows", "Max number of rows:", {
'onfocusout': "validateNumOfRowsInput()",
'defaultvalue': 100,
}],
["text", "Note: Options apply to new events only."],
];

Expand Down Expand Up @@ -175,9 +179,9 @@ function init() {
// =====

function onKeyDown(e) {
_isKeydown = true;
_isKeydown = true;
handleKeyEvent("keydown", e);
_isKeydown = false;
_isKeydown = false;
}

function onKeyPress(e) {
Expand Down Expand Up @@ -427,3 +431,17 @@ function toggleReadonly() {
}
setInputFocus(false);
}

function validateNumOfRowsInput() {
var input = document.getElementById("maxNumberOfRows");
var roundedInputValue = parseInt(input.value);

// Default 100 if undefined, NaN, or less than zero
if (roundedInputValue === undefined || isNaN(roundedInputValue) || roundedInputValue <= 0) {
input.value = 100;
}
// Round number if a decimal
else {
input.value = roundedInputValue;
}
}
111 changes: 74 additions & 37 deletions tools/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ function createOptions(options_div, event_info, table_info, extra) {
} else if (type == "text") {
var text = opt[1];
cell.appendChild(document.createTextNode(text));
} else if (type == "input") {
var name = opt[1];
var label = opt[2];
var options = opt[3];
addOptionInput(cell, name, label, options);
}

row.appendChild(cell);
Expand All @@ -80,11 +85,11 @@ function createOptions(options_div, event_info, table_info, extra) {
}

function addOptionTitle(cell, title) {
var span = document.createElement('span');
span.classList.add("opttitle");
span.textContent = title;
cell.appendChild(span);
cell.appendChild(document.createElement("br"));
var span = document.createElement('span');
span.classList.add("opttitle");
span.textContent = title;
cell.appendChild(span);
cell.appendChild(document.createElement("br"));
}

function addOptionCheckbox(cell, id, text, options) {
Expand All @@ -93,44 +98,76 @@ function addOptionCheckbox(cell, id, text, options) {
if (options.checked === undefined)
options.checked = true;

var input = document.createElement("input");
input.type = "checkbox";
input.id = id;
input.checked = options.checked;
input.disabled = !options.enabled;
if (options.onclick != undefined && options.onclick != "") {
input.setAttribute("onclick", options.onclick);
}
cell.appendChild(input);

var label = document.createElement("label");
label.setAttribute("for", id);
var span = document.createElement('span');
if (options.class !== undefined) {
for (var c of options.class.split(' ')) {
span.classList.add(c);
var input = document.createElement("input");
input.type = "checkbox";
input.id = id;
input.checked = options.checked;
input.disabled = !options.enabled;
if (options.onclick != undefined && options.onclick != "") {
input.setAttribute("onclick", options.onclick);
}
cell.appendChild(input);

var label = document.createElement("label");
label.setAttribute("for", id);
var span = document.createElement('span');
if (options.class !== undefined) {
for (var c of options.class.split(' ')) {
span.classList.add(c);
}
}
span.appendChild(document.createTextNode(text));
label.appendChild(span);
cell.appendChild(label);
span.appendChild(document.createTextNode(text));
label.appendChild(span);
cell.appendChild(label);

cell.appendChild(document.createElement("br"));
}

function addOptionInput(cell, id, text, options) {
var label = document.createElement("label");
label.setAttribute("for", id);
var span = document.createElement('span');
if (options.class !== undefined) {
for (var c of options.class.split(' ')) {
span.classList.add(c);
}
}

span.appendChild(document.createTextNode(text));
label.appendChild(span);
cell.appendChild(label);

if (options.enabled === undefined)
options.enabled = true;
if (options.defaultvalue === undefined)
options.defaultvalue = "";

var input = document.createElement("input");
input.type = "text";
input.id = id;
input.value = options.defaultvalue;
input.disabled = !options.enabled;
if (options.onfocusout !== undefined && options.onfocusout != "") {
input.setAttribute("onfocusout", options.onfocusout);
}
cell.appendChild(input);

cell.appendChild(document.createElement("br"));
cell.appendChild(document.createElement("br"));
}

function addOptionText(cell, prefix, id, text) {
var span1 = document.createElement('span');
span1.classList.add("opttext");
span1.appendChild(document.createTextNode(prefix));

var span2 = document.createElement('span');
span2.id = id;
span2.textContent = 0;
span1.appendChild(span2);
span1.appendChild(document.createTextNode(text));

cell.appendChild(span1);
cell.appendChild(document.createElement("br"));
var span1 = document.createElement('span');
span1.classList.add("opttext");
span1.appendChild(document.createTextNode(prefix));

var span2 = document.createElement('span');
span2.id = id;
span2.textContent = 0;
span1.appendChild(span2);
span1.appendChild(document.createTextNode(text));

cell.appendChild(span1);
cell.appendChild(document.createElement("br"));
}

function toggleOptions() {
Expand Down
17 changes: 14 additions & 3 deletions tools/output-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// * There is a 'subheader' CSS class for the 2nd header row.

var NUM_HEADER_ROWS = 2;
var MAX_OUTPUT_ROWS = 100 + NUM_HEADER_ROWS;
var DEFAULT_MAX_OUTPUT_ROWS = 100;

// Sequence ID for numbering events.
var _seqId = 1;
Expand Down Expand Up @@ -119,13 +119,13 @@ function deleteLastOutputRow() {
function addOutputRow(extra_class) {
var table = document.getElementById("output");

while (table.rows.length >= MAX_OUTPUT_ROWS) {
while (table.rows.length >= maxNumberOfRows()) {
table.deleteRow(-1);
}
// Insert after the header rows.
var row = table.insertRow(NUM_HEADER_ROWS);
if (extra_class) {
row.classList.add(extra_class);
row.classList.add(extra_class);
}
return row;
}
Expand Down Expand Up @@ -273,3 +273,14 @@ function calcString(data) {
}
return "'" + data + "'";
}

function maxNumberOfRows() {
var input = document.getElementById("maxNumberOfRows");
var numberOfRows = DEFAULT_MAX_OUTPUT_ROWS;
if (input !== undefined) {
numberOfRows = parseInt(input.value);
}

var maxRows = numberOfRows + NUM_HEADER_ROWS;
return maxRows;
}