Commit 80b89c52 authored by Jonathan Wilkes's avatar Jonathan Wilkes

attempt to show the correct directory in a "Save" dialog. (Still doesn't work...

attempt to show the correct directory in a "Save" dialog.  (Still doesn't work for the "Open" dialog.)
parent bd652ed1
......@@ -5,8 +5,10 @@
type="text/css" href="css/default.css">
</head>
<body id="console_body">
<input style="display:none;" id="fileDialog" type="file"
nwworkingdir multiple />
<span id="fileDialogSpan">
<input style="display:none;" id="fileDialog" type="file"
nwworkingdir multiple />
</span>
<div id="console_controls" class="noselect">
<div id="control_frame">
<label><input type="checkbox" id="dsp_control" name="dsp_control"
......
......@@ -343,6 +343,19 @@ function nw_create_pd_window_menus () {
modifiers: "ctrl",
tooltip: l("menu.open.tt"),
click: function (){
var input, chooser,
span = 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: pwd,
multiple: null,
// These are copied from pd_filetypes in pdgui.js
accept: ".pd,.pat,.mxt,.mxb,.help"
});
span.innerHTML = input;
var chooser = document.querySelector("#fileDialog");
chooser.click();
}
......
......@@ -5,16 +5,19 @@
type="text/css" href="css/default.css">
</head>
<body id="patch_body">
<input style="display:none;" id="fileDialog" type="file" multiple />
<input style="display:none;" id="saveDialog" type="file"
nwsaveas nwworkingdir accept=".pd" />
<span id = fileDialogSpan>
<input style="display:none;" id="fileDialog" type="file" multiple />
</span>
<span id = saveDialogSpan>
<input style="display:none;" id="saveDialog" type="file"
nwsaveas nwworkingdir accept=".pd" />
</span>
<input style="display:none;" id="openpanel_dialog" type="file" />
<input style="display:none;" id="savepanel_dialog" type="file"
nwsaveas nwworkingdir />
<svg xmlns="http://www.w3.org/2000/svg"
version="1.1"
id="patchsvg"
overflow="visible"
class="noselect">
</svg>
<div id="canvas_find" style="display:none;">
......
......@@ -641,7 +641,16 @@ function nw_create_patch_window_menus(name) {
modifiers: "ctrl",
tooltip: l("menu.open_tt"),
click: function() {
var chooser = document.querySelector("#fileDialog");
var input, chooser,
span = document.querySelector("#fileDialogSpan");
input = pdgui.build_file_dialog_string({
id: "fileDialog",
nwworkingdir: "/user/home",
style: "display: none;",
type: "file",
});
span.innerHTML = input;
chooser = document.querySelector("#fileDialog");
chooser.click();
}
}));
......
......@@ -21,6 +21,14 @@ exports.get_gui_dir = function() {
return gui_dir;
}
exports.get_pd_opendir = function() {
if (pd_opendir) {
return pd_opendir;
} else {
return pwd;
}
}
var fs = require("fs"); // for fs.existsSync
var path = require("path"); // for path.dirname path.extname path.join
......@@ -316,14 +324,50 @@ function menu_save(name) {
exports.menu_save = menu_save;
// This is an enormous workaround based off of the comment for this bug:
// https://github.com/nwjs/nw.js/issues/3372
// Essentially nwworkingdir won't work if you set it through a javascript
// object like a normal human being. Instead, you have to let it get parsed
// by the browser, which means adding a <span> tag as a parent just so we
// can set its innerHTML.
// If this bug is ever resolved then this function can go away, as you should
// be able to just set nwsaveas and nwworkingdir through the setAttribute
// DOM interface.
function build_file_dialog_string(obj) {
var prop, input = "<input ";
for (prop in obj) {
if (obj.hasOwnProperty(prop)) {
input += prop;
if (obj[prop]) {
input += '="' + obj[prop] + '"';
}
input += ' ';
}
}
input += "/>";
return input;
}
exports.build_file_dialog_string = build_file_dialog_string;
function gui_canvas_saveas (name, initfile, initdir) {
post("working directory is " + pwd);
//global pd_nt filetypes untitled_directory
var input, chooser,
span = patchwin[name].window.document.querySelector("#saveDialogSpan");
if (!fs.existsSync(initdir)) {
initdir = pwd;
}
// patchwin[name].window.document.getElementById("fileDialog").setAttribute("nwworkingdir", pwd);
var chooser = patchwin[name].window.document.querySelector("#saveDialog");
// 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",
nwworkingdir: initdir,
accept: ".pd"
});
post("input is " + input);
span.innerHTML = input;
chooser = patchwin[name].window.document.querySelector("#saveDialog");
chooser.click();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment