Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-12-16 13:26:03 +0000
committerThomas Wolf2019-12-16 16:00:55 +0000
commite16db8b764b65adcadd8a0678cbc49c22d4186c6 (patch)
treec9b4d12a2346115ce02d72d80559c5bffd689bd8
parentefc4d4acc01e6ccbee512d065e714e6342fc645e (diff)
downloadegit-e16db8b764b65adcadd8a0678cbc49c22d4186c6.tar.gz
egit-e16db8b764b65adcadd8a0678cbc49c22d4186c6.tar.xz
egit-e16db8b764b65adcadd8a0678cbc49c22d4186c6.zip
Staging View: fix title label updates
Since the label provider/decorator setup changes in commit b2e98cd3 the staging view title could flicker between undecorated and decorated label. DecoratingStyledCellLabelProvider.getStyledText() has no protection for decorations being pending, so it mustn't be used anymore to determine the view's title. Instead use a simple DecoratingLabelProvider. Use it to update a ViewerLabel object on any LabelProviderChangedEvent, and update the form title only if that ViewerLabel has a new image or text. The label provider's updateLabel() method has similar protection for pending decorations, and so the flickering can be avoided. Also use this ViewerLabel to set the form title image; this gives the staging view the correct image (for instance, the "Gerrit repo" image for Gerrit-enabled repositories). Bug: 558360 Change-Id: I69f83b21703959610208d06abda3b2aa65d6a555 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java43
1 files changed, 35 insertions, 8 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
index 5fec3702e..209eb9a85 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
@@ -30,6 +30,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
@@ -159,6 +160,7 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.ViewerLabel;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.api.AddCommand;
@@ -175,6 +177,7 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.util.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.VerifyKeyListener;
@@ -269,7 +272,9 @@ public class StagingView extends ViewPart
private RepositoryNode titleNode;
- private RepositoryTreeNodeLabelProvider titleLabelProvider;
+ private Map<File, ViewerLabel> titleLabels = new HashMap<>();
+
+ private DecoratingLabelProvider titleLabelProvider;
private SashForm mainSashForm;
@@ -734,11 +739,12 @@ public class StagingView extends ViewPart
GridLayoutFactory.fillDefaults().applyTo(parent);
titleNode = null;
- titleLabelProvider = new RepositoryTreeNodeLabelProvider(false);
+ titleLabelProvider = new DecoratingLabelProvider(
+ new RepositoryTreeNodeLabelProvider(),
+ PlatformUI.getWorkbench().getDecoratorManager());
titleLabelProvider.addListener(e -> {
if (titleNode != null && form != null && !form.isDisposed()) {
- form.setText(titleLabelProvider.getStyledText(titleNode)
- .getString());
+ updateTitle(false);
}
});
toolkit = new FormToolkit(parent.getDisplay());
@@ -1307,6 +1313,27 @@ public class StagingView extends ViewPart
service.showBusyForFamily(org.eclipse.egit.core.JobFamilies.INDEX_DIFF_CACHE_UPDATE);
}
+ private void updateTitle(boolean force) {
+ ViewerLabel label = titleLabels.computeIfAbsent(
+ titleNode.getRepository().getDirectory(),
+ r -> new ViewerLabel(null, null));
+ if (force) {
+ if (label.getImage() != null) {
+ form.setImage(label.getImage());
+ }
+ if (!StringUtils.isEmptyOrNull(label.getText())) {
+ form.setText(label.getText());
+ }
+ }
+ titleLabelProvider.updateLabel(label, titleNode);
+ if (label.hasNewImage()) {
+ form.setImage(label.getImage());
+ }
+ if (label.hasNewText()) {
+ form.setText(label.getText());
+ }
+ }
+
/**
* On Windows some SWT bug avoids repainting the non selected elements
* correctly, see bugzilla 533555.
@@ -3652,6 +3679,7 @@ public class StagingView extends ViewPart
refreshAction.setEnabled(false);
updateSectionText();
titleNode = null;
+ form.setImage(getImage(UIIcons.REPOSITORY));
if (repository != null && repository.isBare()) {
form.setText(UIText.StagingView_BareRepoSelection);
} else {
@@ -3737,8 +3765,7 @@ public class StagingView extends ViewPart
if (repositoryChanged) {
titleNode = new RepositoryNode(null, repository);
- form.setText(titleLabelProvider.getStyledText(titleNode)
- .getString());
+ updateTitle(true);
// Reset paths, they're from the old repository
resetPathsToExpand();
removeRepositoryListeners();
@@ -3752,8 +3779,7 @@ public class StagingView extends ViewPart
repository));
} else if (titleNode != null) {
// The label decoration may need an update.
- form.setText(titleLabelProvider.getStyledText(titleNode)
- .getString());
+ updateTitle(false);
}
final StagingViewUpdate update = new StagingViewUpdate(repository,
indexDiff, null);
@@ -4380,6 +4406,7 @@ public class StagingView extends ViewPart
titleLabelProvider = null;
}
titleNode = null;
+ titleLabels.clear();
currentRepository = null;
lastSelection = null;
disposed = true;

Back to the top