From f586bcc4d6b797cd9d6166a93337602dd9172a46 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Wed, 8 Feb 2017 11:38:54 +0100 Subject: [PATCH] more clear name for modification check for viewer (IDEA-CR-17799) --- .../codeInsight/generation/GenerateDelegateHandler.java | 2 +- .../codeInsight/generation/GenerateMembersHandlerBase.java | 2 +- .../com/intellij/codeInsight/actions/CodeInsightAction.java | 4 ++-- .../src/com/intellij/codeInsight/CodeInsightUtilBase.java | 4 ++-- .../codeInsight/actions/MultiCaretCodeInsightAction.java | 2 +- .../codeInsight/completion/CodeCompletionHandlerBase.java | 2 +- .../completion/actions/HippieWordCompletionHandler.java | 2 +- .../com/intellij/codeInsight/editorActions/PasteHandler.java | 2 +- .../com/intellij/codeInsight/editorActions/TypedHandler.java | 2 +- .../codeInsight/generation/DelegateMethodsHandler.java | 2 +- .../codeInsight/generation/ImplementMethodsHandler.java | 2 +- .../codeInsight/generation/OverrideMethodsHandler.java | 2 +- .../generation/surroundWith/SurroundWithHandler.java | 2 +- .../intellij/codeInsight/lookup/impl/LookupTypedHandler.java | 2 +- .../template/impl/SurroundWithTemplateHandler.java | 2 +- .../src/com/intellij/codeInsight/unwrap/UnwrapHandler.java | 2 +- .../com/intellij/openapi/editor/EditorModificationUtil.java | 4 ++-- .../codeInsight/actions/AddGradleDslPluginActionHandler.java | 2 +- .../actions/AddGradleDslDependencyActionHandler.java | 2 +- .../overrideImplement/GroovyImplementMethodsHandler.java | 2 +- .../overrideImplement/GroovyOverrideMethodsHandler.java | 2 +- .../src/com/intellij/xml/actions/GenerateXmlTagAction.java | 2 +- 22 files changed, 25 insertions(+), 25 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java index 026d8ef6f681..ada860857564 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateDelegateHandler.java @@ -56,7 +56,7 @@ public class GenerateDelegateHandler implements LanguageCodeInsightActionHandler @Override public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) { return; } diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java index 90f208d2e563..37df54e41b56 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/GenerateMembersHandlerBase.java @@ -69,7 +69,7 @@ public abstract class GenerateMembersHandlerBase implements CodeInsightActionHan @Override public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) { return; } diff --git a/platform/lang-api/src/com/intellij/codeInsight/actions/CodeInsightAction.java b/platform/lang-api/src/com/intellij/codeInsight/actions/CodeInsightAction.java index c65127d8ef07..af1a4863fcb0 100644 --- a/platform/lang-api/src/com/intellij/codeInsight/actions/CodeInsightAction.java +++ b/platform/lang-api/src/com/intellij/codeInsight/actions/CodeInsightAction.java @@ -19,7 +19,7 @@ package com.intellij.codeInsight.actions; import com.intellij.codeInsight.CodeInsightActionHandler; import com.intellij.codeInsight.FileModificationService; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.application.*; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorModificationUtil; @@ -63,7 +63,7 @@ public abstract class CodeInsightAction extends AnAction { final CodeInsightActionHandler handler = getHandler(); PsiElement elementToMakeWritable = handler.getElementToMakeWritable(psiFile); if (elementToMakeWritable != null && - !(EditorModificationUtil.showReadOnlyViewWarning(editor) && + !(EditorModificationUtil.checkModificationAllowed(editor) && FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable))) { return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightUtilBase.java b/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightUtilBase.java index e8397866ba63..223d2c22b887 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightUtilBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/CodeInsightUtilBase.java @@ -101,11 +101,11 @@ public class CodeInsightUtilBase extends CodeInsightUtilCore { // returns true on success @Deprecated public static boolean prepareEditorForWrite(@NotNull Editor editor) { - return EditorModificationUtil.showReadOnlyViewWarning(editor); + return EditorModificationUtil.checkModificationAllowed(editor); } @Deprecated public static void showReadOnlyViewWarning(Editor editor) { - EditorModificationUtil.showReadOnlyViewWarning(editor); + EditorModificationUtil.checkModificationAllowed(editor); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/actions/MultiCaretCodeInsightAction.java b/platform/lang-impl/src/com/intellij/codeInsight/actions/MultiCaretCodeInsightAction.java index e399b77bdc45..07f24de96764 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/actions/MultiCaretCodeInsightAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/actions/MultiCaretCodeInsightAction.java @@ -53,7 +53,7 @@ public abstract class MultiCaretCodeInsightAction extends AnAction { if (hostEditor == null) { return; } - if (!EditorModificationUtil.showReadOnlyViewWarning(hostEditor)) return; + if (!EditorModificationUtil.checkModificationAllowed(hostEditor)) return; PsiFile hostFile = PsiDocumentManager.getInstance(project).getPsiFile(hostEditor.getDocument()); if (hostFile != null && !FileModificationService.getInstance().prepareFileForWrite(hostFile)) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java index f1b5042c438a..eed2786666cc 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/CodeCompletionHandlerBase.java @@ -140,7 +140,7 @@ public class CodeCompletionHandlerBase { int offset = editor.getCaretModel().getOffset(); if (editor.isViewer() || editor.getDocument().getRangeGuard(offset, offset) != null) { editor.getDocument().fireReadOnlyModificationAttempt(); - EditorModificationUtil.showReadOnlyViewWarning(editor); + EditorModificationUtil.checkModificationAllowed(editor); return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java index a2841cc6ad2f..4c372ff2f2b9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/completion/actions/HippieWordCompletionHandler.java @@ -55,7 +55,7 @@ public class HippieWordCompletionHandler implements CodeInsightActionHandler { int caretOffset = editor.getCaretModel().getOffset(); if (editor.isViewer() || editor.getDocument().getRangeGuard(caretOffset, caretOffset) != null) { editor.getDocument().fireReadOnlyModificationAttempt(); - EditorModificationUtil.showReadOnlyViewWarning(editor); + EditorModificationUtil.checkModificationAllowed(editor); return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java index fc2c6ac2c893..5ddb7b33b05f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/PasteHandler.java @@ -79,7 +79,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser final Transferable transferable = EditorModificationUtil.getContentsToPasteToEditor(producer); if (transferable == null) return; - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; final Document document = editor.getDocument(); if (!EditorModificationUtil.requestWriting(editor)) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java index 639706f82fcc..da29f868f406 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/editorActions/TypedHandler.java @@ -157,7 +157,7 @@ public class TypedHandler extends TypedActionHandlerBase { return; } - if (!EditorModificationUtil.showReadOnlyViewWarning(originalEditor)) return; + if (!EditorModificationUtil.checkModificationAllowed(originalEditor)) return; final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); final Document originalDocument = originalEditor.getDocument(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/DelegateMethodsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/DelegateMethodsHandler.java index 95d9b1702809..a9480001cfdb 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/DelegateMethodsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/DelegateMethodsHandler.java @@ -31,7 +31,7 @@ import org.jetbrains.annotations.NotNull; public class DelegateMethodsHandler implements CodeInsightActionHandler{ @Override public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){ return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/ImplementMethodsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/ImplementMethodsHandler.java index b670c697d2b9..a39e1a4ff022 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/ImplementMethodsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/ImplementMethodsHandler.java @@ -31,7 +31,7 @@ import org.jetbrains.annotations.NotNull; public class ImplementMethodsHandler implements CodeInsightActionHandler{ @Override public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){ return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/OverrideMethodsHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/OverrideMethodsHandler.java index 83db0240c8fd..771e8f5f36aa 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/OverrideMethodsHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/OverrideMethodsHandler.java @@ -31,7 +31,7 @@ import org.jetbrains.annotations.NotNull; public class OverrideMethodsHandler implements CodeInsightActionHandler{ @Override public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)){ return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java index d1fb12d5a561..4fb903a3aaf7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/surroundWith/SurroundWithHandler.java @@ -74,7 +74,7 @@ public class SurroundWithHandler implements CodeInsightActionHandler { } public static void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file, Surrounder surrounder) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; if (file instanceof PsiCompiledElement) { HintManager.getInstance().showErrorHint(editor, "Can't modify decompiled code"); return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java index f27342593833..1d8cc441bd18 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupTypedHandler.java @@ -66,7 +66,7 @@ public class LookupTypedHandler extends TypedActionHandlerBase { return; } - if (!EditorModificationUtil.showReadOnlyViewWarning(originalEditor)) { + if (!EditorModificationUtil.checkModificationAllowed(originalEditor)) { return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java index 4fea4d84bf83..5e94a91bc1c7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/SurroundWithTemplateHandler.java @@ -41,7 +41,7 @@ import java.util.Set; public class SurroundWithTemplateHandler implements CodeInsightActionHandler { @Override public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; DefaultActionGroup group = createActionGroup(project, editor, file); if (group == null) return; diff --git a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java index 638dc7ac8f5f..921e9f4ac570 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/unwrap/UnwrapHandler.java @@ -59,7 +59,7 @@ public class UnwrapHandler implements CodeInsightActionHandler { @Override public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; List options = collectOptions(project, editor, file); selectOption(options, editor, file); } diff --git a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java index bc0b2d0eaa13..df4c4bb8dbb8 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/EditorModificationUtil.java @@ -28,7 +28,6 @@ import com.intellij.util.Producer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; @@ -417,8 +416,9 @@ public class EditorModificationUtil { /** * @return true when not viewer + * false otherwise, additionally information hint with warning would be shown */ - public static boolean showReadOnlyViewWarning(Editor editor) { + public static boolean checkModificationAllowed(Editor editor) { if (!editor.isViewer()) return true; if (ApplicationManager.getApplication().isHeadlessEnvironment() || editor instanceof TextComponentEditor) return false; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java index 589be8b970aa..e1de704605df 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/codeInsight/actions/AddGradleDslPluginActionHandler.java @@ -60,7 +60,7 @@ class AddGradleDslPluginActionHandler implements CodeInsightActionHandler { @Override public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; if (!FileModificationService.getInstance().preparePsiElementsForWrite(file)) return; final JBList list = new JBList(myPlugins); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionHandler.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionHandler.java index 58996b48000c..48c9f4261e3c 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionHandler.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/maven/codeInsight/actions/AddGradleDslDependencyActionHandler.java @@ -48,7 +48,7 @@ class AddGradleDslDependencyActionHandler implements CodeInsightActionHandler { @Override public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor) || + if (!EditorModificationUtil.checkModificationAllowed(editor) || !FileModificationService.getInstance().preparePsiElementsForWrite(file)) return; final List ids; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyImplementMethodsHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyImplementMethodsHandler.java index a0d6ac05e87b..bf901b2c2aca 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyImplementMethodsHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyImplementMethodsHandler.java @@ -39,7 +39,7 @@ public class GroovyImplementMethodsHandler implements LanguageCodeInsightActionH @Override public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true); if (aClass instanceof GrTypeDefinition) { GrTypeDefinition typeDefinition = (GrTypeDefinition)aClass; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyOverrideMethodsHandler.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyOverrideMethodsHandler.java index be3746aa7a82..c4a5e0d5a532 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyOverrideMethodsHandler.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/overrideImplement/GroovyOverrideMethodsHandler.java @@ -39,7 +39,7 @@ public class GroovyOverrideMethodsHandler implements LanguageCodeInsightActionHa @Override public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; PsiClass aClass = OverrideImplementUtil.getContextClass(project, editor, file, true); if (aClass instanceof GrTypeDefinition) { GrTypeDefinition typeDefinition = (GrTypeDefinition)aClass; diff --git a/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java b/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java index 9590086ac359..61f6e2e1ba7f 100644 --- a/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java +++ b/xml/impl/src/com/intellij/xml/actions/GenerateXmlTagAction.java @@ -72,7 +72,7 @@ public class GenerateXmlTagAction extends SimpleCodeInsightAction { @Override public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) { - if (!EditorModificationUtil.showReadOnlyViewWarning(editor)) return; + if (!EditorModificationUtil.checkModificationAllowed(editor)) return; try { final XmlTag contextTag = getContextTag(editor, file); if (contextTag == null) {