Losing connection with HtmlDialog

Yes that’s the isue I had with this approach, I thought that was a bit too long because the window is opened and closed all the time.

Thanks for the tips Kenny, sounds like a very good approach, especially when you make lots of user interfaces in SketchUp.

Yes, that works very well indeed.

I will take another stab at first generating the html using ruby, and then updating the content using JavaScript. That was my original approach, but noticed that completely regenerating the html all the time didn’t have much performance impact, only this issue with losing the connection.

Well … you said …

… it is a known “quirk” of UI::HtmlDialog class objects that all the callbacks are disconnected when the dialog window is closed.

The documentation for #add_action_callback has a prominet bold box note:

Note: When an HtmlDialog is closed, all callbacks to that instance are cleared. Re-attach them if you need to open the dialog again.

Didn’t I make this plain above ? :thinking:

If it is (only) the closing of the window that is causing the issues, then this is just an implementation “flavour” of the CEF windows and using the class.

Again (for anyone reading) it is easily dealt with by either wrapping all your dialog’s callback attachments within a single method, or if they are each wrapped in their own method, then write an "attachment control’ method that calls each callback attaching method in turn just prior to calling #show on your dialog instance. (You might also be able to attach callbacks after the window is shown, although I’ve never seen a need myself to do this.)

Yes, that;s why I maked it as answered with that, but I just replied to the other responses.
But I did mis that warning note! Thanks for pointing that out, that makes it even more obvious…

1 Like

Again, sorry for the delay. You can use a js framework, or ‘roll your own’. I found that writing js functions for dialogs worked well. I also found that always passing arrays of element id’s or arrays of element id/property pairs worked best. Also, using Ruby’s Array#inspect will often generate the equivalent of a json array string.

For instance, the code you posted above could be changed to something similar to:

function element(id) { return document.getElementById(id); }

const pagesBase = ['building', 'shed', 'window', 'door', 'barn', 'ohd', 'cupola']

function select_pages(pages) {
  pagesBase.forEach( (p) => {
    let display = (pages.includes(p)) ? 'block' : 'none';
    element(`${p}_specs`).style.display = display;
  })
}
1 Like