"Finding a file" from it's string name Follow
I have a fiile path (like "/PM/pom.sml") and I want to locate that file within the current VCS configuration, and then open an editor. I can't figure out how on earth to do this, nor find any examples that are similar. Any easy pointers?
Please sign in to leave a comment.
you the list of all directories marked as VCS roots in the project.
VfsUtil.findRelativeFile() should give you a specific file under the root,
given the VCS root and the path relative to the VCS root.
Once you've found the correct virtual file, use the following code to open
the file in the editor:
new OpenFileDescriptor(project, virtualFile).navigate(true);
"Develop with Pleasure!"
Dmitry - thanks mate, that's gold. The only problem is sometimes the file paths aren't identical in my testing if they haven't go the right section of the repository checked out.
Is there any way from the VCS Root to work out exactly what the SVN path to this file is? That would help me do some pattern matching to open the right file, no matter which section of the SVN repo they have checked out. For example if the file coming in is /foo/bar/pom.xml but /foo is in the local SVN checkout already.
Once you have Virtual file you can call:
AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(virtualFile);
String repoLocation = vcs.getCommittedChangesProvider().getLocationFor(VcsUtil.getFilePath(vFile.getPath())).toPresentableString();
Check ThePlugin source code :)