How to hook into click/select event of the project view?
已回答
Hi,
in a plugin I want to react to a file selection in the project view to check the file content and -type whether its eligible for a certain interaction. Please note that this should intentionally happen when selecting the file (via single left click or keyboard navigation) in the project view, e.g. it is not an option to have this functionality as an action in the context-menu!
Any suggestions? Thanks.
请先登录再写评论。
There currently exists no such API. You could try adding your own TreeSelectionListener to a tree via
ProjectView.getInstance(project).getCurrentProjectViewPane().getTree(), but we have no listener to notify when a pane or a tree changed.
Could you please elaborate your use-case of "certain interaction"? Maybe we could suggest a different mechanism.
Thanks Yann for the hint, the TreeSelectionListener is doing fine so far. I am not sure what is the best point in time (and place) to attach to it though?! I placed it into a project component but during initComponent/openProject, the ProjectViewPane is still null (using a pretty bad workaround for late initialization makes it at least work...).
The purpose is a [preview-plugin](https://youtrack.jetbrains.com/issue/IDEA-130918).
You can use StartupActivity EP instead of costly Project component. Then install listener com.intellij.openapi.wm.ex.ToolWindowManagerListener#toolWindowRegistered to be notified when Project View toolwindow is registered (com.intellij.openapi.wm.ToolWindowId#PROJECT_VIEW)
Thanks again - didn't know about this yet. The only startup and activity related EP was postStartupActivity, which seems to be always called after the ProjectView-ToolWindow is registered. That's actually even better and works like charm - just not sure whether you were referring to another EP.
StartupActivity class is available under "postStartupActivity" EP name, so it's the same actually :)