Commit fec4b5f6 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

first stab at making iemgui dialog "Cancel" button actually cancel

* still need to test with each iemgui
* still need to add flag for params callback to choose whether to have an undo_point
parent 1184440e
......@@ -278,7 +278,8 @@
<div class="background-color prop hidden">
<label data-i18n="[title]iem.prop.bgcolor_tt">
<input type="color" name="background-color">
<input type="color" name="background-color"
onchange="update_attr(this);">
<span data-i18n="iem.prop.bgcolor"></span>
</label>
<br>
......@@ -286,7 +287,8 @@
<div class="foreground-color prop hidden">
<label data-i18n="[title]iem.prop.fgcolor_tt">
<input type="color" name="foreground-color">
<input type="color" name="foreground-color"
onchange="update_attr(this);">
<span data-i18n="iem.prop.fgcolor"></span>
</label>
<br>
......@@ -294,7 +296,8 @@
<div class="label-color prop hidden">
<label data-i18n="[title]iem.prop.label_color_tt">
<input type="color" name="label-color">
<input type="color" name="label-color"
onchange="update_attr(this);">
<span data-i18n="iem.prop.label_color"></span>
</label>
<br>
......@@ -314,7 +317,7 @@
<button type="button" onClick="apply()" data-i18n="[title]iem.prop.apply_tt">
<span data-i18n="iem.prop.apply"></span>
</button>
<button type="button" onClick="cancel()" data-i18n="[title]iem.prop.cancel_tt">
<button type="button" onClick="cancel(true)" data-i18n="[title]iem.prop.cancel_tt">
<span data-i18n="iem.prop.cancel"></span>
</button>
</div>
......@@ -337,11 +340,6 @@ var pd_object_callback,
old_attrs = {}, // original state. Used if we cancel the dialog
new_attrs = {}; // changed state. Used if we apply or click "Ok"
function ok() {
apply();
cancel();
}
function substitute_space(arg) {
var fake_space = String.fromCharCode(11);
return arg.split(" ").join(fake_space);
......@@ -364,13 +362,28 @@ function update_attr(elem) {
if (elem.type === "checkbox") {
new_attrs[elem.name] = elem.checked ? 1 : 0;
} else if (elem.type === "select-one") {
new_attrs[elem] = elem.selectedIndex;
new_attrs[elem.name] = elem.selectedIndex;
} else if (elem.type === "color") {
pdgui.post("elem.vlaue.sliceis " + elem.value.slice(1));
pdgui.post("elem.vlaue.sliceis.parseint " + parseInt(elem.value.slice(1)), 16);
new_attrs[elem.name] = parseInt(elem.value.slice(1), 16)
} else {
new_attrs[elem] = elem.value;
new_attrs[elem.name] = elem.value;
}
}
function apply() {
//Clean up strings to send as symbol arguments to Pd
function pd_symbol_carwash(s) {
s = (s === "" || !s) ? "empty" : s;
if (s.charAt(0) === "$") {
s = "#" + s.slice(1);
}
s = substitute_space(s);
s = strip_problem_chars(s);
}
function send_params(attrs, create_undo_point) {
pdgui.post("we're applying iemgui changes!");
/* Not sure what these are...
iemgui_clip_dim $id
......@@ -380,114 +393,103 @@ function apply() {
iemgui_sched_rng $id
iemgui_clip_fontsize $id
*/
var send_symbol = document.getElementsByName("send-symbol")[0].value;
var receive_symbol = document.getElementsByName("receive-symbol")[0].value;
var label = document.getElementsByName("label")[0].value;
if (send_symbol === null || send_symbol === "") {
send_symbol = "empty";
}
if (receive_symbol === null || receive_symbol === "") {
receive_symbol = "empty";
}
if (label === null || label === "") {
label = "empty";
}
console.log("send_symbol is " + send_symbol);
if (send_symbol.charAt(0) === "$") {
send_symbol = "#" + send_symbol.slice(1);
}
if (receive_symbol.charAt(0) === "$") {
receive_symbol = "#" + receive_symbol.slice(1);
}
if (label.charAt(0) === "$") {
label = "#" + label.slice(1);
}
send_symbol = substitute_space(send_symbol);
receive_symbol = substitute_space(receive_symbol);
label = substitute_space(label);
pdgui.post("label is " + attrs["label"]);
var send_symbol = attrs["send-symbol"],
receive_symbol = attrs["receive-symbol"],
label = attrs["label"];
pd_symbol_carwash(send_symbol);
pd_symbol_carwash(receive_symbol);
pd_symbol_carwash(label);
send_symbol = strip_problem_chars(send_symbol);
receive_symbol = strip_problem_chars(receive_symbol);
label = strip_problem_chars(label);
var label_x_offset = document.getElementsByName("x-offset")[0].value;
var label_y_offset = document.getElementsByName("y-offset")[0].value;
var label_x_offset = attrs["x-offset"];
var label_y_offset = attrs["y-offset"];
// make sure the offset boxes have a value
if (label_x_offset === null) { label_x_offset = 0; }
if (label_y_offset === null) { label_y_offset = 0; }
if (!label_x_offset) {
label_x_offset = 0;
}
if (!label_y_offset) {
label_y_offset = 0;
}
var height, width;
var size = document.getElementsByName("size")[0].value;
if (size === "") {
var size = document.getElementsByName("selection-size")[0].value;
var size = attrs["size"];
pdgui.post("size is " + attrs["size"]);
if (!size) {
pdgui.post("looked for selection size");
pdgui.post("ssize is " + attrs["selection-size"]);
size = attrs["selection-size"];
}
if (size !== "") {
pdgui.post("almost final size is " + size);
if (size) {
pdgui.post("checking final size");
width = size;
height = size;
} else {
width = document.getElementsByName("width")[0].value;
height = document.getElementsByName("height")[0].value;
width = attrs["width"];
height = attrs["height"];
}
var slot3 = document.getElementsByName("minimum-range")[0].value;
var slot4 = document.getElementsByName("maximum-range")[0].value;
pdgui.post("width = " + attrs["width"]);
pdgui.post("height = " + attrs["height"]);
var slot3 = attrs["minimum-range"];
var slot4 = attrs["maximum-range"];
if (slot3 === "") {
slot3 = document.getElementsByName("flash-interrupt")[0].value;
slot4 = document.getElementsByName("flash-hold")[0].value;
if (!slot3) {
slot3 = attrs["flash-interrupt"];
slot4 = attrs["flash-hold"];
}
if (slot3 === "") {
slot3 = document.getElementsByName("visible-width")[0].value;
slot4 = document.getElementsByName("visible-height")[0].value;
if (!slot3) {
slot3 = attrs["visible-width"];
slot4 = attrs["visible-height"];
}
if (slot3 === "") { // toggle
slot3 = document.getElementsByName("nonzero-value")[0].value;
if (!slot3) { // toggle
slot3 = attrs["nonzero-value"];
if (slot3 === "") {
slot3 = 0;
}
slot4 = 0;
}
var slot5 = +document.getElementsByName("log-scaling")[0].checked;
var slot5 = attrs["log-scaling"] ? +attrs["log-scaling"] : 0;
// Hack to accomodate the vu-scale property, which exists in the same
// slot as this one
var log_scaling_div = document.querySelector(".log-scaling");
var no_log_display = log_scaling_div.classList.contains("hidden");
if (no_log_display) {
slot5 = +document.getElementsByName("vu-scale")[0].checked;
slot5 = attrs["vu-scale"] ? +attrs["vu-scale"] : 0;
pdgui.post("slot five is " + slot5);
}
pdgui.post("slot five is " + slot5);
var init = +document.getElementsByName("init")[0].checked;
if (init === "") { init = 0; }
var init = +attrs["init"];
if (!init) { init = 0; }
var slot7 = document.getElementsByName("log-height")[0].value;
if (slot7 === "") {
slot7 = document.getElementsByName("number")[0].value;
var slot7 = attrs["log-height"];
if (!slot7) {
slot7 = attrs["number"];
}
if (slot7 === "") {
if (!slot7) {
slot7 = 0;
}
var font_style = document.getElementsByName("font-style")[0].
selectedIndex;
// if (font_style !== null) { font_style = 0; }
var font_style = attrs["font-style"];
//if (font_style !== null) { font_style = 0; }
var font_size = document.getElementsByName("font-size")[0].value;
if (font_size === "") { font_size = 0; }
var font_size = attrs["font-size"];
if (!font_size) { font_size = 0; }
var foreground_color = parseInt(document.getElementsByName("foreground-color")[0].value.slice(1), 16);
var background_color = parseInt(document.getElementsByName("background-color")[0].value.slice(1), 16);
var label_color = parseInt(document.getElementsByName("label-color")[0].value.slice(1), 16);
pdgui.post("background-color is " + attrs["background-color"]);
var foreground_color = attrs["foreground-color"];
var background_color = attrs["background-color"];
var label_color = attrs["label-color"];
var slot18 = +document.getElementsByName("steady-on-click")[0].checked;
var slot18 = attrs["steady-on-click"] ? +attrs["steady-on-click"] : 0;
pdgui.pdsend(pd_object_callback, "dialog",
width, height,
......@@ -512,12 +514,35 @@ function apply() {
0);
}
function cancel() {
function cancel(revert_changes) {
var dirty = false, attr;
pdgui.post("closing the window at this point");
//window.close(true);
if (revert_changes) {
for (attr in old_attrs) {
if (old_attrs[attr] !== new_attrs[attr]) {
dirty = true;
}
}
if (dirty) {
send_params(old_attrs, false);
}
}
pdgui.pdsend(pd_object_callback, "cancel");
}
function apply() {
send_params(new_attrs, false);
}
function ok() {
// Steal focus from any active input to make sure it triggers an
// onchange event
document.querySelector("button").focus();
send_params(new_attrs, true);
cancel(false);
}
// This gets called from the nw_create_window function in index.html
// It provides us with our window id from the C side. Once we have it
// we can create the menu and register event callbacks
......@@ -577,7 +602,7 @@ function populate_form(attr_object) {
// iemguis use the string 'empty' for null because of
// the limitations of Pd's state-saving API. So we have
// to filter that one out
if(attr_object[attr] !== "empty") {
if (attr_object[attr] !== "empty") {
var elem = document.getElementsByName(attr);
if (elem.length > 0) {
if(attr.slice(-5) === "color") {
......
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