Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
nerrons
purr-data
Commits
b65d3a59
Commit
b65d3a59
authored
May 22, 2017
by
Jonathan Wilkes
Browse files
attempt to fix #323: openpanel doesn't load specified directory
parent
e9461435
Changes
2
Hide whitespace changes
Inline
Side-by-side
pd/nw/pd_canvas.html
View file @
b65d3a59
...
...
@@ -19,9 +19,13 @@
<input
style=
"display:none;"
id=
"printDialog"
type=
"file"
nwsaveas
nwworkingdir
accept=
".pdf"
/>
</span>
<input
style=
"display:none;"
id=
"openpanel_dialog"
type=
"file"
/>
<input
style=
"display:none;"
id=
"savepanel_dialog"
type=
"file"
<span
id =
"openpanelSpan"
>
<input
style=
"display:none;"
id=
"openpanel_dialog"
type=
"file"
/>
</span>
<span
id =
"savepanelSpan"
>
<input
style=
"display:none;"
id=
"savepanel_dialog"
type=
"file"
nwsaveas
nwworkingdir
/>
</span>
<svg
xmlns=
"http://www.w3.org/2000/svg"
version=
"1.1"
id=
"patchsvg"
...
...
pd/nw/pdgui.js
View file @
b65d3a59
...
...
@@ -4471,21 +4471,57 @@ exports.raise_pd_window= gui_raise_pd_window;
var
file_dialog_target
;
function
file_dialog
(
cid
,
type
,
target
,
path
)
{
function
file_dialog
(
cid
,
type
,
target
,
start_
path
)
{
file_dialog_target
=
target
;
var
query_string
=
(
type
===
"
open
"
?
"
openpanel_dialog
"
:
"
savepanel_dialog
"
),
"
openpanelSpan
"
:
"
savepanelSpan
"
),
input_span
,
input_elem
,
input_string
,
dialog_options
,
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
();
// 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_span
=
win
.
window
.
document
.
querySelector
(
"
#
"
+
query_string
);
// We have to use an absolute path here because of a bug in nw.js 0.14.7
if
(
!
path
.
isAbsolute
(
start_path
))
{
start_path
=
path
.
join
(
pwd
,
start_path
);
}
// We also have to inject html into the dom because of a bug in nw.js
// 0.14.7. For some reason we can't just change the value of nwworkingdir--
// it just doesn't work. So this requires us to have the parent <span>
// around the <input>. Then when we change the innerHTML of the span the
// new value for nwworkingdir magically works.
dialog_options
=
{
style
:
"
display: none;
"
,
type
:
"
file
"
,
id
:
type
===
"
open
"
?
"
openpanel_dialog
"
:
"
savepanel_dialog
"
,
// using an absolute path here, see comment above
nwworkingdir
:
start_path
};
if
(
type
!==
"
open
"
)
{
dialog_options
.
nwsaveas
=
""
;
}
input_string
=
build_file_dialog_string
(
dialog_options
);
input_span
.
innerHTML
=
input_string
;
// Now that we've rebuilt the input element, let's get a reference to it...
input_elem
=
win
.
window
.
document
.
querySelector
(
"
#
"
+
(
type
===
"
open
"
?
"
openpanel_dialog
"
:
"
savepanel_dialog
"
));
// And add an event handler for the callback
input_elem
.
onchange
=
function
()
{
// reset value so that we can open the same file twice
file_dialog_callback
(
this
.
value
);
this
.
value
=
null
;
console
.
log
(
"
openpanel/savepanel called
"
);
};
win
.
window
.
setTimeout
(
function
()
{
input_elem
.
click
();
},
300
);
}
function
gui_openpanel
(
cid
,
target
,
path
)
{
...
...
@@ -4496,11 +4532,13 @@ function gui_savepanel(cid, target, path) {
file_dialog
(
cid
,
"
save
"
,
target
,
path
);
}
exports
.
file_dialog_callback
=
function
(
file_string
)
{
function
file_dialog_callback
(
file_string
)
{
pdsend
(
file_dialog_target
,
"
callback
"
,
enquote
(
defunkify_windows_path
(
file_string
)));
}
exports
.
file_dialog_callback
=
file_dialog_callback
;
// Used to convert the ["key", "value"...] arrays coming from
// Pd to a javascript object
function
attr_array_to_object
(
attr_array
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment