use of com.intellij.ide.util.gotoByName.GotoFileModel in project intellij-community by JetBrains.
the class GotoFileAction method gotoActionPerformed.
@Override
public void gotoActionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null)
return;
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.popup.file");
final GotoFileModel gotoFileModel = new GotoFileModel(project);
GotoActionCallback<FileType> callback = new GotoActionCallback<FileType>() {
@Override
protected ChooseByNameFilter<FileType> createFilter(@NotNull ChooseByNamePopup popup) {
return new GotoFileFilter(popup, gotoFileModel, project);
}
@Override
public void elementChosen(final ChooseByNamePopup popup, final Object element) {
if (element == null)
return;
ApplicationManager.getApplication().assertIsDispatchThread();
Navigatable n = (Navigatable) element;
//this is for better cursor position
if (element instanceof PsiFile) {
VirtualFile file = ((PsiFile) element).getVirtualFile();
if (file == null)
return;
OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, popup.getLinePosition(), popup.getColumnPosition());
n = descriptor.setUseCurrentWindow(popup.isOpenInCurrentWindowRequested());
}
if (n.canNavigate()) {
n.navigate(true);
}
}
};
GotoFileItemProvider provider = new GotoFileItemProvider(project, getPsiContext(e), gotoFileModel);
showNavigationPopup(e, gotoFileModel, callback, IdeBundle.message("go.to.file.toolwindow.title"), true, true, provider);
}
use of com.intellij.ide.util.gotoByName.GotoFileModel in project intellij-community by JetBrains.
the class TestDataGuessByExistingFilesUtil method buildDescriptor.
@NotNull
private static TestDataDescriptor buildDescriptor(@NotNull String test, @NotNull PsiClass psiClass) {
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(psiClass.getProject()).getFileIndex();
GotoFileModel gotoModel = new GotoFileModel(psiClass.getProject());
Set<TestLocationDescriptor> descriptors = new HashSet<>();
// PhpStorm has tests that use '$' symbol as a file path separator, e.g. 'test$while_stmt$declaration' test
// stands for '/while_smt/declaration.php' file somewhere in a test data.
final String possibleFileName = ContainerUtil.getLastItem(StringUtil.split(test, "$"), test);
assert possibleFileName != null;
final String possibleFilePath = test.replace('$', '/');
final Collection<String> fileNames = getAllFileNames(possibleFileName, gotoModel);
for (String name : fileNames) {
ProgressManager.checkCanceled();
boolean currentNameProcessed = false;
final Object[] elements = gotoModel.getElementsByName(name, false, name);
for (Object element : elements) {
if (!(element instanceof PsiFile)) {
continue;
}
final VirtualFile file = ((PsiFile) element).getVirtualFile();
if (file == null || fileIndex.isInSource(file) && !fileIndex.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.RESOURCES)) {
continue;
}
final String filePath = file.getPath();
if (!StringUtil.containsIgnoreCase(filePath, possibleFilePath) && !StringUtil.containsIgnoreCase(filePath, test)) {
continue;
}
final String fileName = PathUtil.getFileName(filePath).toLowerCase();
int i = fileName.indexOf(possibleFileName.toLowerCase());
// to be matched to the test 'testEnter()'.
if (i < 0 || (i + possibleFileName.length() < fileName.length()) && Character.isDigit(fileName.charAt(i + possibleFileName.length()))) {
continue;
}
TestLocationDescriptor current = new TestLocationDescriptor();
current.populate(possibleFileName, file);
if (!current.isComplete()) {
continue;
}
currentNameProcessed = true;
if (descriptors.isEmpty() || (descriptors.iterator().next().dir.equals(current.dir) && !descriptors.contains(current))) {
descriptors.add(current);
continue;
}
if (moreRelevantPath(current, descriptors, psiClass)) {
descriptors.clear();
descriptors.add(current);
}
}
if (currentNameProcessed) {
break;
}
}
return new TestDataDescriptor(descriptors, possibleFileName);
}
Aggregations