One-shot toolbar buttons?
-
Is there a way to create a button in a toolbar that works like the zoom extents button? That is, when you click it the underlying Tool/Command does its one-shot action and then the Toolbar button returns to un-selected? The only way I've been able to get this effect is to force the model to select the SelectionTool (which isn't necessarily what was active before). I tried things such as popping the active tool, but it didn't reset the button.
Thanks
Steve -
A button should never show it is checked unless YOU set it's validation to anything other than
MF_ENABLED || MF_UNCHECKED
Answer yes, using send_action.
IF there is a selection then this Zoom command should zoom to the selection, otherwise zoom to the model extents.
command_proc = { if Sketchup.active_model.selection.empty? Sketchup.send_action("viewZoomExtents;") else Sketchup.send_action("viewZoomToSelection;") end }
-
@slbaumgartner said:
Is there a way to create a button in a toolbar that works like the zoom extents button? That is, when you click it the underlying Tool/Command does its one-shot action and then the Toolbar button returns to un-selected?
That is the default behaviour, unless you implement validation procs or make the button activate a tool. When you activate a tool the button will remain pressed for as long as that tool is active.
-
@dan you may have missed my point. I don't want to implement a zoom, I was just mentioning zoom extents as a tool whose button does what I want. I have a different tool that isn't really modal, it just performs an action and then wants control to go back to whatever was live before.
@TT I'm puzzled. Here's what I tried:
tb=UI;;Toolbar.new "Test" cmd = UI;;Command.new("clickme") {puts "click!"} tb.add_item cmd tb.show
This works functionally, that is, it prints click! in the Ruby Console, but the button toggles between unselected and selected ("pressed") look with each click. I want it to reset to unselected after each click and reactivate whatever was the active tool before the click.
Thanks
Steve -
Your example works fine for me on PC, in both versions that I have installed (and from memory in all versions I have ever had installed.)
-
You may have run into a Mac bug in a certain version.
Try this:
tb=UI;;Toolbar.new "Test" cmd = UI;;Command.new("clickme") {puts "click!"} cmd.set_validation_proc { MF_UNCHECKED } tb.add_item cmd tb.show
-
@dan rathbun said:
You may have run into a Mac bug in a certain version.
Try this:
tb=UI;;Toolbar.new "Test" > cmd = UI;;Command.new("clickme") {puts "click!"} > cmd.set_validation_proc { MF_UNCHECKED } > tb.add_item cmd > tb.show
Tried that in several versions of SU and the button toggles between "unpressed" and "pressed" every time...
-
Disable all plugins, test again. If still it does not work.. log a bug report.
State whether the toolbar is floating, docked vertically, or on the top horizontal bar (which has always been buggy on the Mac.)
-
Also verify that
MF_UNCHECKED == 0
, just to be sure no plugin has messed with the global constants. -
@dan rathbun said:
Disable all plugins, test again. If still it does not work.. log a bug report.
State whether the toolbar is floating, docked vertically, or on the top horizontal bar (which has always been buggy on the Mac.)
Still doesn't work, whether floating, docked, or in the top bar. Filing a bug.
Steve
-
Oh, right - yes I noticed that there's a bug under OSX. Sorry, I mostly use PC so I'd forgotten. I think there's an issue for it, but I'll check again and bump it.
Advertisement