Hi, I am trying to implement an extension. I created a custom tool and try to utilize the tool as click button. However when I click the tool in the toolbar, it is activated and activated event is fired. When I click the tool again, the event naturally is not fired. I want to have an ability to deactivate the tool programmatically(Select another tool may be a workaround) to be able to click the tool again and fire the activated event. Is there a possibility to do this?
Extensions cannot currently select different tools. (Whoops, I was wrong.) If you’re looking to have something you run rather than an interactive tool, you should create an Action instead of a Tool.
Depending on what exactly it is you want, you can also associate actions with a tool (see
ToolDefinition.toolBarActions), which puts them in the toolbar, but those are only visible while the tool is active.
Well, the existing tools do have actions associated with them, which can be triggered using
tiled.trigger, for example:
// Activate the Stamp Brush
Provided the tool is enabled, this would allow you to deactivate your tool. You can look up the action IDs in Preferences > Keyboard.
Another way to force deactivation of your tool should be to set its
enabled property to
false. It might not suffice to put it to
false and then immediately back to
true again, though.
Thank you @bjorn for your time,
tiled.enabled=true does the job. One last thing to ask is that registerTool adds the tool at the end of toolbar. Is there an API call to add the tool between default tools? Moreover I try to do it in Tiled GUI manually, it does not help either. How can I do it effeciently?
I’m sorry, there is at the moment no way to control the tool’s placement. Scripted tools are always at the end, in the order of registration.
Suggestions for extending the API to allow control over placement are welcome.
I think the ability to customise the various toolbars via the GUI would be more useful than controlling placement via scripting, since it would allow hiding/reordering the built-in tools too, and would allow users to order their toolbar to their own taste, rather than the script author’s.
I am a newbie at Tiled. When I get used to it, I would suggest more useful ideas. GUI based reorder would be helpful for everyone I think, since it can be used by more people. Layout save and restore would be also awesome too