diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index e62bfd49d6c9a11132402fe5cfa058bad4875bec..63c493ae3ed91ffca94fedda4ca1ebf60dc351db 100644 --- a/pd/nw/pd_canvas.js +++ b/pd/nw/pd_canvas.js @@ -937,12 +937,14 @@ function nw_create_patch_window_menus(gui, w, name) { click: function() { var input, chooser, span = w.document.querySelector("#fileDialogSpan"); + // Complicated workaround-- see comment in build_file_dialog_string input = pdgui.build_file_dialog_string({ style: "display: none;", type: "file", id: "fileDialog", - nwworkingdir: "/user/home", + nwworkingdir: pdgui.get_pwd(), multiple: null, + // These are copied from pd_filetypes in pdgui.js accept: ".pd,.pat,.mxt,.mxb,.help" }); span.innerHTML = input; diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js index 71a292e6fb575178191ea945c14908c29ca4c6b9..81bc3b11688a9fec434140bcb0d270326a19828e 100644 --- a/pd/nw/pdgui.js +++ b/pd/nw/pdgui.js @@ -409,6 +409,7 @@ function build_file_dialog_string(obj) { exports.build_file_dialog_string = build_file_dialog_string; function gui_canvas_saveas(name, initfile, initdir, close_flag) { +post("hey, the initdir is " + initdir + " and initfile is " + initfile); var input, chooser, span = patchwin[name].window.document.querySelector("#saveDialogSpan"); if (!fs.existsSync(initdir)) { @@ -423,8 +424,13 @@ function gui_canvas_saveas(name, initfile, initdir, close_flag) { style: "display: none;", type: "file", id: "saveDialog", - nwsaveas: initdir + '/' + initfile, - nwworkingdir: initdir, + nwsaveas: initfile, + // For some reason we have to put the file name at the end of + // nwworkingdir path. Otherwise nw.js picks the final subdirectory as + // the suggested file name. + // nwworkingdir is by far the worst part of nw.js API-- if you run + // into a bug then be very suspicious of this code... + nwworkingdir: path.join(initdir, initfile), accept: ".pd" }); span.innerHTML = input;