diff options
author | angelozerr | 2017-12-19 19:32:55 +0000 |
---|---|---|
committer | Mickael Istria | 2017-12-20 08:06:04 +0000 |
commit | 1318c013824ccc86b3371748147b4c8c731235df (patch) | |
tree | 8c1b7f070e8a32d9efdad9ffd30bf889ddd35262 | |
parent | 9b3c88639be6dfbefbf70ee443c8d04e1aea7eae (diff) | |
download | eclipse.platform.text-1318c013824ccc86b3371748147b4c8c731235df.tar.gz eclipse.platform.text-1318c013824ccc86b3371748147b4c8c731235df.tar.xz eclipse.platform.text-1318c013824ccc86b3371748147b4c8c731235df.zip |
Bug 528907 - [CodeMining] Render code minings without flickering
Change-Id: I62607e8f2aa5bee6ab2c47ff0870f94c0c859666
Signed-off-by: angelozerr <angelo.zerr@gmail.com>
-rw-r--r-- | org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java index 7b7daad3f58..aa85ca8beb9 100644 --- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java +++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningAnnotation.java @@ -19,7 +19,6 @@ import org.eclipse.swt.graphics.GC; import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.codemining.ICodeMining;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -34,22 +33,54 @@ public class CodeMiningAnnotation extends LineHeaderAnnotation { private static final String SEPARATOR= " | "; //$NON-NLS-1$
+ /**
+ * List of resolved minings which contains current resolved minings and last resolved minings
+ * and null if mining is not resolved.
+ */
+ private ICodeMining[] fResolvedMinings;
+
+ /**
+ * List of current resolved/unresolved minings
+ */
private final List<ICodeMining> fMinings;
- private ITextViewer fViewer;
+ /**
+ * The viewer
+ */
+ private ISourceViewer fViewer;
+ /**
+ * The current progress monitor
+ */
private IProgressMonitor fMonitor;
+ /**
+ * Code mining annotation constructor.
+ *
+ * @param position the position
+ * @param viewer the viewer
+ */
public CodeMiningAnnotation(Position position, ISourceViewer viewer) {
super(position, viewer.getTextWidget());
+ fResolvedMinings= null;
fMinings= new ArrayList<>();
this.fViewer= viewer;
}
+ /**
+ * Update code minings.
+ *
+ * @param minings the minings to update.
+ * @param monitor the monitor
+ */
public void update(List<ICodeMining> minings, IProgressMonitor monitor) {
disposeMinings();
fMonitor= monitor;
fMinings.addAll(minings);
+ if (fResolvedMinings == null || (fResolvedMinings.length != fMinings.size())) {
+ // size of resolved minings are different from size of minings to update, initialize it with size of minings to update
+ fResolvedMinings= new ICodeMining[fMinings.size()];
+ }
}
@Override
@@ -57,6 +88,7 @@ public class CodeMiningAnnotation extends LineHeaderAnnotation { super.markDeleted(deleted);
if (deleted) {
disposeMinings();
+ fResolvedMinings= null;
}
}
@@ -72,13 +104,29 @@ public class CodeMiningAnnotation extends LineHeaderAnnotation { List<ICodeMining> minings= new ArrayList<>(fMinings);
int nbDraw= 0;
int separatorWidth= -1;
- for (ICodeMining mining : minings) {
+ boolean redrawn= false;
+ for (int i= 0; i < minings.size(); i++) {
+ ICodeMining mining= minings.get(i);
if (!mining.isResolved()) {
- // Don't draw mining which is not resolved
- // then redraw the annotation when mining is ready.
- mining.resolve(fViewer, fMonitor).thenRun(() -> this.redraw());
- continue;
+ // the mining is not resolved.
+ if (!redrawn) {
+ // redraw the annotation when mining is resolved.
+ redraw();
+ redrawn= true;
+ }
+ // try to get the last resolved mining.
+ if (fResolvedMinings != null) {
+ mining= fResolvedMinings[i];
+ }
+ if (mining == null) {
+ // the last mining was not resolved, don't draw it.
+ continue;
+ }
+ } else {
+ // mining is resolved, update the resolved mining list
+ fResolvedMinings[i]= mining;
}
+ // draw the mining
if (nbDraw > 0) {
gc.drawText(SEPARATOR, x, y);
if (separatorWidth == -1) {
@@ -91,4 +139,21 @@ public class CodeMiningAnnotation extends LineHeaderAnnotation { }
}
+ @Override
+ public void redraw() {
+ // redraw codemining annotation is done only if all current minings are resolved.
+ List<ICodeMining> minings= new ArrayList<>(fMinings);
+ for (ICodeMining mining : minings) {
+ if (!mining.isResolved()) {
+ // one of mining is not resolved, resolve it and then redraw the annotation.
+ mining.resolve(fViewer, fMonitor).thenRunAsync(() -> {
+ this.redraw();
+ });
+ return;
+ }
+ }
+ // all minings are resolved, redraw the annotation
+ super.redraw();
+ }
+
}
|