Open a toolbar from another toolbar

Hi again,

I want to open a toolbar from another toolbar. The scenario - I click on a button in the first toolbar, get some data from API, and then I want to populate the second toolbar with this data. I used message bus to transfer data between the two, but encountered two issues:

1) The second toolbar isn't instanced until it's opened, therefore I have to open it first so it would subscribe to the queue.
2) I would like the action to actually open the second toolbar, similarly to what happens if you click `run` and then the result opens in the bottom toolbar.

Thank you!
Shachar 

0
5 comments
Avatar
Permanently deleted user

Every toolbar consists of actions, so first action should:

1) Get the data from API

2) Create ActionGroup with corresponding actions

3) Create Toolbar with this ActionGroup and show it.

Why these two toolbars should interact with each other? As I see the first toolbar is 'the main' one, the second one is dependant and can be disposed and recreated when data is changed (when you have some updates from API).

0
Avatar
Permanently deleted user

Hi Vassilly,

Thank you for your answer, I agree with your line of thought. How can I create a Toolbar from an action?

Thanks,
Shachar

0
Avatar
Permanently deleted user

It should look like this in your action:

 

public void actionPerformed(@NotNull AnActionEvent e) {
ActionToolbar toolbar = ActionManager.getInstance()
.createActionToolbar(ActionPlaces.TOOLBAR, new DefaultActionGroup(actions), true);
//use toolbar.getComponent() somehow
}

 

0
Avatar
Permanently deleted user

Hey Vassiliy, 

Do you have a code example for following such structure of design (ActionGroup) and Toolbar creation from an action? 
It would be very much appreciated.

Thank you,
Shachar

0
Avatar
Permanently deleted user

In my previous example is shown namely "Toolbar creation from an action), you create ActionGroup from an array of AnAction (see actions argument), maybe from single action.

0

Please sign in to leave a comment.