UI::WebDialog.set_file
BUG found
Found the problem on PC.
It's a boo-boo using the File.join method. An extra SEPARATOR is getting inserted at the beginning of the URL string, so that whatever the pathname, whether you use the optional relative path (2nd argument) or not, the resulting URL passed to the browser begins with:
file:///
For this test I have Rick Wilson's lil' html help file in the Support folder:
Rename it to .html and put it in the Sketchup Support folder
my_dialog=UI;;WebDialog.new('Smustard Organizer Compatibility',true,'test',800,600,100,100,true)
SUpath=Sketchup.find_support_file('') #empty string needed!
my_dialog.set_file('Support/Smustard_Organizer.html',SUpath)
my_dialog.show
On the PC this results in MSIE error dialog stating that 'Internet Explorer cannot find the file:
"file:///C:/Program Files/Google/Google SketchUp 7/Support/Smustard_Organizer.html"_'
Trying various combinations of the set_file method: 1 argument, 2 arguments, etc., I have also been able to get 2 types of error webpages, 'Internal Server Error' and the normal useless 'Cannot Open the Webpage error' with the likely reasons ie: No Internet connection, etc.
LESSON
UseUI::WebDialog.set_url instead.
my_dialog=UI;;WebDialog.new('Smustard Organizer Compatibility',true,'test',800,600,100,100,true)
SUpath=Sketchup.find_support_file('') #empty string needed!
# Remove leading file separator on Mac (or Win without Drive;)
SUpath.slice!(0,1) if SUpath[0,1]==File;;SEPARATOR
# File.join will put it back in
my_dialog.set_url( File.join('file;//localhost',SUpath,'Support/Smustard_Organizer.html'))
my_dialog.show
It is quite likely that .set_file actually just calls .set_url passing the latter improperly concatenated pathname string portions misusing the File.join method. (Obviously the set_file method could be fixed using the slice! technique above.)
UI.openURL
The same technique can (and should) be used with UI.openURL so that code is cross-plaform.
On
Mac, testing has shown that OSX wants 'file://localhost' at the begining of the URL or it can't find the file.* On
PC, Windows will adjust the URL, stripping off the 'file://localhost' and passing the rest of the path to whatever application is registered for the file extension. (Not always the browser.)
WebDialog.new
Two things to note here.
Comma Separated Parameter List form: IF the pref_key argument is nil or '' (empty string), the remaining arguments are ignored. (This is why I set the key to 'test' in the examples above.) So if you are attempting to make a WebDialog that does not save settings, and it is not showing at the position and size you want, this may be why.
Hash as Parameter form: Contrary to what has been said that the dialog_title parameter cannot be set through the hash, it CAN be. However, there is a bug in this new Hash based functionality. In that the Google coder did not take into account that there are several ways of defining a Hash, ie, with Symbol keys or String keys. The coder should have just converted each key using to_s and then made the value assignments based on the keystring, but didn't. So the Hash based form is 'quirky'. You must use Symbolsas keys, NOT Strings:
hsh=Hash[:dialog_title=>'Title passed by Hash', :scrollable=>false, :preferences_key=>'MyDialog', :width=>800, :height=>600, :left=>100, :top=>100, :resizable=>true]
AND once again if you omit the :preferences_key value pair, it seems the remaining arguments are ignored.. ie default position is 0,0 and size is 250,250 instead of those specified in the hash.
Conclusion: Because of the kwappy way the WebDialog API was coded, we must pass ALL parameters or Hash keys (which actually defeats the advantage of the Hash, over a Comma Sep'd Parameter List.)
_