Commit 33bf9711 authored by Albert Gräf's avatar Albert Gräf
Browse files

Port pd-l2ork upstream commits from Dec 7, 2015 improving the handling of $...

Port pd-l2ork upstream commits from Dec 7, 2015 improving the handling of $ substitutions in GUI elements. Also fixes #195.
parent 210c4465
......@@ -567,9 +567,14 @@ function apply() {
for (i = 0; i < pd_garray_attrs.length; i++) {
attrs = pd_garray_attrs[i];
name = get_array_value("array_name", attrs);
if (name.slice(0, 1) === "$") {
name = "#" + name.slice(1);
var arr = name.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "$" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#";
}
}
name = arr.join("");
pdgui.pdsend(
get_array_value("array_gfxstub", attrs),
"arraydialog",
......
......@@ -177,15 +177,16 @@ function strip_problem_chars(arg) {
}
function gatom_escape(str) {
var arr, i, ret;
var ret;
if (str.length === 0) {
ret = "-";
} else if (str.slice(0,1) === "-") {
ret = "-" + str;
} else {
arr = str.split("");
for (i = 0; i < arr.length; i++) {
if (arr[i] === "$") {
var arr = str.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "$" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#";
}
}
......@@ -194,6 +195,22 @@ function gatom_escape(str) {
return strip_problem_chars(ret);
}
function gatom_unescape(str) {
if (str === "-") {
str = "";
} else {
var arr = str.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "#" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "$";
}
}
str = arr.join("");
}
return str;
}
function update_attr(elem) {
new_attrs[elem.name] = elem.value;
}
......@@ -306,11 +323,11 @@ function populate_form(attributes) {
get_elem("draglo").value = attributes.draglo;
get_elem("draghi").value = attributes.draghi;
label = attributes.label;
get_elem("label").value = label === "-" ? "" : label;
get_elem("label").value = gatom_unescape(label);
snd = attributes.send_symbol;
get_elem("send_symbol").value = snd === "-" ? "" : snd;
get_elem("send_symbol").value = gatom_unescape(snd);
rcv = attributes.receive_symbol;
get_elem("receive_symbol").value = rcv === "-" ? "" : rcv;
get_elem("receive_symbol").value = gatom_unescape(rcv);
labelpos = attributes.labelpos;
radios = document.getElementsByName("labelpos");
......
......@@ -371,16 +371,33 @@ function update_attr(elem) {
}
//Clean up strings to send as symbol arguments to Pd
function pd_symbol_carwash(s) {
function iemgui_escape(s) {
s = !s ? "empty" : s;
if (s.charAt(0) === "$") {
s = "#" + s.slice(1);
var arr = s.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "$" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#";
}
}
s = arr.join("");
s = substitute_space(s);
s = strip_problem_chars(s);
return s;
}
function iemgui_unescape(s) {
var arr = s.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "#" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "$";
}
}
s = arr.join("");
return s;
}
function send_params(attrs, create_undo_point) {
/* Not sure what these are...
iemgui_clip_dim $id
......@@ -394,9 +411,9 @@ function send_params(attrs, create_undo_point) {
var send_symbol = attrs.send_symbol,
receive_symbol = attrs.receive_symbol,
label = attrs["label"];
send_symbol = pd_symbol_carwash(send_symbol);
receive_symbol = pd_symbol_carwash(receive_symbol);
label = pd_symbol_carwash(label);
send_symbol = iemgui_escape(send_symbol);
receive_symbol = iemgui_escape(receive_symbol);
label = iemgui_escape(label);
var label_x_offset = attrs.x_offset;
var label_y_offset = attrs.y_offset;
......@@ -605,6 +622,10 @@ function populate_form(attr_object) {
elem[0].checked = +attr_object[attr];
} else if (elem[0].type === "select-one") {
elem[0].selectedIndex = +attr_object[attr];
} else if (attr === "send_symbol" ||
attr === "receive_symbol" ||
attr === "label") {
elem[0].value = iemgui_unescape(attr_object[attr]);
} else {
elem[0].value = attr_object[attr];
}
......
......@@ -53,7 +53,7 @@ t_symbol *iemgui_dollar2raute(t_symbol *s)
return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{
if (*s1 == '$')
if (*s1 == '$' && *s1 && isdigit(s1[1]))
*s2 = '#';
else if (!(*s2 = *s1))
break;
......@@ -68,7 +68,7 @@ t_symbol *iemgui_raute2dollar(t_symbol *s)
return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{
if (*s1 == '#')
if (*s1 == '#' && *s1 && isdigit(s1[1]))
*s2 = '$';
else if (!(*s2 = *s1))
break;
......
......@@ -8,6 +8,7 @@
#include "m_pd.h"
#include "g_canvas.h"
#include <math.h>
#include <ctype.h>
extern int glob_lmclick;
......@@ -24,15 +25,17 @@ two, but how? */
t_symbol *sharptodollar(t_symbol *s)
{
if (*s->s_name == '#')
char buf[MAXPDSTRING], *s1, *s2;
if (strlen(s->s_name) >= MAXPDSTRING)
return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{
char buf[MAXPDSTRING];
strncpy(buf, s->s_name, MAXPDSTRING);
buf[MAXPDSTRING-1] = 0;
buf[0] = '$';
return (gensym(buf));
if (*s1 == '#' && *s1 && isdigit(s1[1]))
*s2 = '$';
else if (!(*s2 = *s1))
break;
}
else return (s);
return (gensym(buf));
}
/* --------- "pure" arrays with scalars for elements. --------------- */
......
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