Commit 3a426dd0 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

First stab at making the "Cancel" button in gatom dialog actually revert to...

First stab at making the "Cancel" button in gatom dialog actually revert to the previously saved values.
parent f372d6a4
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
</label> </label>
</td> </td>
<td data-i18n="[title]gatom.prop.width_tt"> <td data-i18n="[title]gatom.prop.width_tt">
<input type="text" id="width" name="width"> <input type="text" id="width" name="width"
onchange="update_attr(this)">
</td> </td>
<td> <td>
</td> </td>
...@@ -31,7 +32,8 @@ ...@@ -31,7 +32,8 @@
</label> </label>
</td> </td>
<td data-i18n="[title]iem.prop.minimum_tt"> <td data-i18n="[title]iem.prop.minimum_tt">
<input type="text" id="minimum-range" name="minimum-range"> <input type="text" id="draglo" name="draglo"
onchange="update_attr(this)">
</td> </td>
<td> <td>
<label data-i18n="[title]iem.prop.maximum_tt"> <label data-i18n="[title]iem.prop.maximum_tt">
...@@ -39,7 +41,8 @@ ...@@ -39,7 +41,8 @@
</label> </label>
</td> </td>
<td data-i18n="[title]iem.prop.maximum_tt"> <td data-i18n="[title]iem.prop.maximum_tt">
<input type="text" id="maximum-range" name="maximum-range"> <input type="text" id="draghi" name="draghi"
onchange="update_attr(this)">
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -49,7 +52,8 @@ ...@@ -49,7 +52,8 @@
</label> </label>
</td> </td>
<td colspan="3"> <td colspan="3">
<input type="text" id="send-symbol" name="send-symbol"> <input type="text" id="send_symbol" name="send_symbol"
onchange="update_attr(this)">
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -59,7 +63,7 @@ ...@@ -59,7 +63,7 @@
</label> </label>
</td> </td>
<td colspan="3"> <td colspan="3">
<input type="text" id="receive-symbol" name="receive-symbol"> <input type="text" id="receive_symbol" name="receive_symbol">
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -69,7 +73,8 @@ ...@@ -69,7 +73,8 @@
</label> </label>
</td> </td>
<td colspan="3"> <td colspan="3">
<input type="text" id="label" name="label"> <input type="text" id="label" name="label"
onchange="update_attr(this)">
</td> </td>
</tr> </tr>
<tr> <tr>
...@@ -86,7 +91,8 @@ ...@@ -86,7 +91,8 @@
type="radio" type="radio"
id="labelpos_left" id="labelpos_left"
value="2" value="2"
name="labelpos"> name="labelpos"
onchange="update_attr(this)">
<span data-i18n="gatom.prop.label_top"></span> <span data-i18n="gatom.prop.label_top"></span>
<br/> <br/>
...@@ -95,26 +101,29 @@ ...@@ -95,26 +101,29 @@
type="radio" type="radio"
id="labelpos_left" id="labelpos_left"
value="0" value="0"
name="labelpos"> name="labelpos"
onchange="update_attr(this)">
<span data-i18n="gatom.prop.label_left"></span> <span data-i18n="gatom.prop.label_left"></span>
<input class="array-style" <input class="array-style"
type="radio" type="radio"
id="labelpos_right" id="labelpos_right"
value="1" value="1"
name="labelpos"> name="labelpos"
<span data-i18n="gatom.prop.label_right"></span> onchange="update_attr(this)">
<span data-i18n="gatom.prop.label_right"></span>
<br/> <br/>
<input class="array-style" <input class="array-style"
type="radio" type="radio"
id="labelpos_bottom" id="labelpos_bottom"
value="3" value="3"
name="labelpos"> name="labelpos"
<span data-i18n="gatom.prop.label_bottom"></span> onchange="update_attr(this)">
<span data-i18n="gatom.prop.label_bottom"></span>
</label> </label>
</table> </table>
...@@ -127,7 +136,7 @@ ...@@ -127,7 +136,7 @@
<button type="button" onClick="apply()" data-i18n="[title]iem.prop.apply_tt"> <button type="button" onClick="apply()" data-i18n="[title]iem.prop.apply_tt">
<span data-i18n="iem.prop.apply"></span> <span data-i18n="iem.prop.apply"></span>
</button> </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> <span data-i18n="iem.prop.cancel"></span>
</button> </button>
</div> </div>
...@@ -145,12 +154,9 @@ var l = pdgui.get_local_string; ...@@ -145,12 +154,9 @@ var l = pdgui.get_local_string;
pdgui.skin.apply(this); pdgui.skin.apply(this);
var pd_object_callback; var pd_object_callback,
old_attrs = {}, // original state. Used if we cancel the dialog
function ok() { new_attrs = {}; // changed state. Used if we apply or click "Ok"
apply();
cancel();
}
function substitute_space(arg) { function substitute_space(arg) {
var fake_space = String.fromCharCode(11); var fake_space = String.fromCharCode(11);
...@@ -184,33 +190,76 @@ function gatom_escape(str) { ...@@ -184,33 +190,76 @@ function gatom_escape(str) {
return strip_problem_chars(ret); return strip_problem_chars(ret);
} }
function apply() { function update_attr(elem) {
pdgui.post("we're applying gatom changes!"); pdgui.post("updated value detected. I am " + elem.name + " and my v is " + elem.value);
new_attrs[elem.name] = elem.value;
}
function send_params(attrs, create_undo_point) {
//pdgui.post("we're applying gatom changes!");
pdgui.pdsend(pd_object_callback, "param", pdgui.pdsend(pd_object_callback, "param",
+document.getElementById("width").value, +attrs.width,
+document.getElementById("minimum-range").value, +attrs.draglo,
+document.getElementById("maximum-range").value, +attrs.draghi,
gatom_escape(document.getElementById("label").value), gatom_escape(attrs.label),
document.querySelector('input[name="labelpos"]:checked').value, +attrs.labelpos,
gatom_escape(document.getElementById("receive-symbol").value), gatom_escape(attrs.receive_symbol),
gatom_escape(document.getElementById("send-symbol").value) gatom_escape(attrs.send_symbol),
create_undo_point ? 1 : 0
); );
} }
function cancel() { function cancel(revert_changes) {
var dirty = false, attr;
pdgui.post("closing the window at this point"); pdgui.post("closing the window at this point");
//window.close(true); //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"); 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 // 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 // It provides us with our window id from the C side. Once we have it
// we can create the menu and register event callbacks // we can create the menu and register event callbacks
function register_window_id(gfxstub, attributes) { function register_window_id(gfxstub, attributes) {
var attr;
pd_object_callback = gfxstub; pd_object_callback = gfxstub;
add_events(gfxstub); add_events(gfxstub);
translate_form(); translate_form();
populate_form(attributes); populate_form(attributes);
// Hack... change incoming "-" to empty string
if (attributes.label === "-") { attributes.label = ""; }
if (attributes.send_symbol === "-") { attributes.send_symbol= ""; }
if (attributes.receive_symbol === "-") { attributes.receive_symbol = ""; }
// Initialize the new_attrs to the current ones
for (attr in attributes) {
if (attributes.hasOwnProperty(attr)) {
new_attrs[attr] = attributes[attr];
}
}
old_attrs = attributes;
// We don't turn on rendering of the "container" div until // We don't turn on rendering of the "container" div until
// We've finished displaying all the spans and populating the // We've finished displaying all the spans and populating the
// labels and form elements. That makes it more efficient and // labels and form elements. That makes it more efficient and
...@@ -250,16 +299,16 @@ function get_elem(name) { ...@@ -250,16 +299,16 @@ function get_elem(name) {
function populate_form(attributes) { function populate_form(attributes) {
var label, snd, rcv, labelpos, i, radios; var label, snd, rcv, labelpos, i, radios;
get_elem("width").value = attributes.width; get_elem("width").value = attributes.width;
get_elem("minimum-range").value = attributes.draglo; get_elem("draglo").value = attributes.draglo;
get_elem("maximum-range").value = attributes.draghi; get_elem("draghi").value = attributes.draghi;
label = attributes.label; label = attributes.label;
get_elem("label").value = label === "-" ? "" : label; get_elem("label").value = label === "-" ? "" : label;
snd = attributes["send-symbol"]; snd = attributes.send_symbol;
get_elem("send-symbol").value = snd === "-" ? "" : snd; get_elem("send_symbol").value = snd === "-" ? "" : snd;
rcv = attributes["receive-symbol"]; rcv = attributes.receive_symbol;
get_elem("receive-symbol").value = rcv === "-" ? "" : rcv; get_elem("receive_symbol").value = rcv === "-" ? "" : rcv;
labelpos = attributes["labelpos"]; labelpos = attributes.labelpos;
radios = document.getElementsByName("labelpos"); radios = document.getElementsByName("labelpos");
for (i = 0; i < radios.length; i++) { for (i = 0; i < radios.length; i++) {
if (+radios[i].value === labelpos) { if (+radios[i].value === labelpos) {
......
...@@ -1128,7 +1128,10 @@ EXTERN int canvas_apply_restore_original_position(t_canvas *x, int pos); ...@@ -1128,7 +1128,10 @@ EXTERN int canvas_apply_restore_original_position(t_canvas *x, int pos);
/* message back from dialog window */ /* message back from dialog window */
static void gatom_param(t_gatom *x, t_symbol *sel, int argc, t_atom *argv) static void gatom_param(t_gatom *x, t_symbol *sel, int argc, t_atom *argv)
{ {
canvas_apply_setundo(x->a_glist, (t_gobj *)x); /* Check if we need to set an undo point. This happens if the user
clicks the "Ok" button, but not when clicking "Apply" or "Cancel" */
if (atom_getintarg(7, argc, argv))
canvas_apply_setundo(x->a_glist, (t_gobj *)x);
t_float width = atom_getfloatarg(0, argc, argv); t_float width = atom_getfloatarg(0, argc, argv);
t_float draglo = atom_getfloatarg(1, argc, argv); t_float draglo = atom_getfloatarg(1, argc, argv);
...@@ -1391,8 +1394,8 @@ static void gatom_properties(t_gobj *z, t_glist *owner) ...@@ -1391,8 +1394,8 @@ static void gatom_properties(t_gobj *z, t_glist *owner)
gui_s("draghi"); gui_f(x->a_draghi); gui_s("draghi"); gui_f(x->a_draghi);
gui_s("labelpos"); gui_i(x->a_wherelabel); gui_s("labelpos"); gui_i(x->a_wherelabel);
gui_s("label"); gui_s(gatom_escapit(x->a_label)->s_name); gui_s("label"); gui_s(gatom_escapit(x->a_label)->s_name);
gui_s("receive-symbol"); gui_s(gatom_escapit(x->a_symfrom)->s_name); gui_s("receive_symbol"); gui_s(gatom_escapit(x->a_symfrom)->s_name);
gui_s("send-symbol"); gui_s(gatom_escapit(x->a_symto)->s_name); gui_s("send_symbol"); gui_s(gatom_escapit(x->a_symto)->s_name);
gui_end_array(); gui_end_array();
gui_end_vmess(); gui_end_vmess();
} }
......
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