How to listens to project opened?
Answered
Does IntelliJ Plugin has any function to catch Project Opened Extension like preloadingActivity?
preloadingActivity is Application level Listener of opening intellij application.
Does IntelliJ has project version of this??
I know that using ProjectManager.TOPIC can listen project open and close event, but I don't know where I should use this.
Because extensions like projectService, toolWindow is initialized after project opened. So, if I use ProjectManger.TOPIC in toolwindow's code, it is too late.
Now, I planned to use this in preloadingActitity extension, but I feel this is not a proper way.
I want to know is there any way to do this?
Please sign in to leave a comment.
GitRepository objects are created and managed by the GitRepositoryManager. Unfortunately, it happens somewhat separately from the VCS roots which are managed by the ProjectLevelVcsManager. Fortunately, GitRepositoryManager.getRepositoryForRoot() has some internal machinery which creates necessary objects on-the-fly.
That said, you've found correctly that you should listen to ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED and then call getRepositoryForRoot to achieve GitRepository objects you can work with.
Don't hesitate to write back if this doesn't work for some reason.
Well, it depends on what are you trying to achieve.
See com.intellij.openapi.startup.StartupActivity
Or com.intellij.openapi.components.ProjectComponent
Thanks I will try to use either of them.
What I want to do is determine the project has git repository or not.
GitBranchUtil.getCurrentRepository(project) can get repository but it may return null if the initialization of mapping is not finished (in ProjectLevelVcsManager).
And GitBranchUtil.getCurrentRepository(project) return null if the project is not git repository also.
So, I need to know the mapping is finished or not.
ProjectLevelVcsManager.myMappings.myActivated is private so I cannot get it from ProjectLevelVcsManager (I want to add isInitialized() method to ProjectLevelVcsManager...)
I tried to receive the event of end of initialization by ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED.
But my plugin is toolwindow so it is not known when the code is run.
That's why I will try to set listener when the project opened.
by using
to the code which called on startup of project.
Maybe StartupActivity is a good way to do it.
Thank you.
I might be really late to the party - but I was searching a long time for this answer
How to listens to project opened?
This is how I solved it:
Short, sweet, simple :-) I hope someone else gets to save some minutes tripping over this!