From bd9a82a7510e8141b4e4d9f6adc1222248d6bf1d Mon Sep 17 00:00:00 2001 From: Eldar Abusalimov Date: Tue, 22 Jan 2019 04:21:14 +0300 Subject: [PATCH 1/4] EditorGutterComponentEx: Add an option to forbid closing annotations (cherry picked from commit ba98d3736006ca549b9a4c2c28753892ae5d7142) --- .../editor/ex/EditorGutterComponentEx.java | 4 +++- .../impl/EditorGutterComponentImpl.java | 24 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java index 0fabe91822c6..5e25105debd2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.editor.ex; import com.intellij.codeInsight.daemon.GutterMark; @@ -44,6 +44,8 @@ public abstract class EditorGutterComponentEx extends JComponent implements Edit public abstract void setShowDefaultGutterPopup(boolean show); + public abstract void setCanCloseAnnotations(boolean canCloseAnnotations); + public abstract void setGutterPopupGroup(@Nullable ActionGroup group); public abstract void setPaintBackground(boolean value); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index 22085ef95b55..3b684c659b77 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.editor.impl; @@ -139,6 +139,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse @NotNull private TIntFunction myLineNumberConvertor = value -> value; @Nullable private TIntFunction myAdditionalLineNumberConvertor; private boolean myShowDefaultGutterPopup = true; + private boolean myCanCloseAnnotations = true; @Nullable private ActionGroup myCustomGutterPopupGroup; private final TIntObjectHashMap myTextFgColors = new TIntObjectHashMap<>(); private boolean myPaintBackground = true; @@ -1823,6 +1824,8 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse @Override public void closeAllAnnotations() { + if (!myCanCloseAnnotations) return; + for (TextAnnotationGutterProvider provider : myTextAnnotationGutters) { provider.gutterClosed(); } @@ -1891,6 +1894,11 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse myShowDefaultGutterPopup = show; } + @Override + public void setCanCloseAnnotations(boolean canCloseAnnotations) { + myCanCloseAnnotations = canCloseAnnotations; + } + @Override public void setGutterPopupGroup(@Nullable ActionGroup group) { myCustomGutterPopupGroup = group; @@ -1919,9 +1927,8 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse private void invokePopup(MouseEvent e) { final ActionManager actionManager = ActionManager.getInstance(); if (myEditor.getMouseEventArea(e) == EditorMouseEventArea.ANNOTATIONS_AREA) { - DefaultActionGroup actionGroup = new DefaultActionGroup(EditorBundle.message("editor.annotations.action.group.name"), true); - actionGroup.add(new CloseAnnotationsAction()); final List addActions = new ArrayList<>(); + if (myCanCloseAnnotations) addActions.add(new CloseAnnotationsAction()); final Point p = e.getPoint(); int line = EditorUtil.yPositionToLogicalLine(myEditor, p); //if (line >= myEditor.getDocument().getLineCount()) return; @@ -1936,11 +1943,14 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } } } - for (AnAction addAction : addActions) { - actionGroup.add(addAction); + if (!addActions.isEmpty()) { + DefaultActionGroup actionGroup = new DefaultActionGroup(EditorBundle.message("editor.annotations.action.group.name"), true); + for (AnAction addAction : addActions) { + actionGroup.add(addAction); + } + JPopupMenu menu = actionManager.createActionPopupMenu("", actionGroup).getComponent(); + menu.show(this, e.getX(), e.getY()); } - JPopupMenu menu = actionManager.createActionPopupMenu("", actionGroup).getComponent(); - menu.show(this, e.getX(), e.getY()); e.consume(); } else { From 13a3cdee5ac03777087274b08e7c97746a6bce03 Mon Sep 17 00:00:00 2001 From: Eldar Abusalimov Date: Tue, 22 Jan 2019 17:56:45 +0300 Subject: [PATCH 2/4] EditorGutterComponentEx: Don't add gap after the last annotation gutter (cherry picked from commit c39ba25672d624a80ad073ac287fb116de65d3be) --- .../openapi/editor/impl/EditorGutterComponentImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index 3b684c659b77..363afb9fd90d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -762,7 +762,8 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse private void calcAnnotationsSize() { myTextAnnotationGuttersSize = 0; final int lineCount = Math.max(myEditor.getDocument().getLineCount(), 1); - for (int j = 0; j < myTextAnnotationGutters.size(); j++) { + final int guttersCount = myTextAnnotationGutters.size(); + for (int j = 0; j < guttersCount; j++) { TextAnnotationGutterProvider gutterProvider = myTextAnnotationGutters.get(j); int gutterSize = 0; for (int i = 0; i < lineCount; i++) { @@ -774,7 +775,7 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse gutterSize = Math.max(gutterSize, fontMetrics.stringWidth(lineText)); } } - if (gutterSize > 0) gutterSize += getGapBetweenAnnotations(); + if (gutterSize > 0 && j < guttersCount - 1) gutterSize += getGapBetweenAnnotations(); myTextAnnotationGutterSizes.set(j, gutterSize); myTextAnnotationGuttersSize += gutterSize; } From 30947001f1333de777acd0b74bc11c3796e471d1 Mon Sep 17 00:00:00 2001 From: Eldar Abusalimov Date: Wed, 30 Jan 2019 11:56:43 +0300 Subject: [PATCH 3/4] EditorGutterComponentEx: (doc) Add javadoc for setCanCloseAnnotations() Follow-up: IDEA-CR-42395 EditorGutterComponentEx: Add an option to forbid closing annotations (cherry picked from commit 40013f242f216578117f8cdbe97eb918cfeff94e) --- .../com/intellij/openapi/editor/ex/EditorGutterComponentEx.java | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java index 5e25105debd2..4f0350973042 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/ex/EditorGutterComponentEx.java @@ -44,6 +44,7 @@ public abstract class EditorGutterComponentEx extends JComponent implements Edit public abstract void setShowDefaultGutterPopup(boolean show); + /** When set to false, makes {@link #closeAllAnnotations()} a no-op and hides the corresponding context menu action. */ public abstract void setCanCloseAnnotations(boolean canCloseAnnotations); public abstract void setGutterPopupGroup(@Nullable ActionGroup group); From 917cb704e76d351483aa3a5aa09c9e2b5a5a5c90 Mon Sep 17 00:00:00 2001 From: Eldar Abusalimov Date: Wed, 30 Jan 2019 11:57:41 +0300 Subject: [PATCH 4/4] EditorGutterComponentEx: Only consume event if there's popup to show Follow-up: IDEA-CR-42395 EditorGutterComponentEx: Add an option to forbid closing annotations (cherry picked from commit ed8f09934fff69052e9873719e5bd235192b51ee) --- .../intellij/openapi/editor/impl/EditorGutterComponentImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java index 363afb9fd90d..daefa322a898 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/EditorGutterComponentImpl.java @@ -1951,8 +1951,8 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse } JPopupMenu menu = actionManager.createActionPopupMenu("", actionGroup).getComponent(); menu.show(this, e.getX(), e.getY()); + e.consume(); } - e.consume(); } else { GutterIconRenderer renderer = getGutterRenderer(e);