Commit adb3c663 authored by Jonathan Wilkes's avatar Jonathan Wilkes

fix #176: openpanel/savepanel error when the containing canvas isn't vis'd

parent 2ebe3e19
Pipeline #556 failed with stage
in 275 minutes and 33 seconds
......@@ -11,6 +11,9 @@
<input style="display:none;" id="fileDialog" type="file"
nwworkingdir multiple />
</span>
<input style="display:none;" id="openpanel_dialog" type="file" />
<input style="display:none;" id="savepanel_dialog" type="file"
nwsaveas nwworkingdir />
<div id="console_controls" class="noselect">
<div id="control_frame">
<label class="dsp_toggle">DSP
......
......@@ -341,6 +341,26 @@ function add_events() {
document.getElementById("fileDialog").setAttribute("accept",
Object.keys(pdgui.pd_filetypes).toString());
// [openpanel] and [savepanel] callbacks
document.querySelector("#openpanel_dialog").addEventListener("change",
function(evt) {
var file_string = evt.target.value;
// reset value so that we can open the same file twice
evt.target.value = null;
pdgui.file_dialog_callback(file_string);
console.log("tried to openpanel something");
}, false
);
document.querySelector("#savepanel_dialog").addEventListener("change",
function(evt) {
var file_string = evt.target.value;
// reset value so that we can open the same file twice
evt.target.value = null;
pdgui.file_dialog_callback(file_string);
console.log("tried to savepanel something");
}, false
);
// disable drag and drop for the time being
window.addEventListener("dragover", function (evt) {
evt.preventDefault();
......
......@@ -119,7 +119,8 @@ function permission_to_paste_from_external_clipboard() {
return global.confirm(l("canvas.paste_clipboard_prompt"));
}
function nw_window_focus_callback() {
function nw_window_focus_callback(name) {
pdgui.set_focused_patchwin(name);
// on OSX, update the menu on focus
if (process.platform === "darwin") {
nw_create_patch_window_menus(gui, window, canvas_events.get_id());
......@@ -592,7 +593,7 @@ var canvas_events = (function() {
pdgui.gui_canvas_get_scroll(name);
});
gui.Window.get().on("focus", function() {
nw_window_focus_callback();
nw_window_focus_callback(name);
});
gui.Window.get().on("blur", function() {
nw_window_blur_callback(name);
......@@ -757,7 +758,7 @@ function register_window_id(cid, attr_array) {
canvas_events.register(cid);
translate_form();
// Trigger a "focus" event so that OSX updates the menu for this window
nw_window_focus_callback();
nw_window_focus_callback(cid);
canvas_events.normal();
pdgui.canvas_map(cid); // side-effect: triggers gui_canvas_get_scroll
set_editmode_checkbox(attr_array.editmode !== 0 ? true : false);
......
......@@ -66,6 +66,10 @@ function gui_set_gui_preset(name) {
skin.set(name);
}
exports.set_focused_patchwin = function(cid) {
last_focused = cid;
}
// Modules
var fs = require("fs"); // for fs.existsSync
......@@ -1110,7 +1114,8 @@ var scroll = {},
redo = {},
font = {},
doscroll = {},
last_loaded,
last_loaded, // last loaded canvas
last_focused, // last focused canvas (doesn't include Pd window or dialogs)
loading = {},
title_queue= {}, // ugly kluge to work around an ugly race condition
popup_menu = {};
......@@ -4127,9 +4132,17 @@ function file_dialog(cid, type, target, path) {
file_dialog_target = target;
var query_string = (type === "open" ?
"openpanel_dialog" : "savepanel_dialog"),
d = patchwin[cid].window.document.querySelector("#" + query_string);
d.setAttribute("nwworkingdir", path);
d.click();
input_elem,
win;
// We try opening the dialog in the last focused window. There's an
// edge case where [loadbang]--[openpanel] will trigger before the
// window has finished loading. In that case we just trigger the
// dialog in the main Pd window.
win = last_focused && patchwin[last_focused] ? patchwin[last_focused] :
pd_window;
input_elem = win.window.document.querySelector("#" + query_string);
input_elem.setAttribute("nwworkingdir", path);
input_elem.click();
}
function gui_openpanel(cid, target, path) {
......
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