2 * Copyright 2000-2014 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.ide.actions;
18 import com.intellij.ide.util.gotoByName.ChooseByNameBase;
19 import com.intellij.ide.util.gotoByName.ChooseByNamePopup;
20 import com.intellij.ide.util.gotoByName.DefaultChooseByNameItemProvider;
21 import com.intellij.ide.util.gotoByName.GotoFileModel;
22 import com.intellij.openapi.progress.ProgressIndicator;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.roots.ProjectFileIndex;
25 import com.intellij.openapi.util.io.FileUtil;
26 import com.intellij.openapi.vfs.LocalFileSystem;
27 import com.intellij.openapi.vfs.VirtualFile;
28 import com.intellij.psi.PsiElement;
29 import com.intellij.psi.PsiFileSystemItem;
30 import com.intellij.psi.PsiManager;
31 import com.intellij.util.Processor;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
38 public class GotoFileItemProvider extends DefaultChooseByNameItemProvider {
39 private final Project myProject;
40 private final GotoFileModel myModel;
42 public GotoFileItemProvider(@NotNull Project project, @Nullable PsiElement context, GotoFileModel model) {
49 public boolean filterElements(@NotNull ChooseByNameBase base,
50 @NotNull String pattern,
52 @NotNull ProgressIndicator indicator,
53 @NotNull Processor<Object> consumer) {
54 if (pattern.contains("/") || pattern.contains("\\")) {
55 String path = FileUtil.toSystemIndependentName(ChooseByNamePopup.getTransformedPattern(pattern, myModel));
56 VirtualFile vFile = LocalFileSystem.getInstance().findFileByPathIfCached(path);
58 ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(myProject);
59 if (index.isInContent(vFile) || index.isInLibraryClasses(vFile) || index.isInLibrarySource(vFile)) {
60 PsiFileSystemItem fileOrDir = vFile.isDirectory() ?
61 PsiManager.getInstance(myProject).findDirectory(vFile) :
62 PsiManager.getInstance(myProject).findFile(vFile);
63 if (fileOrDir != null && !consumer.process(fileOrDir)) {
70 return super.filterElements(base, pattern, everywhere, indicator, consumer);