Hi All,
I create a dialog and save its instance for showing/hiding.
When I show it first everything works fine. If I close the dialog and show it again then sketchup methods are not called. Here is the test code
d = UI::HtmlDialog.new()
d.set_html(%[<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./../css/style.css" type="text/css" />
<title>Test</title>
</head>
<body>
<script>
window.onload = function() {
sketchup.onloaded();
}
</script>
</body>
</html>
])
d.add_action_callback("onloaded") do |wd|
puts "On loaded called from js"
d.close
d.show
end
d.show {
puts "Show the dialog"
}
I know it is recursive but it is not behaving as it should.
Javascript error : sketchup.onloaded is not a function (sketchup instance exists)
What I am doing wrong here ? or I have to create new instance of dialog everytime ?
nothing, it was broken in an attempt to stop CEF crashing SU during application close…
the crashes were deemed to be caused when javascript was left ‘open’ in CEF by extensions, but why it needed to clear the ruby callbacks is a mystery…
on a mac it also uses a different window ‘style’ when opened more than once…
you don’t want to make additional UI::HtmlDialog.new()…
but you do need to re-add the call backs
@d = UI::HtmlDialog.new()
@d.set_html(%[<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./../css/style.css" type="text/css" />
<title>Test</title>
</head>
<body>
Message
<script>
window.onload = function() {
sketchup.onloaded();
}
</script>
</body>
</html>
])
def dlg
# add the callback each time...
@d.add_action_callback("onloaded") do |wd|
puts "On loaded called from js from #{@d}"
@d.close
end
# this happens first
@d.show
# #show{} this only works with WebDialogs
# not HtmlDialogs, so put 'puts' on new line
puts "Show the dialog"
end
The behaviour of HtmlDialog where you need to re-register action callbacks is described in our HtmlDialog examples. (Though we should update the docs to make this clearer.)