"Finding a file" from it's string name

Hey guys,

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?

m

0
3 comments
Avatar
Permanently deleted user

Hello Mike,

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?


ProjectLevelVcsManager.getInstance(project).getAllVersionedRoots() gives
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);

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Avatar
Permanently deleted user

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.

0
Avatar
Permanently deleted user

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 :)

0

Please sign in to leave a comment.