I’m porting a plugin from Windows to OS X and I have a very basic problem with UI::Commands. The validation proc callbacks aren’t called regularly. They are only called when I click on one of the default SketchUp toolbar buttons, not when I click on any of my own buttons.
Here’s a minimal example that exhibits the problem on SketchUp 2015 and 2016 on OS X El Capitan 10.11.3:

This is a known issue. Under OSX they update only when the active tool updates. This means you cannot rely on changing checked or disabled state for toolbar buttons under OSX. They should work for menus though.

This is a known issue. Under OSX they update only when the active tool updates. This means you cannot rely on changing checked or disabled state for toolbar buttons under OSX. They should work for menus though.

Oh, I see. Is there some kind of work-around? We have lots of toolbar buttons that aren’t tools in that sense.

The validation proc should be called at least as often as the button is clicked. Not just when the active tool is changed. Because clicking the button may change the state of the button. And the visible state is only updated when the validation proc is called. We have a toolbar where the user can select one of ten alternatives that are represented by ten buttons in a row. Like radio buttons. They don’t change the active tool, though.

No, we’ve seen (and reported) this for a while. The plain vs greyed look of an extension’s buttons depends only on how many times they have been pressed, and does not necessarily reflect the current active/deactivated status of the tool.

Another example of how the UI on Mac has been neglected for some time now…

This does actually trigger the procs twice, because both push and pop trigger them.
I’m adding this code to my toolbar button click callbacks. I hope this doesn’t lead to any problems with the active tool.

They are only supposed to work with Ruby tools, not native tools. So, it is strange that the nil argument does not raise a TypeError exception. But then, the Tool class is abstract (a class without a specified superclass, other than the implied Object.)

Are there any plans to fix this issue on Mac? Being able to changing the state of the button is quite important to design a intuitive UI and make the plugin fit in to SketchUp (match Make Component, Face Style, Display Section Cut/Plane etc). For developers like me who don’t have a Mac to play with things like this can be quite problematic.

This is how a utility refresh function might look (ignore the namespacing as this is a sample):

def refresh_toolbars
# Return if Windows
return if RUBY_PLATFORM =~ /mswin|mingw/i
# For SU2018 use new function; for others use the push/pop tool workaround.
if ::Sketchup.version.to_i >= 18
::UI.refresh_toolbars
else
model = ::Sketchup.active_model
return unless model # Make sure there is a model as can be nil
model.tools.push_tool(nil)
model.tools.pop_tool
end
end

# At top of module:
OS_IS_WIN =( Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /darwin/i )
def refresh_toolbars
# Return if Windows
return if OS_IS_WIN
# Use new method if available; older versions
# will use the push/pop tool workaround.
if ::UI.respond_to?(:refresh_toolbars)
::UI.refresh_toolbars
else
model = ::Sketchup.active_model
# Make sure there is a model as can be nil
return unless model
model.tools.push_tool(nil)
model.tools.pop_tool
end
end

Ie, …

if ::Sketchup.version.to_i >= 18

… needs to call 3 methods before doing the boolean evaluation.
And it makes you try to remember version numbers matched to features.
Better to just test for functionality.