Getting keyboard modifiers for mouse events on a status bar widget

Hi
My plugin makes use of an implementation StatusBarWidget.MultipleTextValuesPresentation

I'd like to open a different menu if the user shift-clicked the status bar widget.
The implemented method that handles getting the proper menu pop up actions is

public ListPopup getPopupStep()

however this method has no hook to the actual mouseEvent.

How can I get the shift modifier for the click event that initiated this function? Or is there a better way to go about this?

Relevant code is here:

https://github.com/OpherV/gitflow4idea/blob/develop/src/gitflow/ui/GitflowWidget.java#L96

Thanks!

6 comments
Comment actions Permalink

though not sure what "having no hook to the actual event" is supposed to mean, i'd suggest to have your event handler store or pass the event, so the getPopupStep method can access it.
you can than detect pressed special keys like:

       // ActionEvent e
        boolean isShiftPressed = e.getModifiers & ActionEvent.SHIFT_MASK == ActionEvent.SHIFT_MASK;

0
Comment actions Permalink

the ActionEvent e you're referring to is exactly the thing I need but don't have access to.

I'm implementing StatusBarWidget.MultipleTextValuesPresentation and registering it via

    StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
    statusBar.addWidget(myGitflowWidget, "after " + git4idea.ui.branch.GitBranchWidget.class.getName(), myProject);

So it's the intelli UI the handles the click on the status bar widget, and then calls the implemented method public ListPopup getPopupStep()
This method returns the list of actions in the status bar, but it doesn't receive the ActionEvent as an input paramter and here lies the problem.

How do I get to that ActionEvent?

0
Comment actions Permalink

You have as much access to the code in question as anyone else in this forum. If you don't see any way to accomplish the task, the most likely reason is that there is no such way. You're welcome to submit a pull request that extends the API in a way that will give you access to the ActionEvent.

0
Comment actions Permalink

Hi Dmitry,
I appreciate your reply and all the hard work you've put into this awesome product.

"If you don't see any way to accomplish the task, the most likely reason is that there is no such way"

I whole-heartedly disagree with this statement.

While it's true that I have as much access to the source code as anyone else, what I don't have access to is the shared experience and knowledge of everyone.
That's why I think it's still relevant to ask questions in this forum - even if the code is out there for me to see.
Who knows - maybe someone has a better idea, solution ,workaround, or alternative suggestions. Maybe they already tried something and failed\succeeded.
Learning from the exprience of others is part of the process, you know? I think every developer had that "eureka" moment of how to solve something just by talking about it with fellow developers. Communication is the ultimate goal a forum...

In any case thanks for the confirmation and I'll definitely consider sending a pull request!

0
Comment actions Permalink

Hi Opher,

Please don't see my previous reply as a discouragement to ask questions - this is not at all what I meant!

My point was simply that this piece of code is fairly simple and self-contained, and it feels unlikely that there is a simple workaround that you may have missed. Even if you could do some hack to achieve what you need with the current API (retrieve the last processed event from the event queue or something like that), it's very likely that it would be ugly and brittle. On the other hand, you do have the option of changing the code to allow you to achieve your goal cleanly by sending a pull request, and the result is going to be beneficial both for you and for the platform as a whole.

0

Please sign in to leave a comment.