Newer
Older
<!DOCTYPE html>
<html>
<head>
<link id="page_style" rel="stylesheet" type="text/css" href="css/default.css">
</head>
<body class="dialog_body">
<div class="container">
<textarea id="text" style="width: 100%; box-sizing: border-box; height: 85vh; resize: none;">
</textarea>
</div>
<div class="submit_buttons">
<button type="button" onClick="ok()" data-i18n="[title]iem.prop.ok_tt">
<span data-i18n="iem.prop.ok"></span>
</button>
<button type="button" onClick="cancel()" data-i18n="[title]iem.prop.cancel_tt">
<span data-i18n="iem.prop.cancel"></span>
</button>
</div>
<dialog id="save_before_quit">
<h4>Do you want to save the changes you made before closing the window?
</h4>
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<div class="submit_buttons">
<button type="button"
onClick="ok()"
id="dialog_yes_button"
data-i18n="[title]canvas.save_dialog.yes_tt">
<span data-i18n="canvas.save_dialog.yes"></span>
</button>
<button type="button"
onClick="cancel()"
id="dialog_no_button"
data-i18n="[title]canvas.save_dialog.no_tt">
<span data-i18n="canvas.save_dialog.no"></span>
</button>
<button type="button"
onClick="close_modal_dialog()"
id="dialog_cancel_button"
data-i18n="[title]canvas.save_dialog.cancel_tt">
<span data-i18n="canvas.save_dialog.cancel"></span>
</button>
</div>
</dialog>
<script>
"use strict";
var gui = require("nw.gui");
var pdgui = require("./pdgui.js");
// For translations
var l = pdgui.get_local_string;
pdgui.skin.apply(window);
var pd_object_callback;
var dirty = false;
function apply() {
var text_array = document.getElementById("text").value.split("\n");
// clear out Pd's binbuf for our text object
pdgui.pdsend(pd_object_callback, "clear");
text_array.forEach(function (line) {
line = line.replace(",", " \\, ");
line = line.replace(";", " \\; ");
line = line.replace("$", " \\$ ");
pdgui.pdsend(pd_object_callback, "addline", line);
});
dirty = 0;
}
function cancel() {
//window.close(true);
close_window();
}
function ok() {
apply();
cancel();
}
// Close the modal dialog that appears after clicking the window "x"
// with a dirty textarea
function close_modal_dialog() {
document.getElementById("save_before_quit").close();
}
function textarea_clear() {
document.getElementById("text").value = "";
dirty = true;
}
function textarea_append(line) {
document.getElementById("text").value += line;
dirty = true;
}
function set_dirty(state) {
dirty = state;
}
// 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
function register_window_id(gfxstub, text_string) {
var head, tail, templates, data, data_separator;
pd_object_callback = gfxstub;
add_events(gfxstub);
translate_form();
// We request the text data only after we're certain our window
// has loaded. Otherwise the node.js context might try to populate
// the textarea before the window has actually loaded.
// This doesn't happen in Pd Vanilla because tcl/tk synchronously
// creates the window.
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
pdgui.pdsend(gfxstub, "map");
// We don't turn on rendering of the "container" div until
// We've finished displaying all the spans and populating the
// labels and form elements. That makes it more efficient and
// snappier, at least on older machines.
document.getElementsByClassName("container")[0]
.style.setProperty("display", "inline");
}
// Stop-gap translator
function translate_form() {
var elements = document.querySelectorAll("[data-i18n]"),
data,
i;
for (i = 0; i < elements.length; i++) {
data = elements[i].dataset.i18n;
if (data.slice(0, 7) === "[title]") {
elements[i].title = l(data.slice(7));
} else {
elements[i].textContent = l(data);
}
}
}
function close_window() {
pdgui.pdsend(pd_object_callback, "close");
Jonathan Wilkes
committed
//pdgui.remove_dialogwin(pd_object_callback);
//gui.Window.get().close(true);
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
}
function close_from_pd(signoff) {
if (signoff) {
pdgui.pdsend(pd_object_callback, "signoff");
}
pdgui.remove_dialogwin(pd_object_callback);
gui.Window.get().close(true);
}
function add_events(name) {
// closing the Window
gui.Window.get().on("close", function () {
// this needs to do whatever the "cancel" button does
//pdgui.pdsend(name, "menuclose 0");
//cancel();
// blur the textarea to trigger an onchange if it was modified
document.getElementById("text").blur();
if (dirty) {
document.getElementById("save_before_quit").showModal();
} else {
close_window();
}
});
document.getElementById("text").onchange = function() {
dirty = true;
}
// Right now the bindings are limited to "Enter = Ok" and "Escape = Cancel".
// We leave off those bindings since Enter starts a new line in the textarea
//pdgui.dialog_bindings(name);
}
</script>
</body>
</html>