Commit 0a216d25 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

Merge branch 'gui-code-cleanup'

parents e697e70d 86d73c3c
This diff is collapsed.
...@@ -122,10 +122,10 @@ var index_manif = new Set(); ...@@ -122,10 +122,10 @@ var index_manif = new Set();
function index_entry_esc(s) { function index_entry_esc(s) {
if (s) { if (s) {
var t = s.replace(/\\/g, "\\\\").replace(/:/g, "\\:"); var t = s.replace(/\\/g, "\\\\").replace(/:/g, "\\:");
return t.replace(/(?:\r\n|\r|\n)/g, "\\n"); return t.replace(/(?:\r\n|\r|\n)/g, "\\n");
} else { } else {
return ""; return "";
} }
} }
...@@ -151,7 +151,7 @@ function add_doc_to_index(filename, data) { ...@@ -151,7 +151,7 @@ function add_doc_to_index(filename, data) {
title = title.slice(0, -5); title = title.slice(0, -5);
} }
index_cache[index_cache.length] = [filename, title, keywords, desc] index_cache[index_cache.length] = [filename, title, keywords, desc]
.map(index_entry_esc).join(":"); .map(index_entry_esc).join(":");
var d = path.dirname(filename); var d = path.dirname(filename);
index_manif.add(d); index_manif.add(d);
// Also add the parent directory to catch additions of siblings. // Also add the parent directory to catch additions of siblings.
...@@ -200,32 +200,32 @@ function finish_index() { ...@@ -200,32 +200,32 @@ function finish_index() {
index_done = true; index_done = true;
var have_cache = index_cache.length > 0; var have_cache = index_cache.length > 0;
try { try {
// write the index cache if we have one // write the index cache if we have one
if (have_cache) { if (have_cache) {
var a = new Array(); var a = new Array();
index_manif.forEach(function(x) { index_manif.forEach(function(x) {
var st = fs.statSync(x); var st = fs.statSync(x);
a[a.length] = index_entry_esc(x) + ":" + st.mtimeMs; a[a.length] = index_entry_esc(x) + ":" + st.mtimeMs;
}); });
a.sort(); a.sort();
// Make sure that the target dir exists: // Make sure that the target dir exists:
try { try {
fs.mkdirSync(expand_tilde(path.dirname(cache_name))); fs.mkdirSync(expand_tilde(path.dirname(cache_name)));
} catch (err) { } catch (err) {
//console.log(err); //console.log(err);
} }
fs.writeFileSync(expand_tilde(cache_name), fs.writeFileSync(expand_tilde(cache_name),
index_cache.join("\n"), {mode: 0o644}); index_cache.join("\n"), {mode: 0o644});
// also write a manifest with the timestamps of all directories: // also write a manifest with the timestamps of all directories:
fs.writeFileSync(expand_tilde(stamps_name), fs.writeFileSync(expand_tilde(stamps_name),
a.join("\n"), {mode: 0o644}); a.join("\n"), {mode: 0o644});
} }
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
var t = new Date().getTime() / 1000; var t = new Date().getTime() / 1000;
post("finished " + (have_cache?"building":"loading") + " help index (" + post("finished " + (have_cache?"building":"loading") + " help index (" +
(t-index_start_time).toFixed(2) + " secs)"); (t-index_start_time).toFixed(2) + " secs)");
} }
// AG: pilfered from https://stackoverflow.com/questions/21077670 // AG: pilfered from https://stackoverflow.com/questions/21077670
...@@ -241,23 +241,23 @@ function check_timestamps(manif) ...@@ -241,23 +241,23 @@ function check_timestamps(manif)
{ {
manif = manif.split('\n'); manif = manif.split('\n');
for (var j = 0, l = manif.length; j < l; j++) { for (var j = 0, l = manif.length; j < l; j++) {
if (manif[j]) { if (manif[j]) {
var e = manif[j].replace(/\\:/g, "\x1c").split(':') var e = manif[j].replace(/\\:/g, "\x1c").split(':')
.map(x => x .map(x => x
.replace(/\x1c/g, ":") .replace(/\x1c/g, ":")
.replace(/\\n/g, "\n") .replace(/\\n/g, "\n")
.replace(/\\\\/g, "\\")); .replace(/\\\\/g, "\\"));
var dirname = e[0] ? e[0] : null; var dirname = e[0] ? e[0] : null;
var stamp = e[1] ? parseFloat(e[1]) : 0.0; var stamp = e[1] ? parseFloat(e[1]) : 0.0;
try { try {
var st = fs.statSync(dirname); var st = fs.statSync(dirname);
if (st.mtimeMs > stamp) { if (st.mtimeMs > stamp) {
return false; return false;
} }
} catch (err) { } catch (err) {
return false; return false;
} }
} }
} }
return true; return true;
} }
...@@ -292,43 +292,43 @@ function make_index() { ...@@ -292,43 +292,43 @@ function make_index() {
index_start_time = new Date().getTime() / 1000; index_start_time = new Date().getTime() / 1000;
var idx, manif; var idx, manif;
try { try {
// test for index cache and manifest // test for index cache and manifest
idx = fs.readFileSync idx = fs.readFileSync
(expand_tilde(cache_name), 'utf8'); (expand_tilde(cache_name), 'utf8');
manif = fs.readFileSync manif = fs.readFileSync
(expand_tilde(stamps_name), 'utf8'); (expand_tilde(stamps_name), 'utf8');
} catch (err) { } catch (err) {
//console.log(err); //console.log(err);
} }
if (idx && manif && check_timestamps(manif)) { if (idx && manif && check_timestamps(manif)) {
// index cache is present and up-to-date, load it // index cache is present and up-to-date, load it
post("loading cached help index from " + cache_name); post("loading cached help index from " + cache_name);
idx = idx.split('\n'); idx = idx.split('\n');
for (var j = 0, l = idx.length; j < l; j++) { for (var j = 0, l = idx.length; j < l; j++) {
if (idx[j]) { if (idx[j]) {
var e = idx[j].replace(/\\:/g, "\x1c").split(':') var e = idx[j].replace(/\\:/g, "\x1c").split(':')
.map(x => x .map(x => x
.replace(/\x1c/g, ":") .replace(/\x1c/g, ":")
.replace(/\\n/g, "\n") .replace(/\\n/g, "\n")
.replace(/\\\\/g, "\\")); .replace(/\\\\/g, "\\"));
var filename = e[0] ? e[0] : null; var filename = e[0] ? e[0] : null;
var title = e[1] ? e[1] : null; var title = e[1] ? e[1] : null;
var keywords = e[2] ? e[2] : null; var keywords = e[2] ? e[2] : null;
var descr = e[3] ? e[3] : null; var descr = e[3] ? e[3] : null;
index.addDoc({ index.addDoc({
"id": filename, "id": filename,
"title": title, "title": title,
"keywords": keywords, "keywords": keywords,
"description": descr "description": descr
}); });
} }
} }
finish_index(); finish_index();
} else { } else {
// no index cache, or it is out of date, so (re)build it now, and // no index cache, or it is out of date, so (re)build it now, and
// save the new cache along the way // save the new cache along the way
post("building help index in " + doc_path); post("building help index in " + doc_path);
dive(doc_path, read_file, browser_path?make_index_cont:finish_index); dive(doc_path, read_file, browser_path?make_index_cont:finish_index);
} }
pdsend("pd gui-busy 0"); pdsend("pd gui-busy 0");
} }
...@@ -361,10 +361,10 @@ function rebuild_index() ...@@ -361,10 +361,10 @@ function rebuild_index()
index = init_elasticlunr(); index = init_elasticlunr();
index_started = index_done = false; index_started = index_done = false;
try { try {
fs.unlink(expand_tilde(cache_name)); fs.unlink(expand_tilde(cache_name));
fs.unlink(expand_tilde(stamps_name)); fs.unlink(expand_tilde(stamps_name));
} catch (err) { } catch (err) {
//console.log(err); //console.log(err);
} }
} }
...@@ -375,15 +375,15 @@ function update_browser(doc_flag, path_flag) ...@@ -375,15 +375,15 @@ function update_browser(doc_flag, path_flag)
doc_flag = doc_flag?1:0; doc_flag = doc_flag?1:0;
path_flag = path_flag?1:0; path_flag = path_flag?1:0;
if (browser_doc !== doc_flag) { if (browser_doc !== doc_flag) {
browser_doc = doc_flag; browser_doc = doc_flag;
changed = true; changed = true;
} }
if (browser_path !== path_flag) { if (browser_path !== path_flag) {
browser_path = path_flag; browser_path = path_flag;
changed = true; changed = true;
} }
if (changed) { if (changed) {
rebuild_index(); rebuild_index();
} }
} }
...@@ -1442,13 +1442,13 @@ function update_grid(grid) { ...@@ -1442,13 +1442,13 @@ function update_grid(grid) {
// option in the gui prefs changes. // option in the gui prefs changes.
var bg = grid != 0 ? gui_editmode_svg_background : "none"; var bg = grid != 0 ? gui_editmode_svg_background : "none";
for (var cid in patchwin) { for (var cid in patchwin) {
gui(cid).get_elem("patchsvg", function(patchsvg, w) { gui(cid).get_elem("patchsvg", function(patchsvg, w) {
var editmode = patchsvg.classList.contains("editmode"); var editmode = patchsvg.classList.contains("editmode");
if (editmode) { if (editmode) {
patchwin[cid].window.document.body.style.setProperty patchwin[cid].window.document.body.style.setProperty
("background-image", bg); ("background-image", bg);
} }
}); });
} }
// Also update the showgrid flags. // Also update the showgrid flags.
set_showgrid(grid); set_showgrid(grid);
...@@ -1725,7 +1725,7 @@ var scroll = {}, ...@@ -1725,7 +1725,7 @@ var scroll = {},
var set_showgrid = function(grid) { var set_showgrid = function(grid) {
for (var cid in showgrid) { for (var cid in showgrid) {
showgrid[cid] = grid; showgrid[cid] = grid;
} }
} }
...@@ -1828,7 +1828,7 @@ function canvas_sendkey(cid, state, evt, char_code, repeat) { ...@@ -1828,7 +1828,7 @@ function canvas_sendkey(cid, state, evt, char_code, repeat) {
var shift = evt.shiftKey ? 1 : 0, var shift = evt.shiftKey ? 1 : 0,
repeat_number = repeat ? 1 : 0; repeat_number = repeat ? 1 : 0;
//post("canvas_sendkey state=" + state + " evt=" + evt + //post("canvas_sendkey state=" + state + " evt=" + evt +
// " char_code=<" + char_code + "> repeat=" + repeat); // " char_code=<" + char_code + "> repeat=" + repeat);
pdsend(cid, "key", state, char_code, shift, 1, repeat_number); pdsend(cid, "key", state, char_code, shift, 1, repeat_number);
} }
...@@ -2576,29 +2576,32 @@ function message_border_points(width, height) { ...@@ -2576,29 +2576,32 @@ function message_border_points(width, height) {
// called from pd_canvas.js text events to deal with // called from pd_canvas.js text events to deal with
// the drawing of the msg box // the drawing of the msg box
function gui_message_update_textarea_border(elem, init_width) { function gui_message_update_textarea_border(elem, init_width) {
if (elem.classList.contains("msg")) { if (elem.classList.contains("msg")) {
if (init_width) { if (init_width) {
var i, ncols = 0, var i, ncols = 0,
text = elem.innerHTML, text = elem.innerHTML,
textByLine = text.split(/\r*\n/); textByLine = text.split(/\r*\n/);
for (i = 0; i < textByLine.length; i++) { for (i = 0; i < textByLine.length; i++) {
if (textByLine[i].length > ncols) { if (textByLine[i].length > ncols) {
ncols = textByLine[i].length; ncols = textByLine[i].length;
} }
} }
configure_item(elem, { configure_item(elem, {
cols: ncols cols: ncols
}); });
gui_gobj_erase_io(elem.getAttribute("cid"), elem.getAttribute("tag")); gui_gobj_erase_io(elem.getAttribute("cid"),
} elem.getAttribute("tag"));
}
gui_message_redraw_border(
elem.getAttribute("cid"), gui_message_redraw_border(
elem.getAttribute("tag"), elem.getAttribute("cid"),
parseInt(elem.offsetWidth / elem.getAttribute("font_width")) * elem.getAttribute("font_width") + 4, elem.getAttribute("tag"),
parseInt(elem.offsetHeight / elem.getAttribute("font_height")) * elem.getAttribute("font_height") + 4 parseInt(elem.offsetWidth / elem.getAttribute("font_width"))
); * elem.getAttribute("font_width") + 4,
} parseInt(elem.offsetHeight / elem.getAttribute("font_height"))
* elem.getAttribute("font_height") + 4
);
}
} }
exports.gui_message_update_textarea_border = gui_message_update_textarea_border; exports.gui_message_update_textarea_border = gui_message_update_textarea_border;
...@@ -3331,8 +3334,8 @@ function gui_numbox_draw_text(cid,tag,text,font_size,color,xpos,ypos,basex,basey ...@@ -3331,8 +3334,8 @@ function gui_numbox_draw_text(cid,tag,text,font_size,color,xpos,ypos,basex,basey
// below. But it works for most font sizes. // below. But it works for most font sizes.
gui(cid).get_gobj(tag) gui(cid).get_gobj(tag)
.append(function(frag, w) { .append(function(frag, w) {
//post("ypos=" + ypos + " int=" + Math.floor(ypos)); //post("ypos=" + ypos + " int=" + Math.floor(ypos));
//ypos = Math.floor(ypos); //ypos = Math.floor(ypos);
var svg_text = create_item(cid, "text", { var svg_text = create_item(cid, "text", {
transform: "translate(" + transform: "translate(" +
(xpos - basex) + "," + (xpos - basex) + "," +
...@@ -5890,23 +5893,23 @@ function gui_font_dialog_change_size(did, font_size) { ...@@ -5890,23 +5893,23 @@ function gui_font_dialog_change_size(did, font_size) {
function gui_menu_font_change_size(canvas, newsize) { function gui_menu_font_change_size(canvas, newsize) {
pdsend(canvas, "menufont", newsize); pdsend(canvas, "menufont", newsize);
// ico@vt.edu 2020-08-24: changed to use submenu // ico@vt.edu 2020-08-24: changed to use submenu
// this was the following // this was the following
/*+document.querySelector('input[name="font_size"]:checked').value, //+document.querySelector('input[name="font_size"]:checked').value,
current_size, //current_size,
100, //100,
0 // "$noundo" from pd.tk-- not sure what it does*/ //0
} }
exports.gui_menu_font_change_size = gui_menu_font_change_size; exports.gui_menu_font_change_size = gui_menu_font_change_size;
function gui_menu_font_set_initial_size(cid, size) { function gui_menu_font_set_initial_size(cid, size) {
//post("gui_menu_font_set_initial_size " + cid + " " + size); //post("gui_menu_font_set_initial_size " + cid + " " + size);
gui(cid).get_nw_window(function(nw_win) { gui(cid).get_nw_window(function(nw_win) {
if (cid !== "nobody") { if (cid !== "nobody") {
nw_win.window.init_menu_font_size(size); nw_win.window.init_menu_font_size(size);
//post("this should work"); //post("this should work");
} }
}); });
} }
...@@ -5926,7 +5929,7 @@ function gui_array_new(did, count) { ...@@ -5926,7 +5929,7 @@ function gui_array_new(did, count) {
} }
function gui_canvas_dialog(did, attr_arrays) { function gui_canvas_dialog(did, attr_arrays) {
//post("gui_canvas_dialog"); //post("gui_canvas_dialog");
var i, j, inner_array, prop; var i, j, inner_array, prop;
// Convert array of arrays to an array of objects // Convert array of arrays to an array of objects
for (i = 0; i < attr_arrays.length; i++) { for (i = 0; i < attr_arrays.length; i++) {
...@@ -5940,8 +5943,8 @@ function gui_canvas_dialog(did, attr_arrays) { ...@@ -5940,8 +5943,8 @@ function gui_canvas_dialog(did, attr_arrays) {
var has_array = (attr_arrays.length > 1 ? 1 : 0); var has_array = (attr_arrays.length > 1 ? 1 : 0);
/* /*
post("array.length=" + attr_arrays.length + " has_array=" + has_array +" width=" + post("array.length=" + attr_arrays.length + " has_array=" + has_array +" width=" +
(230 - (8 * has_array)) + " height=" + (230 - (8 * has_array)) + " height=" +
(attr_arrays.length > 1 ? 494-25+(attr_arrays.length > 2 ? 38 : 0) : 392-25)); (attr_arrays.length > 1 ? 494-25+(attr_arrays.length > 2 ? 38 : 0) : 392-25));
*/ */
dialogwin[did] = create_window(did, "canvas", dialogwin[did] = create_window(did, "canvas",
// ico@vt.edu: property dialog size is larger when one has // ico@vt.edu: property dialog size is larger when one has
...@@ -6308,7 +6311,7 @@ function textarea_font_size_to_index(font_size) { ...@@ -6308,7 +6311,7 @@ function textarea_font_size_to_index(font_size) {
} }
function textarea_line_height_kludge(font_size, zoom) { function textarea_line_height_kludge(font_size, zoom) {
return textarea_font_height_array_kludge return textarea_font_height_array_kludge
[textarea_font_size_to_index(font_size)][zoom+7]+"%"; [textarea_font_size_to_index(font_size)][zoom+7]+"%";
} }
...@@ -6318,11 +6321,11 @@ function textarea_y_offset_kludge(font_size, zoom) { ...@@ -6318,11 +6321,11 @@ function textarea_y_offset_kludge(font_size, zoom) {
} }
function textarea_x_offset_kludge(font_size, zoom) { function textarea_x_offset_kludge(font_size, zoom) {
if (font_size === 36) { if (font_size === 36) {
return -2; return -2;
} else { } else {
return -0.5; return -0.5;
} }
} }
function textarea_msg_y_offset_kludge(zoom) { function textarea_msg_y_offset_kludge(zoom) {
...@@ -6365,17 +6368,17 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text, ...@@ -6365,17 +6368,17 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text,
// 2) extend this to adjust patch cords as things are being edited, and // 2) extend this to adjust patch cords as things are being edited, and
// 3) extend this to all text objects. // 3) extend this to all text objects.
if (type === "msg") { if (type === "msg") {
// Message approach // Message approach
var i, nlets = patchwin[cid].window.document var i, nlets = patchwin[cid].window.document
.getElementById(tag+"gobj").querySelectorAll(".xlet_control"); .getElementById(tag+"gobj").querySelectorAll(".xlet_control");
for (i = 0; i < nlets.length; i++) { for (i = 0; i < nlets.length; i++) {
nlets[i].style.setProperty("visibility", "hidden"); nlets[i].style.setProperty("visibility", "hidden");
} }
gui(cid).get_gobj(tag).q(".box_text", { visibility: "hidden" }); gui(cid).get_gobj(tag).q(".box_text", { visibility: "hidden" });
} else { } else {
// Anything else but message // Anything else but message
configure_item(gobj, { visibility: "hidden" }); configure_item(gobj, { visibility: "hidden" });
} }
p = patchwin[cid].window.document.createElement("p"); p = patchwin[cid].window.document.createElement("p");
configure_item(p, { configure_item(p, {
...@@ -6413,7 +6416,7 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text, ...@@ -6413,7 +6416,7 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text,
p.style.setProperty("font-size", p.style.setProperty("font-size",
pd_fontsize_to_gui_fontsize(font_size) + "px"); pd_fontsize_to_gui_fontsize(font_size) + "px");
p.style.setProperty("line-height", p.style.setProperty("line-height",
textarea_line_height_kludge(font_size, zoom)); textarea_line_height_kludge(font_size, zoom));
//pd_fontsize_to_gui_fontsize(font_size) + 1 + "px"); //pd_fontsize_to_gui_fontsize(font_size) + 1 + "px");
p.style.setProperty("transform", "translate(0px, " + p.style.setProperty("transform", "translate(0px, " +
(zoom > 0 ? 0.5 : 0) + "px)"); (zoom > 0 ? 0.5 : 0) + "px)");
...@@ -6450,7 +6453,7 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text, ...@@ -6450,7 +6453,7 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text,
//shove_svg_background_data_into_css(patchwin[cid].window, //shove_svg_background_data_into_css(patchwin[cid].window,
// parseInt(get_gobj(cid, tag).getBoundingClientRect().height / // parseInt(get_gobj(cid, tag).getBoundingClientRect().height /
// (parseInt(p.style.lineHeight) / 100 * font_size))); // (parseInt(p.style.lineHeight) / 100 * font_size)));
gui_message_update_textarea_border(p,1); gui_message_update_textarea_border(p,1);
} }
p.focus(); p.focus();
select_text(cid, p, sel_start, sel_end); select_text(cid, p, sel_start, sel_end);
...@@ -6475,9 +6478,9 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text, ...@@ -6475,9 +6478,9 @@ function gui_textarea(cid, tag, type, x, y, width_spec, height_spec, text,
// MSG approach // MSG approach
var i, nlets = patchwin[cid].window.document var i, nlets = patchwin[cid].window.document
.getElementById(tag+"gobj").querySelectorAll(".xlet_control"); .getElementById(tag+"gobj").querySelectorAll(".xlet_control");
for (i = 0; i < nlets.length; i++) { for (i = 0; i < nlets.length; i++) {
nlets[i].style.setProperty("visibility", "visible"); nlets[i].style.setProperty("visibility", "visible");
} }
gui(cid).get_gobj(tag).q(".box_text", { visibility: "visible" }); gui(cid).get_gobj(tag).q(".box_text", { visibility: "visible" });
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment