From 3bc841556093f02f7a79895e1928f3fc6ea60e69 Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Sat, 5 Dec 2015 22:00:42 -0500 Subject: [PATCH] fix bug with menu_open not getting triggered from a canvas window --- pd/nw/index.js | 2 ++ pd/nw/pd_canvas.html | 4 ++-- pd/nw/pd_canvas.js | 40 ++++++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/pd/nw/index.js b/pd/nw/index.js index 5e306c6c5..909ea5575 100644 --- a/pd/nw/index.js +++ b/pd/nw/index.js @@ -381,6 +381,8 @@ function nw_create_pd_window_menus(gui, w) { }); span.innerHTML = input; var chooser = w.document.querySelector("#fileDialog"); + // Hack-- we have to set the event listener here because we + // changed out the innerHTML above chooser.onchange = function() { var file_array = this.value; // reset value so that we can open the same file twice diff --git a/pd/nw/pd_canvas.html b/pd/nw/pd_canvas.html index 57b36bef6..feed1c5c5 100644 --- a/pd/nw/pd_canvas.html +++ b/pd/nw/pd_canvas.html @@ -5,10 +5,10 @@ type="text/css" href="css/default.css"> </head> <body id="patch_body"> - <span id = fileDialogSpan> + <span id = "fileDialogSpan"> <input style="display:none;" id="fileDialog" type="file" multiple /> </span> - <span id = saveDialogSpan> + <span id = "saveDialogSpan"> <input style="display:none;" id="saveDialog" type="file" nwsaveas nwworkingdir accept=".pd" /> </span> diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index 8cb3f46f9..1349e1f67 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -376,18 +376,23 @@ var canvas_events = (function() { pdgui.saveas_callback(name, this.value); // reset value so that we can open the same file twice this.value = null; - console.log("tried to open something"); - }, false - ); - document.querySelector("#fileDialog").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"); + console.log("tried to save something"); }, false ); + + // The following is commented out because we have to set the + // event listener inside nw_create_pd_window_menus due to a + // bug with nwworkingdir + + //document.querySelector("#fileDialog").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\n\n\n\n\n\n\n\n"); + // }, false + //); document.querySelector("#openpanel_dialog").addEventListener("change", function(evt) { var file_string = this.value; @@ -663,13 +668,24 @@ function nw_create_patch_window_menus(gui, w, name) { var input, chooser, span = w.document.querySelector("#fileDialogSpan"); input = pdgui.build_file_dialog_string({ - id: "fileDialog", - nwworkingdir: "/user/home", style: "display: none;", type: "file", + id: "fileDialog", + nwworkingdir: "/user/home", + multiple: null, + accept: ".pd,.pat,.mxt,.mxb,.help" }); span.innerHTML = input; chooser = w.document.querySelector("#fileDialog"); + // Hack-- we have to set the event listener here because we + // changed out the innerHTML above + 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(); } }); -- GitLab