Popup menu on ToolWindow

I try to get a  popup menu on my own tool window, expecting behaviour similar to ‘Projet’ tool window

Here is my piece of code using setTitleActions

...
toolWindow.setStripeTitle("Categories");


AnAction anAction = new MyAction(toolWindow);
anAction.getTemplatePresentation().setIcon(AllIcons.General.Combo2);
((ToolWindowEx) toolWindow).setTitleActions(new AnAction[]{anAction});


and MyAction class

public void actionPerformed(AnActionEvent aae) {

  DefaultActionGroup actionGroup = new DefaultActionGroup();
actionGroup.add(new DoSomething("C1"));
actionGroup.add(new DoSomething("C2"));
actionGroup.add(new DoSomething("C3"));

ActionPopupMenu actionPopupMenu =
ActionManager.getInstance().createActionPopupMenu(null,actionGroup) ;


ToolWindow toolWindow =
ToolWindowManager.getInstance(aae.getProject())
.getToolWindow(TOOL_WINDOW_ID) ;
actionPopupMenu.getComponent().show(
toolWindow.getComponent().getComponent(0), 0, 0); // toolWindow is composed of only one Jpanel
}

I got something working, nevertheless I have some questions:
- Do I am on the right track for such feature ?
- The only clikable part is the Combo2 icon, how to get a wider clickable area (as done on project tool window where 'Project text' is also clickable)  ?
- For now, the text "Categories" is set on left side and the Combo2 icon is stick on right side, How to put Combo2 icon close to text "Categories" ?
- Must I take care of the fact that a new ActionPopupMenu is created on each invocation of actionPerformed  (memory leak ) ?

Thanks for the tips

Bernard

0
1 comment

 To be more realistic, here is a picture of my current situation
My two questions are
 - How to get a wider clickable area ?
 - How to customize the tree renderer
   For now I have implemented getPresentableText() and getIcon() for the object returned by getRoot() of my model, that’s ok.    
   But for tree nodes what is the hook to get control on the displayed name and icon; to get control on the depth on the tree ?

Best regards

 

0

Please sign in to leave a comment.