From 37756c8af85ff12f78e1cd719193f703485573ee Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jon.w.wilkes@gmail.com> Date: Sat, 30 Jan 2016 22:16:10 -0500 Subject: [PATCH] fix regression with the terrible and buggy nwworkingdir --- pd/nw/pd_canvas.js | 4 +++- pd/nw/pdgui.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pd/nw/pd_canvas.js b/pd/nw/pd_canvas.js index e62bfd49d..63c493ae3 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 71a292e6f..81bc3b116 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; -- GitLab