UI::WebDialog position and location methods (from DC extension.)

Hey.
I`m developing a plugin that uses WebDialog.last_width and WebDialog.last_height to reopen the dialog with last used position and sizes. It works great in SKU2014 but no longer in 2015 version. Wath’s happen?

not sure what has changed, [click here to have a look at this older thread][1]

john
[1]: Sizing Webdialog

If something does “not work”, it is useful (especially for you) to see the error message. What error is in Window → Ruby Console raised?
If there is no error (silent failure), then a reproducible test case with information about the system where it shows the unexpected behavior (OS, SketchUp, system browser version).

I’m not aware of a method last_width in the API, neither in 2014 nor in 2015. Maybe you were coding against an unofficial method that another plugin in your SketchUp 2014 added into the API?

Yes the following methods are added by the Trimble Dynamic Components extension:

  • last_height()
  • last_height=()
  • last_width()
  • last_width=()
# encoding: UTF-8
#
unless defined?(Sketchup)
  # Allow the Dynamic Components extension to load first:
  if Sketchup.version.to_i < 13
    dir = 'dynamiccomponents'
    require "#{dir}.rb" rescue nil
  else # 13+
    dir = 'su_dynamiccomponents'
    require "#{dir}.rb" rescue nil
  end
  # Be sure API extensions from DC package get loaded:
  Sketchup::require( File.join(dir,'/ruby/dcutils') )
  #
end

These methods are not smart. They do not “reopen the dialog with last used position and size.”

This is done by the API, by saving the user’s position and size into the registry on PC, or plist file on Mac, if the 3rd argument to the constructor call is not nil.

So if a key is given, once a webdialog has been opened, the dialog moved and/or resized by the user, … SketchUp will save the settings.
Thereafter, the API will ignore the size and position in the parameter list of the WebDialog::new constructor call, and use the saved settings.

The UI::WebDialog class lacks getter methods to get the current size and position, as well as other properties, even those set via the new() constructor call.

Thanks Dan, This is the key and is explained in the manual:

> pref_key :The registry entry where the location and size of the dialog will be
>  saved. If preferences_key is not included, the location and size will 
> not be stored

Yes, I know.

My point is the methods from the DC extension are not linked into the API’s save and restore features.
They are simply “manual” methods that set instance variables. So it is up to you the programmer to store some number in those variables. But these instance variables do not get saved in between sessions.

They were used to workaround an old bug (at least on PC,) where the webdialog would not re-appear at the last position & size used within the session. Instead, the bug was that the position & size was always taken from when it was last saved at the end of the previous session. (SketchUp did not save the webdialog positions & size until shutting down.)

But I think that has since been fixed.