16cb555a056dac4d5b9b50ffa9208291f2b1efb1
[fedora-idea.git] / platform / lang-impl / src / com / intellij / codeInspection / ex / DisableInspectionToolAction.java
blob16cb555a056dac4d5b9b50ffa9208291f2b1efb1
1 /*
2 * Copyright 2000-2009 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.
17 package com.intellij.codeInspection.ex;
19 import com.intellij.CommonBundle;
20 import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
21 import com.intellij.codeInsight.daemon.HighlightDisplayKey;
22 import com.intellij.codeInsight.intention.IntentionAction;
23 import com.intellij.codeInspection.InspectionProfile;
24 import com.intellij.codeInspection.InspectionsBundle;
25 import com.intellij.codeInspection.LocalInspectionTool;
26 import com.intellij.codeInspection.ModifiableModel;
27 import com.intellij.openapi.editor.Editor;
28 import com.intellij.openapi.project.Project;
29 import com.intellij.openapi.ui.Messages;
30 import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
31 import com.intellij.psi.PsiFile;
32 import com.intellij.util.IncorrectOperationException;
33 import org.jetbrains.annotations.NotNull;
35 import java.io.IOException;
37 public class DisableInspectionToolAction implements IntentionAction {
38 private final String myToolId;
39 public static final String NAME = InspectionsBundle.message("disable.inspection.action.name");
41 public DisableInspectionToolAction(LocalInspectionTool tool) {
42 myToolId = tool.getShortName();
45 public DisableInspectionToolAction(final HighlightDisplayKey key) {
46 myToolId = key.toString();
49 @NotNull
50 public String getText() {
51 return NAME;
54 @NotNull
55 public String getFamilyName() {
56 return NAME;
59 public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
60 return true;
63 public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
64 final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(file.getProject());
65 InspectionProfile inspectionProfile = profileManager.getInspectionProfile();
66 ModifiableModel model = inspectionProfile.getModifiableModel();
67 model.disableTool(myToolId, file);
68 try {
69 model.commit();
71 catch (IOException e) {
72 Messages.showErrorDialog(project, e.getMessage(), CommonBundle.getErrorTitle());
74 DaemonCodeAnalyzer.getInstance(project).restart();
77 public boolean startInWriteAction() {
78 return false;