Add an extension point implementing gutter icons merging

also adjust calculation of initial icon are width, to avoid gutter 'jumping' (for icon sizes up to 17px)
This commit is contained in:
Dmitry Batrak
2016-04-29 19:54:04 +03:00
parent b65ed30fd4
commit cb93a73770
3 changed files with 51 additions and 4 deletions
@@ -0,0 +1,29 @@
/*
* Copyright 2000-2016 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.openapi.editor;
import com.intellij.codeInsight.daemon.GutterMark;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.sun.istack.internal.NotNull;
import java.util.List;
public interface GutterMarkPreprocessor {
ExtensionPointName<GutterMarkPreprocessor> EP_NAME = ExtensionPointName.create("com.intellij.gutterMarkPreprocessor");
@NotNull
List<GutterMark> processMarkers(@NotNull List<GutterMark> list);
}
@@ -68,6 +68,7 @@ import gnu.trove.TIntArrayList;
import gnu.trove.TIntFunction;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TIntObjectProcedure;
import gnu.trove.TObjectFunction;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -114,6 +115,7 @@ import java.util.List;
*/
class EditorGutterComponentImpl extends EditorGutterComponentEx implements MouseListener, MouseMotionListener, DataProvider {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.editor.impl.EditorGutterComponentImpl");
private static final int START_ICON_AREA_WIDTH = JBUI.scale(17);
private static final int FREE_PAINTERS_LEFT_AREA_WIDTH = JBUI.scale(8);
private static final int FREE_PAINTERS_RIGHT_AREA_WIDTH = JBUI.scale(5);
private static final int GAP_BETWEEN_ICONS = JBUI.scale(3);
@@ -775,9 +777,23 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
myLineToGutterRenderers.put(line, renderers);
}
if (renderers.size() < 5) { // Don't allow more than 5 icons per line
renderers.add(renderer);
renderers.add(renderer);
}
});
myLineToGutterRenderers.transformValues(new TObjectFunction<List<GutterMark>, List<GutterMark>>() {
@Override
public List<GutterMark> execute(List<GutterMark> value) {
List<GutterMark> newValue = value;
for (GutterMarkPreprocessor preprocessor : GutterMarkPreprocessor.EP_NAME.getExtensions()) {
newValue = preprocessor.processMarkers(value);
}
if (newValue.size() >= 5) { // Don't allow more than 5 icons per line
newValue = newValue.subList(0, 4);
}
return newValue;
}
});
}
@@ -804,10 +820,11 @@ class EditorGutterComponentImpl extends EditorGutterComponentEx implements Mouse
return;
}
int minWidth = (int)(START_ICON_AREA_WIDTH * myEditor.getScale());
if (canShrink) {
myIconsAreaWidth = myEditor.getLineHeight();
myIconsAreaWidth = minWidth;
} else {
myIconsAreaWidth = Math.max(myIconsAreaWidth, myEditor.getLineHeight());
myIconsAreaWidth = Math.max(myIconsAreaWidth, minWidth);
}
processGutterRenderers((line, renderers) -> {
@@ -261,6 +261,7 @@
<extensionPoint name="vfs.local.pluggableFileWatcher" interface="com.intellij.openapi.vfs.local.PluggableFileWatcher" />
<extensionPoint name="gutterMarkPreprocessor" interface="com.intellij.openapi.editor.GutterMarkPreprocessor" />
<extensionPoint name="remote.credentialsType" interface="com.intellij.remote.ext.CredentialsTypeEx"/>
<extensionPoint name="remote.credentialsLanguageContribution"
interface="com.intellij.remote.ext.CredentialsLanguageContribution"/>