Tool.onCancel - Reselect tool?
-
https://developers.google.com/sketchup/docs/ourdoc/tool#onCancel
@unknownuser said:
1: the user re-selected the same tool from the toolbar or menu.
I can't seem to get reason code 1 to trigger. Only 0 and 2.
I thought I'd used it before - but I'm unsure.
-
Test snippet:
<span class="syntaxdefault"><br />class MyTool<br /><br /> def activate<br /> puts </span><span class="syntaxstring">"activate; #{self}"<br /></span><span class="syntaxdefault"> end<br /><br /> def deactivate</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> view </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> puts </span><span class="syntaxstring">"deactivate; #{self}"<br /></span><span class="syntaxdefault"> end<br /><br /> def onCancel</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">reason</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> puts </span><span class="syntaxstring">"MyTool was cancelled for reason #{reason}"<br /></span><span class="syntaxdefault"> end<br /><br />end<br /></span> -
@thomthom said:
https://developers.google.com/sketchup/docs/ourdoc/tool#onCancel
@unknownuser said:
1: the user re-selected the same tool from the toolbar or menu.
I can't seem to get reason code 1 to trigger. Only 0 and 2.
I thought I'd used it before - but I'm unsure.
Never got code 1 either. So I usually only test 0 or not 0
Fred
-
Is 1 (technically) possible?
Do "radio" toolbar buttons trigger an action if the current state is not changed?
Do toolbar buttons in the OS X version behave the same way? -
You can click a menu or toolbar button that activates a tool. It does triggesr the action and activates the tool again, but it deactivates the tool instead of calling this event.
-
(Devil's Advocate)Are you dealing with a single re-usable
Toolinstance ?Or does the command create a new
Toolinstance each time the menu item is chosen ? -
@dan rathbun said:
Are you dealing with a single re-usable
Toolinstance ?Or does the command create a new
Toolinstance each time the menu item is chosen ?Either way - I'm unable to trigger that event.
-
This seems like a documentation error. However when re-selecting a tool the deactivate and activate methods seems to be called right after each other so maybe comparing a timestamp can be used to detect when a tool is re-activated.
-
@eneroth3 said:
This seems like a documentation error. However when re-selecting a tool the deactivate and activate methods seems to be called right after each other so maybe comparing a timestamp can be used to detect when a tool is re-activated.
That's what I do, including for simulating a double-click on icon.
However, you cannot avoid the calls toactivate()anddeactivate(), just shortcut them.I just realize that, should Trimble fix this issue, there could be some regression in my scripts, because I only test status 0.
Fredo
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement