WebDialog
December 19th, 2007 | Published in Google SketchUp
One of the interesting features of SketchUp's Ruby API is the UI::WebDialog class. Since WebDialog supports DHTML and JavaScripts, you can provide a rich, custom user experience for your SketchUp plugin users. You may be thinking, just another dialog box pretending to be a browser-lite, right? But there's more: with WebDialog you can call Ruby code from within the DHTML content of the dialog's document. No, this isn't some kind of listen-to-port-80-and-redirect trick. You define a block of execution in your Ruby code, assign it to the WebDialog object by name, and when the user selects the input element with that name the block is executed. Let's say you have an input element such as this:
say hi!
Now, all you have to do is define a block of execution and assign it with the name "myAction."
dialog.add_action_callback("myAction") { |d, p| puts p }
When the user clicks on the input element, it's the equivalent to
proc = Proc.new { |d, p| puts d}
proc.call(dialog, "Hello")
Simple and useful.