File filter added to 'Run Inspection by Name'

This commit is contained in:
Dmitry Avdeev
2011-10-11 16:22:08 +04:00
parent cab4d5006b
commit c1ff48b455
7 changed files with 160 additions and 15 deletions
@@ -20,8 +20,15 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class PsiSearchScopeUtil {
@Nullable
public static SearchScope union(@Nullable SearchScope a, @Nullable SearchScope b) {
return a == null ? b : b == null ? a : a.union(b);
}
/**
* @deprecated
* Use com.intellij.psi.search.SearchScope#union(com.intellij.psi.search.SearchScope)
@@ -74,7 +74,7 @@ public class AnalysisScope {
protected List<Module> myModules;
protected Module myModule;
protected PsiElement myElement;
private final SearchScope myScope;
private SearchScope myScope;
private boolean mySearchInLibraries = false;
protected int myType;
@@ -147,6 +147,10 @@ public class AnalysisScope {
myType = VIRTUAL_FILES;
}
public void setScope(SearchScope scope) {
myScope = scope;
}
public void setSearchInLibraries(final boolean searchInLibraries) {
mySearchInLibraries = searchInLibraries;
}
@@ -301,6 +301,7 @@ public class BaseAnalysisActionDialog extends DialogWrapper {
}
uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources();
scope.setIncludeTestSource(isInspectTestSources());
scope.setScope(getCustomScope());
FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName());
return scope;
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.codeInspection.actions.FileFilterPanel">
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="333" height="57"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4a7d1" class="javax.swing.JCheckBox" binding="myUseFileMask">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="1" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/FindBundle" key="find.filter.file.mask.checkbox"/>
</properties>
</component>
<component id="1aa52" class="javax.swing.JComboBox" binding="myFileMask">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="c6dc4" class="com.intellij.ui.TitledSeparator">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/FindBundle" key="find.filter.file.name.group"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -0,0 +1,74 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.codeInspection.actions;
import com.intellij.find.impl.FindDialog;
import com.intellij.find.impl.FindInProjectUtil;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.regex.Pattern;
/**
* @author Dmitry Avdeev
* Date: 10/11/11
*/
class FileFilterPanel {
private JCheckBox myUseFileMask;
private JComboBox myFileMask;
private JPanel myPanel;
void init() {
FindDialog.initFileFilter(myFileMask, myUseFileMask);
}
@Nullable
SearchScope getSearchScope() {
if (!myUseFileMask.isSelected()) return null;
String text = myUseFileMask.getText();
final Pattern pattern = FindInProjectUtil.createFileMaskRegExp(text);
return new GlobalSearchScope() {
@Override
public boolean contains(VirtualFile file) {
return pattern == null || pattern.matcher(file.getName()).matches();
}
@Override
public int compare(VirtualFile file1, VirtualFile file2) {
return 0;
}
@Override
public boolean isSearchInModuleContent(@NotNull Module aModule) {
return true;
}
@Override
public boolean isSearchInLibraries() {
return true;
}
};
}
JPanel getPanel() {
return myPanel;
}
}
@@ -37,9 +37,12 @@ import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.search.PsiSearchScopeUtil;
import com.intellij.psi.search.SearchScope;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.Arrays;
/**
@@ -100,6 +103,10 @@ public class RunInspectionAction extends GotoActionBase {
analysisScope = new AnalysisScope(project, Arrays.asList(virtualFile));
}
}
final FileFilterPanel fileFilterPanel = new FileFilterPanel();
fileFilterPanel.init();
final BaseAnalysisActionDialog dlg = new BaseAnalysisActionDialog(
AnalysisScopeBundle.message("specify.analysis.scope", InspectionsBundle.message("inspection.action.title")),
AnalysisScopeBundle.message("analysis.scope.title", InspectionsBundle.message("inspection.action.noun")),
@@ -108,7 +115,19 @@ public class RunInspectionAction extends GotoActionBase {
module != null ? module.getName() : null,
true,
AnalysisUIOptions.getInstance(project),
psiElement);
psiElement) {
@Override
protected JComponent getAdditionalActionSettings(Project project) {
return fileFilterPanel.getPanel();
}
@Override
public SearchScope getCustomScope() {
return PsiSearchScopeUtil.union(fileFilterPanel.getSearchScope(), super.getCustomScope());
}
};
AnalysisScope scope = analysisScope;
dlg.show();
if (!dlg.isOK()) return;
@@ -71,7 +71,7 @@ import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
class FindDialog extends DialogWrapper {
public class FindDialog extends DialogWrapper {
private static final Logger LOG = Logger.getInstance("#com.intellij.find.impl.FindDialog");
private ComboBox myInputComboBox;
@@ -392,28 +392,33 @@ class FindDialog extends DialogWrapper {
initCombobox(myFileFilter);
filterPanel.add(myUseFileFilter = createCheckbox(FindBundle.message("find.filter.file.mask.checkbox")),BorderLayout.WEST);
filterPanel.add(myFileFilter,BorderLayout.CENTER);
myFileFilter.setEditable(true);
initFileFilter(myFileFilter, myUseFileFilter);
return filterPanel;
}
public static void initFileFilter(final JComboBox fileFilter, final JCheckBox useFileFilter) {
fileFilter.setEditable(true);
String[] fileMasks = FindSettings.getInstance().getRecentFileMasks();
for(int i=fileMasks.length-1; i >= 0; i--) {
myFileFilter.addItem(fileMasks [i]);
fileFilter.addItem(fileMasks[i]);
}
myFileFilter.setEnabled(false);
fileFilter.setEnabled(false);
myUseFileFilter.addActionListener(
useFileFilter.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (!myUseFileFilter.isSelected()) {
myFileFilter.setEnabled(false);
} else {
myFileFilter.setEnabled(true);
myFileFilter.getEditor().selectAll();
myFileFilter.getEditor().getEditorComponent().requestFocusInWindow();
if (!useFileFilter.isSelected()) {
fileFilter.setEnabled(false);
}
else {
fileFilter.setEnabled(true);
fileFilter.getEditor().selectAll();
fileFilter.getEditor().getEditorComponent().requestFocusInWindow();
}
}
}
);
return filterPanel;
}
public void doOKAction() {