I have been creating a plugin for a few months that is a Htmldialog application. There are 2 features important to it, but seem not available yet in Htmldialog api:
Hide the Htmldialog. The Htmldialog window can be closed or brought to front, but not hidden. It is not convenient, because the page has to be loaded when it is re-opened every time.
If you have already the two problems above, donât you think moving to C/C# without experience will rather create more problems than less?
That depends on how you close it. As far as Iâm aware, close hides the dialog so that it can be reshown any number of times as long as you keep a reference to it (instead of creating a new dialog every time, which needs to reload the page). However if you donât keep a reference, the dialog will be garbage collected and removed from memory.
" The #visible? method is useful to tell if the dialog is shown and still alive, if the dialog is minimized or not visible on the screen this will still return true ."
It is likely dangerous to attempt to dock any custom windows in SketchUpâs tray by any means, as SketchUpâs shutdown cycle is not expecting any other inspector panels but itâs own when saving the window metrics.
Ie, the entries in the registry where SketchUp saves the tray setups might become corrupted, and the subsequent startups may fail. (Ie, SketchUp crashes when loading.)
If you look at the GUI interface for manipulating the trays and panels, youâll see that the list of inspectors is hardcoded and is a set of checkboxes, not a scrollable list that is enumerated and displayed. (Meaning there is no current expectation for custom inspector panels to exist.)
It is best to work within what the API allows. Going âoutside the boundsâ can get your extension rejected from the Extension Warehouse.
Before you call @dialog.show the second time, you have to set again its HTML content and its callbacks (and as a consequence reprocess the whole logic of creation). So itâs pretty much equivalent as to recreate the dialog.
Here is a piece of code showing it
def test_close
#HTML content
html_text = ''
html_text += %q(<!DOCTYPE HTML>)
html_text += %q(<META http-equiv='Content-Script-Type' content='text/javascript'>)
html_text += %q(<META http-equiv='Content-Type' Content='text/html; charset=UTF-8'>)
html_text += "<button onclick='sketchup.onclick()'>Click to Close the dialog</button>"
#Creating the HtmlDialog
hsh = { :dialog_title => 'Test close HtmlDialog', :preferences_key => 'close' }
wdlg = UI::HtmlDialog.new hsh
wdlg.add_action_callback("onclick") do |action_context, p1, p2|
wdlg.close
UI.start_timer(1) { wdlg.show }
end
wdlg.set_html html_text
wdlg.show
end
If you run it, the dialog appears empty the second time it is âshownâ.
It will still open the dialog containing the test.html. Does not matter if you close it manually or with .close (I just tried with instance variable if it is matter in this regards⌠but not)
When Sketchup focus, the window will go behind. That is not my intention. I want to manipulate models on Sketchup and keep the plugin window on top of Sketchup.
I tried @dialog.close and @dialog.show. But the second @dialog.show still loads html page again, instead of simply restores the window. So @dialog.close is not hiding the window, it is not keeping the html content of the page.
You can use the âcombinationâ of UI::HtmlDialog::STYLE_WINDOW opttion Sketchup.focus .bring_to_front
instead. Dan prepared a very nice example for you in the post#8
Docked HtmlDialogs/custom panels have been requested by numerous developers and it is something we have on our radar. Itâs not as trivial to implement though as it may seem, as it needs to be coordinated with the UI/UX work in SketchUp both today and for years to come in the future.
For the time being, maybe itâs possible to move the window outside of the screen, or change its size like Open Cutlist is doing (Iâd recommend to change the size vertically though and keep the title bar wide enough for the window to be moved also when collapsed).
In both cases the dialog object âknowsâ the reference to a resource that it can reload automatically.
The dialog object should also âknowâ what the html text property is so it can be reloaded (same as for the other 2 content setter methods.) If this does not work the same on Windows then please file a bug report for #set_html (and also mention the body shift for Mac.)
I had this in my above example, but removed it as I thought it would confuse the issues discussed.
Not quite sure, but I think I agree here that if close is already destructive why not garbage collect the object ? Maybe the method cannot be changed now⌠if this is the case, then perhaps a new destructive #destroy method ?
On the Windows GUI, âhideâ a window means minimize (to the task bar.)
Yes, it would be nice to have a method to minimize the window (and restore) a dialog window.