diff --git a/pd/nw/index.js b/pd/nw/index.js index b801ff1caefe9ef250a0e6b35d6396508f79bcf5..7643a18b27cd91743a3bcf1acebc8246fbf67b8a 100644 --- a/pd/nw/index.js +++ b/pd/nw/index.js @@ -38,15 +38,6 @@ function open_external_doc(target) { gui.Shell.openExternal(target); } -var chooser = document.querySelector("#fileDialog"); -chooser.addEventListener("change", function(evt) { - var file_array = this.value; - // reset value so that we can open the same file twice - this.value = null; - pdgui.menu_open(file_array); - console.log("tried to open something"); -}, false); - document.getElementById("dsp_control").addEventListener("click", function(evt) { var dsp_state = this.checked ? 1 : 0; @@ -357,6 +348,13 @@ function nw_create_pd_window_menus () { }); span.innerHTML = input; var chooser = document.querySelector("#fileDialog"); + chooser.onchange = function() { + var file_array = this.value; + // reset value so that we can open the same file twice + this.value = null; + pdgui.menu_open(file_array); + console.log("tried to open something"); + }; chooser.click(); } })); diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index cd3e93a320a5c49afa912f1f322d9de37298bd79..fdb6aa3765a404306c1c01300da7191543d24cd0 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -32,7 +32,6 @@ function text_to_fudi(text) { text = text.replace(/(?!\\)(,|;)/g, " \\$1 "); // escape "," and ";" text = text.replace(/\{|\}/g, ""); // filter "{" and "}" text = text.replace(/\s+/g, " "); // filter consecutive /s - return text; } @@ -348,7 +347,8 @@ var canvas_events = (function() { } ; - // Dialog events + // Dialog events -- these are set elsewhere now because of a bug + // with nwworkingdir document.querySelector("#saveDialog").addEventListener("change", function(evt) { pdgui.saveas_callback(name, this.value); diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index 0911125afd57262028ef2a390fa536297f305969..a86be9b21dcf407db052e106f125129b99b117e4 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -356,18 +356,28 @@ function gui_canvas_saveas (name, initfile, initdir) { if (!fs.existsSync(initdir)) { initdir = pwd; } + // If we don't have a ".pd" file extension (e.g., "Untitled-1", add one) + if (initfile.slice(-3) !== ".pd") { + initfile += ".pd"; + } // This is complicated because of a bug... see above input = build_file_dialog_string({ style: "display: none;", type: "file", id: "saveDialog", - nwsaveas: initdir + '/' + initfile + ".pd", + nwsaveas: initdir + '/' + initfile, nwworkingdir: initdir, accept: ".pd" }); post("input is " + input); span.innerHTML = input; chooser = patchwin[name].window.document.querySelector("#saveDialog"); + chooser.onchange = function() { + saveas_callback(name, this.value); + // reset value so that we can open the same file twice + this.value = null; + console.log("tried to save something"); + } chooser.click(); } @@ -930,7 +940,7 @@ function connect () { client = new net.Socket(); client.setNoDelay(true); // uncomment the next line to use fast_parser (then set its callback below) - // client.setEncoding("utf8"); + //client.setEncoding("utf8"); client.connect(PORT, HOST, function() { console.log("CONNECTED TO: " + HOST + ":" + PORT); });